Bitcoinjs-lib: Generating Litecoin HD wallet

Created on 18 Oct 2018  路  14Comments  路  Source: bitcoinjs/bitcoinjs-lib

Am trying to generate a litecoin hd wallet and i get "Invalid network version".

Here is my code...

const bip32 = require('bip32')

const network = {
        messagePrefix: '\x19Litecoin Signed Message:\n',
        bip32: { 
          public: 0x043587cf,
          private: 0x04358394
        },
        pubKeyHash: 0x6f,
        scriptHash: 0xc4, //  for segwit (start with 2)
        wif: 0xef
    }

var root = bip32.fromBase58("xxxxxxxxxxxx", network)

var account = root.derivePath("m/44'/2'/0'/0'")

return account

Please am i missing something??

how to / question / docs

All 14 comments

"xxxxxxxxxxxx" needs to start with tprv or tpub but you probably are using xprv or xpub

tprv9s21ZrQH143K2wisZE8ncEu33T4WDRmiT7uK5XeXfb3R4YfRMQQiaT6p2YDjsX7zC4UzaUxTyyXpEZeTmtVsedjnxfPdsTPqEgPUGVwW1oT

This is not a valid tprv... how did you make it? The contents is garbage.

Here's an example of a valid tprv:

tprv8ZgxMBicQKsPeyNs2qAvUt3wqem4pBWrTVixFQoAhrb7fRDcbuJjbyLmQvMBscG2zjeJu8H6C7cp9oQXaSvceMNxxsMzqmGGfN34H6buhE6

tprv9s21ZrQH143K2wisZE8ncEu33T4WDRmiT7uK5XeXfb3R4YfRMQQiaT6p2YDjsX7zC4UzaUxTyyXpEZeTmtVsedjnxfPdsTPqEgPUGVwW1oT

This is not a valid tprv... how did you make it? The contents is garbage.

Here's an example of a valid tprv:

tprv8ZgxMBicQKsPeyNs2qAvUt3wqem4pBWrTVixFQoAhrb7fRDcbuJjbyLmQvMBscG2zjeJu8H6C7cp9oQXaSvceMNxxsMzqmGGfN34H6buhE6

I used https://bip39.net to generate xprv key..... Please what is the best way to generate a valid key for livenet and testnest?

That site only generates xprv keys...... where did you get your tprv key?

That site only generates xprv keys...... where did you get your tprv key?

I replaced xprv with tprv and that's what was giving me error... Your tprv key worked fine. Please how did you generate your key?

I replaced xprv with tprv

That's not how it works. You need to base58check decode the xprv, replace the first 4 bytes with the 4 byte header for tprv, then base58check encode again.

If you change the letters directly the checksum won't match.

@junderw thanks for your answers...
One more question please! Is it the same procedure for Bitcoin Cash?

@Laccy-P BIP32 is coin-agnostic.

@Laccy-P BIP32 is coin-agnostic.

Yeah... Have already tried it but another issue is that i get
bash Signature must use SIGHASH_FORKID
when i try broadcasting a bitcoin cash transaction i built with bitcoinjs. 馃槥

I rebased a branch for BCH support here:

https://github.com/junderw/bitcoinjs-lib/tree/cash402

However, bitcoinjs-lib will not support BCH officially.

@ch4ot1c The sighash only signifies the method used to sign. BCH uses a different signature preimage generation logic that needs to be implemented.

I rebased a branch for BCH support here:

https://github.com/junderw/bitcoinjs-lib/tree/cash402

However, bitcoinjs-lib will not support BCH officially.

@ch4ot1c The sighash only signifies the method used to sign. BCH uses a different signature preimage generation logic that needs to be implemented.

@junderw Have installed your branch(cash402) and i still get

bash '16: mandatory-script-verify-flag-failed (Script failed an OP_EQUALVERIFY operation). Code:-26'
when i try broadcasting using https://test-bch-insight.bitpay.com/api/tx/send.

Here is my code, don't know where am getting it wrong please i really need help.

````js
var tx = new bitcoincashjs.TransactionBuilder(network)

tx.addInput(txid, vout)

tx.addOutput(bchaddrjs.toLegacyAddress(request.input('receiving_address')), sending_amount_sat)

tx.addOutput(bchaddrjs.toLegacyAddress(change_address), change_amount)

var account = root.derivePath("m/44/145'/1'/1")

tx.sign(0, account)

tx.build().toHex()
````

  1. You need to run TransactionBuilder.prototype.enableBitcoinCash
  2. You need the input amount to sign for BCH, and you need to pass it to the sign function.

Please take time to learn how something works before asking a question.

This is getting off topic, so I am closing this thread.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

zhaozhiming picture zhaozhiming  路  3Comments

dcousens picture dcousens  路  3Comments

dakk picture dakk  路  3Comments

LeonYanghaha picture LeonYanghaha  路  3Comments