Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Testnet #21

Closed
jcrubino opened this issue Jan 12, 2014 · 13 comments
Closed

How to use Testnet #21

jcrubino opened this issue Jan 12, 2014 · 13 comments

Comments

@jcrubino
Copy link

How can I use this lib to work with testnet?

@jprichardson
Copy link
Member

As far as I know, it doesn't work with testnet. You'll want to use one of the forks: https://github.com/vbuterin/bitcoinjs-lib & https://github.com/kyledrake/bitcoinjs-lib or follow our effort over here: https://github.com/cryptocoinjs/cryptocoin

@jcrubino
Copy link
Author

@jprichardson it should be as simple as changing the address prefix... need to verify that with others.

@jprichardson
Copy link
Member

For generating testnet addresses, yes, just set an instance of Bitcoin.Address version field to 0x6f. That should do it.

@jprichardson
Copy link
Member

jprichardson commented Jan 16, 2014

I wrote http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript, scroll down to the part on Addresses.

edit: See below for up-to-date examples

@mixdev
Copy link

mixdev commented Jun 14, 2017

From the integration tests directory

var testnet = bitcoin.networks.testnet
var alice = bitcoin.ECPair.makeRandom({ network: testnet })
var bob = bitcoin.ECPair.makeRandom({ network: testnet })
var alicesAddress = alice.getAddress()
var bobsAddress = bob.getAddress()

@dcousens dcousens changed the title Testnet How to use Testnet Jun 14, 2017
@mixdev
Copy link

mixdev commented Jun 14, 2017

If you want to create the ECPair from a hash:

  var hash = bitcoin.crypto.sha256('correct horse battery staple')
  var d = bigi.fromBuffer(hash)
  var keyPair = bitcoin.ECPair(d, null, {network: bitcoin.networks.testnet});

@takahser
Copy link

@mixdev this doesn't work anymore, see #1085 and changelog:

However, payments.p2pkh doesn't return a testnet address (starting with m or n), but obviously a p2pkh address that isn't valid on the testnet address (correct me if I'm wrong). Is there still a way to get testnet addresses using bitcoinjs-lib?

@junderw
Copy link
Member

junderw commented Nov 13, 2018

pass network to p2pkh and all portions inside it.

@bitcoinjs bitcoinjs locked as resolved and limited conversation to collaborators Nov 13, 2018
@bitcoinjs bitcoinjs unlocked this conversation Nov 14, 2018
@dcousens
Copy link
Contributor

@junderw is the .network information on ECPair still useful?

@junderw
Copy link
Member

junderw commented Nov 14, 2018

with the new payments API, no... not really.

@dtaipov
Copy link

dtaipov commented Apr 2, 2019

pass network to p2pkh and all portions inside it.

@junderw Could you suggest how to pass network to p2pkh? This code still returns mainnet address:
const { address } = bitcoin.payments.p2pkh({ pubkey }, {network: bitcoin.networks.testnet});

@junderw
Copy link
Member

junderw commented Apr 2, 2019

const { address } = bitcoin.payments.p2pkh({ pubkey, network: bitcoin.networks.testnet})

this works.

one arg, not two.

@pavoltravnik
Copy link

I had to pass it directly as a parameter
#1259
let script = bitcoin.address.toOutputScript(address, bitcoin.networks.testnet);

louisinger added a commit to louisinger/liquidjs-lib that referenced this issue Aug 19, 2021
* bump bip174-liquid

* blech32 from NPM

* use blech32 from NPM

* format test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants