Transaction on bitcoin address derived from bitcoinjs-lib not showing in Bitcoin core

1.2k views Asked by At

I have generated the xpub using bip32.org and derieved random address using xpub

var hdNode = bitcoinjs.HDNode.fromBase58(derivedPubKey); hdNode.derive(index).pubKey.getAddress().toString();

the Private wif generated via bip32.org imported in the Bitcoin core. On transferring amount on the address generated by above code., amount is not showing in my bitcoin-core..

2

There are 2 answers

0
jaboja On

If you have imported the main pubkey into Core but the address you send to is a derived address then you are just sending to different address than you are expecting the funds to receive at.

Every derived address has its own private key so you have to import the keys of individual derived addresses not just the key of the chain:

var addr = hdNode.derive(i);
/* Derived address: */
addr.getAddress();
/* Corresponding privkey: */
addr.keyPair.toWIF();

In fact every derived address is possibly also a new chain (derive() returns a new HDNode). Also your hdNode is intended to be used only for address derivation yet it has own address too (the one you have sent your funds too), just because there are no separate datatypes for addresses and for chains. To access that funds just generate private key without derivation:

hdNode.keyPair.toWIF();

On the other hand if you use Electrum instead of Core you may just extract the main key of one of address chains of an Electrum wallet (it does not work the opposite way as Electrum uses checksum for wallet seed and you cannot just import non-electrum chain). This way you will be able to independently generate new addresses (also just new addresses without privKeys, for security reasons) which would be recognized by the wallet without importing them explicitly.

By the way, https://bitcoin.stackexchange.com/ is better place to ask bitcoin-related questions.

0
Bablu Singh On

Yes you can create address from private key using below code

const bitcoin = require('bitcoinjs-lib'); let testnet = bitcoin.networks.testnet; const keyPair = bitcoin.ECPair.fromWIF('cQnWufBcGz5fDtAPH8DVzrayXY1BJVCohCSHhgHXV8xnWfkGKQGL', testnet ) const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey }) console.log(address)