2

I am trying to push a raw transaction to blockr.io testnet using bitcore (current latest version 0.12.9) for node.js https://github.com/bitpay/bitcore

I have constructed my transaction like so:

var unspents=
[ { txid: '67b22a1874be2e748b2c904e2181f85a9d6503001e58c374e17b1161cd5a36f4',
    vout: 0,
    address: 'myHtNgECiAjBctWz1tM2TN2PupWwfHtgMi',
    scriptPubKey: '76a914c2f9958848c465efd042fcb76fef519f03a83ec288ac',
    amount: 100000,
    confirmations: 39 } ];



    var transaction=new bitcore.Transaction()
    .fee(bitcore.Unit.fromBTC(0.0001).toSatoshis())
    .from(unspents) // there is one unspent of 0.001
    .to(bitcore.Address.fromString(payToAddress),0.001)
    .change(myAddress)
    .sign(privateKey);



console.log(transaction.isFullySigned()); // This returns true

When I POST this to blockr.io I serialize it:

'https://'+'t'+'btc.blockr.io/api/v1/tx/push'    // < t at the beginning is for testnet

{'hex':transaction.serialize()} // 0100000001f4365acd61117be174c3581e0003659d5af881214e902c8b742ebe74182ab267000000006a47304402204f5950a8f8e7346e96101da811452246d51741131310f58d5cfdc064e547d3dc02202b817a442bb043a1174fe0703082ebbd7bc622afc00084710be21fa143444d83012102bbe798da887604bdd360dd059061b48816634e44d9f54563af2c727b8bcb3e2fffffffff02a08601000000000017a9149ffdff1f3eea0deb21ed967b91c7ef3cce65b2d68750f2704e180900001976a914c2f9958848c465efd042fcb76fef519f03a83ec288ac00000000

The response I get back from blockr.io is:

[ { status: 'fail',
    data: 'Could not push your transaction!',
    code: 500,
    message: 'Did you sign your transaction?' },
  500 ]

Below is the transaction I sent but as JSON. I'm thinking there is something wrong with it?

{
"version":1,
"inputs":
[{
    "prevTxId":"67b22a1874be2e748b2c904e2181f85a9d6503001e58c374e17b1161cd5a36f4",
    "outputIndex":0,
    "sequenceNumber":4294967295,
    "script":"47304402204f5950a8f8e7346e96101da811452246d51741131310f58d5cfdc064e547d3dc02202b817a442bb043a1174fe0703082ebbd7bc622afc00084710be21fa143444d83012102bbe798da887604bdd360dd059061b48816634e44d9f54563af2c727b8bcb3e2f",
    "scriptString":"71 0x304402204f5950a8f8e7346e96101da811452246d51741131310f58d5cfdc064e547d3dc02202b817a442bb043a1174fe0703082ebbd7bc622afc00084710be21fa143444d8301 33 0x02bbe798da887604bdd360dd059061b48816634e44d9f54563af2c727b8bcb3e2f",
    "output":{
        "satoshis":10000000000000,
        "script":"76a914c2f9958848c465efd042fcb76fef519f03a83ec288ac"
    }
}]
,"outputs":
[{
    "satoshis":100000,
    "script":"a9149ffdff1f3eea0deb21ed967b91c7ef3cce65b2d687"
},{
    "satoshis":9999999890000,
    "script":"76a914c2f9958848c465efd042fcb76fef519f03a83ec288ac"
}]
,"nLockTime":0,
"changeScript":"OP_DUP OP_HASH160 20 0xc2f9958848c465efd042fcb76fef519f03a83ec2 OP_EQUALVERIFY OP_CHECKSIG",
"changeIndex":1,
"fee":10000

}

I signed it with my private key then serialized it as blockr wants it in hex format does this mean I have got to somehow sign it after it's serialized or what?

And what is the deal with these large numbers:

"satoshis":10000000000000,

"satoshis":9999999890000,

UPDATE:

Block chain info instead returns this error:

Unable To find all tx inputs [67b22a1874be2e748b2c904e2181f85a9d6503001e58c374e17b1161cd5a36f4]
2

The problem is on this line:

amount: 100000,

The amount is supposed to be in coins, not satoshis, according these comments in the code. To fix it, replace that line with

satoshis: 100000,

And what is the deal with these large numbers:

Since the code was assuming an input with 100,000 coins in the inputs, the change address had a lot more coins in it than there should have been.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.