bitcoinjs-lib: "Error.captureStackTrace is not a function" when creating keypair from privatekey on different network

        const hash = bitcoin.crypto.sha256(Buffer.from("my seed here"))
        const network = coininfo(`DASH-TEST`).toBitcoinJS();
        const keyPair = bitcoin.ECPair.fromPrivateKey(hash,{network})
        console.log(keyPair)


When there is no network option it works fine

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 17 (12 by maintainers)

Most upvoted comments

Just insert the network info needed for DASH.

Then just count up the keys / accounts according to BIP44.

const bip39 = require('bip39')
const bip32 = require('bip32')
const bitcoin = require('bitcoinjs-lib')

const DASH = { // DASH
  "messagePrefix": '\u0018Dash Signed Message:\n',
  "bip32": {
    "public": 0x0488b21e,
    "private": 0x0488ade4
  },
  "pubKeyHash": 0x4c,
  "scriptHash": 0x10,
  "wif": 0xcc
}

let phrase = bip39.generateMnemonic() // generate a random phrase
//  phrase = 'device lady dose anger fire catch junk turtle elite possible correct venue'

let seed = bip39.mnemonicToSeed('device lady dose anger fire catch junk turtle elite possible correct venue')
//  seed (hex) = '4a9b302fbbcf4165575c4bf234a4346a6295301d3f79986eff34514ff217e74468f236ba26a70181d90e1bdfb628f652d75beb9b061d325343d8e8e38f031429'

let rootNode = bip32.fromSeed(seed, DASH)

// 5' is DASH BIP44 coin value
let firstAccount = rootNode.derivePath("m/44'/5'/0'")

let xpub = firstAccount.neutered().toBase58()
// xpub6DX8xdrSMpep9No44GiHTBrXS8spKXUSypS11qtUxRVmBNkyAi9BX1FWn3tLUWeHM6JKiPMyTWMfndkp6oAKp9UAXvcreFVhtbhEE47hZD1

let firstKey = firstAccount.derivePath("0/0")

let address = bitcoin.payments.p2pkh({ pubkey: firstKey.publicKey, network: DASH }).address
// Xw6f5rFzLLAu2d9o8xaEfscuFXbqfMxckg

let firstKeyECPair = bitcoin.ECPair.fromPrivateKey(firstKey.privateKey, { network: DASH })

let wif = firstKeyECPair.toWIF()
// XHXPznM8PEFnkman8aYqG2uRDPT6jxQxKsVmGqxgRdEPha8DPNCG

Thanks, can you point on source

No source, I just made it up because it is irrelevant to the error, and typeforce was yelling at me.

Thanks, can you point on source of

“messagePrefix”: ‘\u0018Dash Signed Message:\n’

@dcousens it’s provided in the codesandbox above. Just comment the line 25 to see the error