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