0

i'm learning about bitcoin, and bitcoinjs-lib (https://github.com/bitcoinjs/bitcoinjs-lib)

I created a dummy wallet on coinomi using this mnemonic ('eight better wealth display father cave suffer game sign health fit exchange noble tunnel poet remember owner letter submit illness cage calm dry noble')

and i'm trying to generate a Deterministic wallet with it.

Here is my code

const bip39 = require('bip39')
const bip32 = require('bip32')
const bitcoin = require('bitcoinjs-lib')
const network = bitcoin.networks.bitcoin;
function getAddress (node) {
return bitcoin.payments.p2pkh({ pubkey: node.publicKey, network}).address
}
const mnemonic = 'eight better wealth display father cave suffer game sign health fit exchange noble tunnel poet remember owner letter submit illness cage calm dry noble'
console.log('Testing mnemonic: ',bip39.validateMnemonic(mnemonic))
const seed = bip39.mnemonicToSeed(mnemonic)
const root = bip32.fromSeed(seed)
console.log("m/0'/0/1 ->",getAddress(root.derivePath("m/0'/0/1")));
console.log("m/0'/0/2 ->",getAddress(root.derivePath("m/0'/0/2")));

.

and this is the output that i got

.

Testing mnemonic: true
m/0'/0/1 -> 17tdSW83Vjw23TdQsmZDtBAupan9WiGGd5
m/0'/0/2 -> 17bYSjEXwZxMgVkRRt9pJgDgExiX8Xht3b

Then I go to (https://www.coinomi.com/recovery-phrase-tool.html) to test if my results are correct, and it isn't, could someone help me with this please. How to fix the code?

1 Answer 1

0

It looks like it is working. Go to https://www.coinomi.com/recovery-phrase-tool.html and make sure to enter the following:

BIP39 Recovery Phrase : eight better wealth display father cave suffer game sign health fit exchange noble tunnel poet remember owner letter submit illness cage calm dry noble

Coin : Bitcoin

BIP32 Derivation Path (In BIP32 Tab): m/0'/0

Result:

Derived Addresses

m/0'/0/0`   169zFhK1WTuxfhgY6bmzE9zP1godCfZr2V
m/0'/0/1    17tdSW83Vjw23TdQsmZDtBAupan9WiGGd5
m/0'/0/2    17bYSjEXwZxMgVkRRt9pJgDgExiX8Xht3b
1
  • hmm thanks, i was using the site wrongly. but just another question, I can get the public key from this code root.derivePath("m/0'/0/0").publicKey.toString('hex') and I get "02db987662b3f1a84c8465ac710de96106ba65aef63d0967e605b802d5fd2579e5" with is correct, but with private key, that doens't work, do you know how I can display my private key for path 0/0? (I resolved it by myself, the solution was to use root.derivePath("m/0'/0/0").toWIF() Jul 24, 2018 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.