Bitcoinjs-lib: DogeCoin TransactionBuilder example?

Created on 21 Aug 2017  路  3Comments  路  Source: bitcoinjs/bitcoinjs-lib

Can anyone give me an example how to create and sign DogeCoin transaction please? I tried something like this:

var bitcoin = require('bitcoinjs-lib');
var coininfo = require('coininfo');
var doge_network = coininfo.dogecoin.main.toBitcoinJS();

var tx = new bitcoin.TransactionBuilder(doge_network)

// Add the input (who is paying):
// [previous transaction hash, index of the output to use]
var txId = 'ac3e9372e66281bf57b2146b90ede4223e15bb5575dae0e74ce0c55fa9cf7b7d'
tx.addInput(txId, 0)

// Add the output (who to pay to):
// [payee's address, amount in satoshis]
tx.addOutput("DG5xxVMn6jRLqoX3KiQAdMAHGy5GJhG8YU", 1000000000)

// Initialize a private key using WIF
var privateKeyWIF = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
var keyPair = bitcoin.ECPair.fromWIF(privateKeyWIF, doge_network)

// Sign the first input with the new key
tx.sign(0, keyPair)

// Print transaction serialized as hex
console.log(tx.build().toHex())
// => 0100000001313eb630b128102b60241ca895f1d0ffca21 ...

// You could now push the transaction onto the Bitcoin network manually
// (see https://blockchain.info/pushtx)

but I got:

        throw tfSubError(e, propertyName)
        ^
Error
    at new TfTypeError (C:\Users\s718\node_modules\typeforce\errors.js:5:24)
    at typeforce (C:\Users\s718\node_modules\typeforce\index.js:193:11)
    at _object (C:\Users\s718\node_modules\typeforce\index.js:99:11)
    at _maybe (C:\Users\s718\node_modules\typeforce\index.js:35:35)
    at typeforce (C:\Users\s718\node_modules\typeforce\index.js:191:9)
    at _object (C:\Users\s718\node_modules\typeforce\index.js:99:11)
    at typeforce (C:\Users\s718\node_modules\typeforce\index.js:191:9)
    at typeforce (C:\Users\s718\node_modules\typeforce\index.js:197:10)
    at new ECPair (C:\Users\s718\node_modules\bitcoinjs-lib\src\ecpair.js:17:5)
    at Function.ECPair.fromWIF (C:\Users\s718\node_modules\bitcoinjs-lib\src\ecpair.js:81:10)
external how to / question / docs

Most helpful comment

Maybe it is '\x19Dogecoin Signed Message:n', but it may not be.

I think it is, cuz it's working for me :)

To be honest, I think we should drop the messagePrefix from this library...

I agree. IMO it would be best if there were a lib containing network list only, but bitcoinjs-message seems to be a good option.

All 3 comments

coininfo's message prefix is null, this is the cause. What it should be?

In Bitcoin, the messagePrefix is '\x18Bitcoin Signed Message:\n',

Maybe it is '\x19Dogecoin Signed Message:\n', but it may not be.

To be honest, I think we should drop the messagePrefix from this library... maybe an isolated network list could be kept at bitcoinjs-message?

Maybe it is '\x19Dogecoin Signed Message:n', but it may not be.

I think it is, cuz it's working for me :)

To be honest, I think we should drop the messagePrefix from this library...

I agree. IMO it would be best if there were a lib containing network list only, but bitcoinjs-message seems to be a good option.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yakitorifoodie picture yakitorifoodie  路  3Comments

panpan2 picture panpan2  路  3Comments

LeonYanghaha picture LeonYanghaha  路  3Comments

thrastarson picture thrastarson  路  3Comments

coingeek picture coingeek  路  4Comments