我正在尝试使用here描述的blockcypher和bitcoinjs签署比特币测试网交易,但是我遇到了这个错误
{"error": "Couldn't deserialize request: invalid character 'x' in literal true (expecting 'r')"}
搜索时,我找不到解决问题的方法,我已经联系了blockcypher,但他们尚未做出回应。这是我用来签署交易的代码,有人知道为什么它会给我这个错误吗?
var bitcoin = require("bitcoinjs-lib");
var buffer = require('buffer');
var keys = new bitcoin.ECPair.fromWIF('cMvPQZiG5mLARSjxbBwMxKwzhTHaxgpTsXB6ymx7SGAeYUqF8HAT', bitcoin.networks.testnet);
var newtx = {
inputs: [{addresses: ['ms9ySK54aEC2ykDviet9jo4GZE6GxEZMzf']}],
outputs: [{addresses: ['msWccFYm5PPCn6TNPbNEnprA4hydPGadBN'], value: 1000}]
};
// calling the new endpoint, same as above
$.post('https://api.blockcypher.com/v1/btc/test3/txs/new', JSON.stringify(newtx))
.then(function(tmptx) {
// signing each of the hex-encoded string required to finalize the transaction
tmptx.pubkeys = [];
tmptx.signatures = tmptx.tosign.map(function(tosign, n) {
tmptx.pubkeys.push(keys.publicKey.toString("hex"));
const SIGHASH_ALL = 0x01;
return bitcoin.script.signature.encode(keys.sign(new buffer.Buffer(tosign, "hex")), SIGHASH_ALL,).toString("hex");
});
// sending back the transaction with all the signatures to broadcast
$.post('https://api.blockcypher.com/v1/btc/test3/txs/send', tmptx).then(function(finaltx) {
console.log(finaltx);
}).catch(function (response) {
console.log(response.responseText);
});
}).catch(function (response) {
console.log(response.responseText);
});