1

I've created a transaction on the TESTNET and am trying to push it via BlockCyphers facility at:

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

when I make the attempt, I get the following error:

Error validating transaction: Error running script for input 0 referencing 261190892daa2c9aaaf25c20624f7f2941d2ad58dec883b0c929d1fa9306fd57 at 0: Script was NOT verified successfully..

here's the transaction. I don't see what the matter with it is and not sure I understand the error. can anyone help?

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

- Addendum I -

to help narrow down the solution, here's the code I'm using to produce the transaction: I first produce an address where to receive some coin:

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);

which yields mjGtZWXgPdbLUZYWtDqVTfbFieVzXFfSEj. I then send some coin to that address and attempt to create my transaction:

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 => res.json());
var utxos = o.txrefs.map(o => ({
    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 => {
    if (!o.address) o.address = 'msp7depXvcjLqykZxYVrWNG9QgKqLWWKEN';
})

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

from which I get a numerical string that converts to the above transaction. as can be seen, I'm using the same root to sign the transaction that was used to create the source address

2
  • Can you show or tell us how you are creating your transaction? Hard to say without more info.
    – m1xolyd1an
    Commented Jan 10, 2020 at 5:36
  • yes. I will post code to help identify the issue
    – ekkis
    Commented Jan 10, 2020 at 7:27

1 Answer 1

1

You have the wrong public key inside your SignatureScript:

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

The outpoint you are spending (2611[...]fd57:0) has the following PubkeyScript:

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

When the script runs it fails on 0x88 (or OP_EqualVerify) because HASH160 of the given public key (02d7[...]d108) is e652ed9163ac72629584ec92f47602cca45aa969

7
  • amazing feedback. I will try to follow your logic and figure it out. thanks a million
    – ekkis
    Commented Jan 10, 2020 at 7:16
  • I've added code to the post to clarify how I'm building the transaction and what I'm using to sign
    – ekkis
    Commented Jan 10, 2020 at 7:43
  • ok. I've come to understand what you said, and I gather that the field inputs[0].script is populated by my call to the transaction builder's sign() function. that doesn't match the script-pubkey that Block.io generated when I sent coins from there to my address mjGtZWXgPdbLUZYWtDqVTfbFieVzXFfSEj... so the question is why that would happen (and how to fix it)
    – ekkis
    Commented Jan 10, 2020 at 8:00
  • FWIW, if I console.log(pubkey.toString('hex') I get: 026c4df6ad30a627bcb045faf913bb25aad26ef9d06a838f8465aead0a63c869ad... which seems to be the Hash160 of 15iBr8YmiWhXbCWRtZhuY9zowF412EwCypjNvY3xX79CX12K8ZH
    – ekkis
    Commented Jan 10, 2020 at 8:06
  • as you can see, I'm passing the root directly to the signature function. originally I was converting to a WIF and then to a key, but I was told I could pass the root directly. see: github.com/bitcoinjs/bip39/issues/129#issuecomment-572365691
    – ekkis
    Commented Jan 10, 2020 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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