signature=48008ac0488b385203b0aee1f9fd3891,RawTransaction send return mandatory-script-verify-flag-f...

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值