Skip to content

RawTransaction send return mandatory-script-verify-flag-failed (Non-canonical DER signature) #1022

@Vutov

Description

@Vutov

I'm using bitcoinjs-lib 3.3.2 and running 2 bitcoin-qt nodes 0.16 on -regtest . I have tried to sign transaction using bitcoinjs and run it in bitcoin-qt console with sendrawtransaction but receive "16: mandatory-script-verify-flag-failed (Non-canonical DER signature) (code -26)"

There is unspent transaction :

{
    "txid": "77d0b6383f93b528333b0f0bd68aab33a3d08cdd05c50e258a7b775d7bfd2527",
    "vout": 0,
    "address": "mhZ1A3Cyqg9XQnRpmYkqjdTzL8yTaBpFf2",
    "scriptPubKey": "21039a0c9cb7c374df809965e4cfeb109ee0e1c7f3a0ee4b4f0cea04eebf25a27ee7ac",
    "amount": 50.00000000,
    "confirmations": 101,
    "spendable": true,
    "solvable": true,
    "safe": true
  }

I use dumpprivkey to get fromWIF value and getnewaccount for the receiver account

The code I'm using:

var testnet = bitcoin.networks.testnet
var value = 50 * 10e7 - 10000;
var key = bitcoin.ECPair.fromWIF("cMrFVDpeP3wvmNRpHLerhtwPY1mwHN3BTYCV1vNtP4zSvvZm11KN", testnet);
var tx = new bitcoin.TransactionBuilder(testnet);
tx.addInput("77d0b6383f93b528333b0f0bd68aab33a3d08cdd05c50e258a7b775d7bfd2527", 0);
tx.addOutput("2N9W57WJHgh8Yiev6s5he1Qn99DkZyKSkYg", value);
tx.sign(0, key);
console.log(tx.build().toHex());

Ive tried with sigwit as well - same result:

var keyPair = bitcoin.ECPair.fromWIF('cPzku2sUaQacgoKNjmS3FZtVrFxB4JtHFiS8y44g9Dr4rMMNn9Di', testnet)
var pubKey = keyPair.getPublicKeyBuffer()
var pubKeyHash = bitcoin.crypto.hash160(pubKey)

var redeemScript = bitcoin.script.witnessPubKeyHash.output.encode(pubKeyHash)
var redeemScriptHash = bitcoin.crypto.hash160(redeemScript)

var scriptPubKey = bitcoin.script.scriptHash.output.encode(redeemScriptHash)
var address = bitcoin.address.fromOutputScript(scriptPubKey, testnet)

var txb = new bitcoin.TransactionBuilder(testnet)
txb.addInput("77d0b6383f93b528333b0f0bd68aab33a3d08cdd05c50e258a7b775d7bfd2527", 0);
txb.addOutput("2MxSE48F9ZgsTghEgNjzNEDZoZbQnR4fcfh", value);
txb.sign(0, keyPair, redeemScript, null, value)

console.log(txb.build().toHex());

Any advice would be greatly appriciated

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions