Raw-Transaction

交易驗證失敗(錯誤執行腳本)

  • January 10, 2020

我在 TESTNET 上創建了一個事務,並試圖通過 BlockCyphers 工具將其推送到:

<https://live.blockcypher.com/btc-testnet/pushtx/>

當我嘗試時,我收到以下錯誤:

驗證交易時出錯:執行輸入 0 的腳本時出錯,在 0 處引用 261190892daa2c9aaaf25c20624f7f2941d2ad58dec883b0c929d1fa9306fd57:腳本未成功驗證。

這是交易。我不明白這是怎麼回事,也不確定我是否理解錯誤。誰能幫忙?

{
   "addresses": [
       "mjGtZWXgPdbLUZYWtDqVTfbFieVzXFfSEj", 
       "2N7nSZjfqikj4oVkCqaLB3CNMY3TA72PbNY", 
       "msp7depXvcjLqykZxYVrWNG9QgKqLWWKEN"
   ], 
   "block_height": -1, 
   "block_index": -1, 
   "confirmations": 0, 
   "double_spend": false, 
   "fees": 12375, 
   "hash": "463372d7a8f456c882179635aabbeca4146396b1f81c05699a2e885e3f84d6e6", 
   "inputs": [
       {
           "addresses": [
               "mjGtZWXgPdbLUZYWtDqVTfbFieVzXFfSEj"
           ], 
           "age": 1657999, 
           "output_index": 0, 
           "output_value": 5000000, 
           "prev_hash": "261190892daa2c9aaaf25c20624f7f2941d2ad58dec883b0c929d1fa9306fd57", 
           "script": "48304502210093b8ff9180a8a31a5ee7b0fb6c560aef888a3d53576e530cb4601dce2d3c51da02204fd8a28743f1d1100a2f56428e743501091e833550df6cf540bad4f5248a6d3c012102d794c7e1a8068782ef6ee68acf9f6ad9c84c78349671c1a7bf60418a8e1ed108", 
           "script_type": "pay-to-pubkey-hash", 
           "sequence": 4294967295
       }
   ], 
   "outputs": [
       {
           "addresses": [
               "2N7nSZjfqikj4oVkCqaLB3CNMY3TA72PbNY"
           ], 
           "script": "a9149f792783320ffb5a4f3ee4c69525d4932ac0497087", 
           "script_type": "pay-to-script-hash", 
           "value": 500
       }, 
       {
           "addresses": [
               "msp7depXvcjLqykZxYVrWNG9QgKqLWWKEN"
           ], 
           "script": "76a91486e0602ab38efd1811ff4db76f7d58c717c8598888ac", 
           "script_type": "pay-to-pubkey-hash", 
           "value": 4987125
       }
   ], 
   "preference": "high", 
   "received": "2020-01-10T05:09:49.945289619Z", 
   "relayed_by": "54.197.194.161", 
   "size": 224, 
   "total": 4987625, 
   "ver": 2, 
   "vin_sz": 1, 
   "vout_sz": 2
}

- 附錄一 -

為了幫助縮小解決方案的範圍,這是我用來生成交易的程式碼:我首先生成一個接收硬幣的地址:

const btc = require('bitcoinjs-lib');
const bip39 = require('bip39');
const bip32 = require('bip32');

var mnem = 'my-12-word-bip39-seed-phrase'
var root = = bip32.fromSeed(
 bip39.mnemonicToSeedSync(mnem), bitcoin.networks.testnet
);
var p = "m/44'/1'/0'/0/0"
var pubkey = root.derivePath(p).publicKey;
var {address} = btc.payments.p2pkh({pubkey, network: btc.networks.testnet});
console.log(address);

產生mjGtZWXgPdbLUZYWtDqVTfbFieVzXFfSEj。然後我向該地址發送一些硬幣並嘗試創建我的交易:

const CS = require('coinselect');
var feeRate = 55;
var env = 'test3'
var src = 'mjGtZWXgPdbLUZYWtDqVTfbFieVzXFfSEj'
var url = `https://api.blockcypher.com/v1/btc/${env}/addrs/${src}?unspendOnly=true`;
var o = await fetch(url).then(res =&gt; res.json());
var utxos = o.txrefs.map(o =&gt; ({
   txId: o.tx_hash, 
   vout: parseInt(o.tx_output_n), 
   value: parseInt(o.value)
}));
var targets = [{address: '2N7nSZjfqikj4oVkCqaLB3CNMY3TA72PbNY', value: 500}];
var {inputs, outputs, fee} = CS(utxos, targets, feeRate);
if (ret.outputs) ret.outputs.forEach(o =&gt; {
   if (!o.address) o.address = 'msp7depXvcjLqykZxYVrWNG9QgKqLWWKEN';
})

// builds the transaction
var tx = new btc.TransactionBuilder(btc.networks.testnet);
inputs.forEach(o =&gt; tx.addInput(o.txId, o.vout));
outputs.forEach(o =&gt; tx.addOutput(o.address, o.value));
tx.sign(0, root);
console.log(tx.build().toHex());

從中我得到一個轉換為上述事務的數字字元串。可以看出,我使用相同的根來簽署用於創建源地址的交易

您的 SignatureScript 中有錯誤的公鑰:

Sig: 48-304502210093b8ff9180a8a31a5ee7b0fb6c560aef888a3d53576e530cb4601dce2d3c51da02204fd8a28743f1d1100a2f56428e743501091e833550df6cf540bad4f5248a6d3c-01
pubkey: 21-02d794c7e1a8068782ef6ee68acf9f6ad9c84c78349671c1a7bf60418a8e1ed108

您花費的 outpoint ( 2611[...]fd57:0) 具有以下 PubkeyScript:

76-a9-14-2937902660c169b9381a5b3eb35cc889a4686a85-88-ac

當腳本執行時,它在 0x88(或 OP_EqualVerify)上失敗,因為給定公鑰 (02d7[…]d108) 的 HASH160 是e652ed9163ac72629584ec92f47602cca45aa969

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