Bitcoinjs-lib: Error : 16: mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)

Created on 5 Aug 2018  ·  13Comments  ·  Source: bitcoinjs/bitcoinjs-lib

I am trying to run the following code snippet:

var keyPair = bitcoin.ECPair.fromWIF('cQRu7yq9HPwm5NhLvYuAEc7iRzEBP5x35Q6UBW6skjfZUn2Z68xZ', bitcoin.networks.testnet)
     const txb = new bitcoin.TransactionBuilder(bitcoin.networks.testnet)
      txb.addInput('0ebd063bfe6d272567a6099ad8e1ab6991d8a002dda011f43bda7b54b073e86d', 0)
      txb.addOutput('n3CKupfRCJ6Bnmr78mw9eyeszUSkfyHcPy', 55000000-5000)
      txb.sign(0, keyPair)
console.log(txb.build().toHex()); 

If i use the generated raw transaction using bitcoin core cliet i keep getting the error:
16: mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)

how to / question / docs

Most helpful comment

i haven't noticed that the input i am trying to consume is a p2sh not a p2pkh.

All 13 comments

i haven't noticed that the input i am trying to consume is a p2sh not a p2pkh.

@bellaj hi, How did you solve this problem?

@junderw thank you very much

@junderw can you help me ? If 'txb.addInput(unspent.txId, unspent.vout)' had more than one , What changes will “ txb.sign(0, keyPair, p2sh.redeem.output, null, unspent.value)
” take?

What do you mean by more than one? More than one input or more than one signature required?

@dcousens More than one input

@dcousens if more than one input , How to deal with parameter "unspent.value" of function "txb.sign()"?

@ShangXoL to have more than one input, is identical to having more than one unspent.
If you have multiple inputs, you should have multiple unspents.
Use each unspent's .value respectively.

@dcousens
var bitcoin = require("bitcoinjs-lib");
const net = bitcoin.networks.testnet;
const keyPair = bitcoin.ECPair.fromWIF("cTDMViKByraUgTryu2bUrv4nj9KF6tjhb9gj1vy9SEQeFQH6hcjL", net);
const p2wpkh = bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey, network: net })
const p2sh = bitcoin.payments.p2sh({ redeem: p2wpkh, network: net })

var tx = new bitcoin.TransactionBuilder(net);
tx.setVersion(2);
tx.addInput("58aab89435bad892ff0817f5296d48faa564dfc369b12121c2e5521ec5f7db0b", 0);//99990000
tx.addInput("31f4d3025a026738ab45b62078c64924f26eee5c7bd1ca5b8f84a46be6e963c9", 1);//70000000
tx.addOutput("2NGVjpAzsd9JPnm1jKHeJtNk3e1FBsCHXZU", 169980000);
tx.sign(0, keyPair, p2sh.redeem.output, null, 169990000);//<--------------------------
console.log(tx.build().toHex());

tx.sign(0, keyPair, p2sh.redeem.output, null, 169990000);//<--------------------------

is that so?

no

99990000 and 70000000

tx.sign(0, keyPair, p2sh.redeem.output, null, 99990000)
tx.sign(1, keyPair, p2sh.redeem.output, null, 70000000)

@junderw @dcousens Thank you so much, i get it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prahaladbelavadi picture prahaladbelavadi  ·  3Comments

Mr-Mondragon picture Mr-Mondragon  ·  3Comments

tuyennvtb picture tuyennvtb  ·  3Comments

askucher picture askucher  ·  3Comments

rbndg picture rbndg  ·  3Comments