Changelly

Cryptocurrency

bitcoinjs – Error validating transaction … Script was NOT verified successfully

1 Mins read


I’m getting this error below when trying to broadcast a transaction with the code below. I’m new to blockchain development and I’ve been trying to solve this but can’t seem to figure it out. I believe I’m inputting incorrect values, but I’m unsure which, could someone let me know? Let me know what other details you need.

Transaction Hex:
02000000000101ed651c31084977c5125c975b0831b01504ac5888b2b8596005a5b2cb88627b670000000017160014dd8ad4d50e55c26ce36be3eb3ec2bbf44615d9a4ffffffff01282300000000000017a91416d7b959cf850264a10e55c2f2b7d85cfacd5059870247304402205c21b8f3e1187ff1963aa3f7ab27054c12d634a18f25038e21a20dd1869440cb022051abe3dd1b6ded962f2a60aa0d419734aa1daa494b5edfded0b935ff3227f656012102e472751c45225337885f86e50e41912424f3831d7d5b1a5a2958cd618507b03b00000000

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

const bitcoin = require('bitcoinjs-lib')
const network = bitcoin.networks.testnet
    
const keyPairAlice1 = bitcoin.ECPair.fromWIF('cMz5Wmw7ee7x57Tbm1W77Apf9AkE9uJy19fqaGVfBdnRoFDL9Bus', network) 
const p2wpkhAlice1 = bitcoin.payments.p2wpkh({pubkey: keyPairAlice1.publicKey, network}) 
const p2shAlice1 = bitcoin.payments.p2sh({redeem: p2wpkhAlice1, network}) 
const redeemScript = p2shAlice1.redeem.output.toString('hex')


const psbt = new bitcoin.Psbt({network})
  .addInput({
    hash: '677b6288cbb2a5056059b8b28858ac0415b031085b975c12c5774908311c65ed',
    index: 0,
    witnessUtxo: {
      script:
        // Buffer.from('0014dd8ad4d50e55c26ce36be3eb3ec2bbf44615d9a4', 'hex'), 
        Buffer.from('a914' +
        bitcoin.crypto.hash160(Buffer.from('0014' + 'dd8ad4d50e55c26ce36be3eb3ec2bbf44615d9a4', 'hex')).toString('hex') +
        '87', 'hex'),
      value: 10000, 
    },
    redeemScript: Buffer.from(redeemScript, 'hex')
  })
  .addOutput({
    address: "2MuL1HGkV9hAmGwefCAr4fa2Kk63CHYFo6u",
    value: 9000,
  })

psbt.signInput(0, keyPairAlice1)
psbt.validateSignaturesOfInput(0)
psbt.finalizeAllInputs()

console.log('Transaction hexadecimal:')
console.log(psbt.extractTransaction().toHex())



Source link

Related posts
Cryptocurrency

6 Questions for Mati Greenspan of Quantum Economics – Cointelegraph Magazine

2 Mins read
We ask the buidlers in the blockchain and cryptocurrency sector for their thoughts on the industry… and we throw in a few…
Cryptocurrency

Crypto Conference DeFiCon 2021 to Be Hosted on December 18-19 in Brooklyn, NYC – Press release Bitcoin News

1 Mins read
press release PRESS RELEASE. The next crypto conference lighting up the season is DeFiCon 2021, hosted on December 18-19 in Brooklyn, NYC….
Cryptocurrency

China’s Hainan Province Ramps Up Crackdown on Crypto Mining Operations – Mining Bitcoin News

2 Mins read
The province of Hainan in South China has taken steps aimed at curbing crypto mining activities. Besides blacklisting the industry, local authorities…

Leave a Reply

Your email address will not be published. Required fields are marked *