RawTransaction send return mandatory-script-verify-flag-failed (Non-canonical DER signature)
See original GitHub issueI’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
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
What does "16: mandatory-script-verify-flag-failed (Non ...
When does this function return true? When all of these conditions are satisfied: /** * A canonical signature exists of: <30> <total len> ......
Read more >(Non-canonical DER signature) - Bitcoin Talk
Always getting Exception: Code: -26, Error: mandatory-script-verify-flag-failed (Non-canonical DER signature) Any idea of why?
Read more >廴聿月月鸟 - CSDN博客
... console with sendrawtransaction but receive "16: mandatory-script-verify-flag-failed (Non-canonical DER signature) (code -26)".
Read more >ECDSA | How To Create Public Keys and Signatures in Bitcoin
This system is used in Bitcoin to allow people to receive and send bitcoins. ... you get "mandatory-script-verify-flag-failed (Non-canonical DER signature) ...
Read more >Unable to send raw transaction: mandatory-script-verify-flag ...
When I send a raw transaction I get an error: 16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Vutov
You might need a minimum block-height on regtest of 432 blocks for segwit… Try
bitcoin-cli generate 432
@tangnv You are spending from P2SH with a P2PKH script.
You are making the transaction wrong.