moneybutton / bsv

Bitcoin SV javascript library
Other
204 stars 105 forks source link

'testnet' address generation bug? #220

Closed antmaster2001 closed 2 years ago

antmaster2001 commented 3 years ago

Hello, today is my first day using the bsv package.

I'm trying to generate a 'testnet' address following the code in the documentation.

const bsv = require("bsv");
let privateKey = bsv.PrivKey.fromRandom('testnet')
let publicKey = bsv.PubKey.fromPrivKey(privateKey)
let address = bsv.Address.fromPubKey(publicKey, 'testnet')
let address2 = bsv.Address.fromPrivKey(privateKey, 'testnet')

console.log(address.toString());
console.log(address2.toString());

No matter how many times I try, they all start with a 1.

example: 1B9ymVLbAMkwY87rNugSxqfx7V1hGw71xX

Am I making a mistake or is there something wrong with the documentation?

sirdeggen commented 2 years ago

Yes, you're making a small mistake. The documentation may be out of date - below works with the new bsv2 library v2 on I think


let privateKey = bsv.PrivKey.Testnet.fromRandom()
let publicKey = bsv.PubKey.fromPrivKey(privateKey)
let address = bsv.Address.Testnet.fromPubKey(publicKey)
let address2 = bsv.Address.Testnet.fromPrivKey(privateKey)

console.log(address.toString())
console.log(address2.toString())
antmaster2001 commented 2 years ago

I just checked and that works perfect 😃 The code I added is straight from the Docs

sirdeggen commented 2 years ago

Such is documentation sadly.