Get wallet address from WIF with bitcoinjs

BITCOIN Convert private key to WIF

Install

npm i bitcoinjs-lib --save

Source

const bitcoin = require('bitcoinjs-lib');
const net = process.env.USDT_OMNI_NETWORK === 'testnet'
      ? bitcoin.networks.testnet
      : bitcoin.networks.bitcoin;
const alice = bitcoin.ECPair.fromWIF(omniWIF, net);
const alice_p2pkh_legacy_address = bitcoin.payments.p2pkh({
  pubkey: alice.publicKey,
  network: net
}).address;// NEW** New Payments API for p2pkh
console.log(alice_p2pkh_legacy_address);


const alice_p2wpkh_segwit_address = bitcoin.payments.p2sh({
  redeem: bitcoin.payments.p2wpkh({pubkey: alice.publicKey, network: net}),
  network: net
}).address;
console.log(alice_p2wpkh_segwit_address);

Leave a Reply

Your email address will not be published.Required fields are marked *