Raw-Transaction

Bitcore.io 創建原始 tx 十六進制(簽名)以推送到區塊鏈

  • September 10, 2019

我正在嘗試使用 node.js 的 bitcore(目前最新版本 0.12.9)將原始交易推送到blockr.io 測試網<https://github.com/bitpay/bitcore>

我已經像這樣建構了我的交易:

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

當我將其發佈到 blockr.io 時,我將其序列化:

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

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

我從 blockr.io 得到的回復是:

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

以下是我發送的交易,但為 JSON。我在想它有什麼問題嗎?

{
"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

}

我用我的私鑰對其進行了簽名,然後將其序列化為blockr希望它以十六進制格式進行,這是否意味著我必須在序列化後以某種方式對其進行簽名或什麼?

這些大數字是怎麼回事:

"satoshis":10000000000000,

"satoshis":9999999890000,

更新:

相反,塊鏈資訊返回此錯誤:

Unable To find all tx inputs [67b22a1874be2e748b2c904e2181f85a9d6503001e58c374e17b1161cd5a36f4]

問題出在這一行:

amount: 100000,

根據程式碼中的這些註釋,金額應該是硬幣,而不是 satoshis 。要修復它,請將該行替換為

satoshis: 100000,

這些大數字是怎麼回事:

由於程式碼假設輸入中有 100,000 個硬幣,因此找零地址中的硬幣比應有的要多得多。

引用自:https://bitcoin.stackexchange.com/questions/38183