Bitcoinjs-lib: How do I generate an address from a WIF key string?

Created on 26 Dec 2018  ·  5Comments  ·  Source: bitcoinjs/bitcoinjs-lib

BTC:
Previously generated private key and address based on path;code show as below:

const bip32 = require('bip32')
const bip39 = require('bip39')

function getAddress (node, network) {
  return bitcoin.payments.p2pkh({ pubkey: node.publicKey, network }).address
}

let mnemonic = bip39.generateMnemonic();
const seedBuffer = bip39.mnemonicToSeed(mnemonic)
const root = bip32.fromSeed(seedBuffer)

const BTCChild = root.derivePath("m/44'/0'/0'/0/0")
const BTCAdress = getAddress(BTCChild)//adress by path
const BTCPrivateKey = BTCChild.toWIF()//private key 

Now import the private key into the wallet; how to generate an address(BTCAdress) based on the private key(BTCAdress);

how to / question / docs

All 5 comments

Now import the private key into the wallet; how to generate an address(BTCAdress) based on the private key(BTCPrivateKey)?

const bitcoin = require('bitcoinjs-lib')
const keyPair = bitcoin.ECPair.fromWIF(BTCPrivateKey)
const BTCAddressFromWIF = getAddress(keyPair, keyPair.network)

Please format your questions properly.

Thank you.

Sorry ! Wallet business is not familiar. I do not know how to describe. Thank you very much!

Ahora importa la clave privada en la billetera; ¿Cómo generar una dirección (BTCAdress) basada en la clave privada (BTCPrivateKey)?

LA DIRECCION PUBLICA SE PUEDE GENERAR DESDE LA CLAVE PLIVADA WIF "5KMA1fY8AiDQgc8jgGEQPCTKXHm4FgUQ6rbvSkTsYPNY5sfufRv' O DESDE UNA CLAVE HEX "cacc96cbe474b7eab87da1b35eac0206193ca2776cabd862450d83835e6b2ae6"

TIENES QUE ESPECIFICAR QUE ES LO QUE QUIERES HACER

Was this page helpful?
0 / 5 - 0 ratings

Related issues

askucher picture askucher  ·  3Comments

silence-may picture silence-may  ·  3Comments

LeonYanghaha picture LeonYanghaha  ·  3Comments

panpan2 picture panpan2  ·  3Comments

yakitorifoodie picture yakitorifoodie  ·  3Comments