javascript - 使用bitcoinjs的Blockcypher交易签名错误
问题描述
我试图使用 blockcypher 和这里描述的 bitcoinjs lib 签署比特币测试网交易,但我遇到了这个错误,我不知道我做错了什么。
{"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);
});
解决方案
推荐阅读
- android - API 在“flutter run --release”模式下不起作用
- android - 将改造响应传递给函数或复制它
- javascript - 从 HTML 元素中提取 href 无法使用 node.js
- java - Android旋转可绘制按钮
- python - Visual Studio Code 和 Azure 中的异步 python 函数
- ios - 由不等部分分隔的数组中的二维数组
- m2doc - 以编程方式进行 M2doc Sirius 会话
- json - Neo4j:在 Cypher 中返回子树
- docker - 我如何知道在 Docker 中从哪个注册表中提取图像?
- node.js - 创建数据库时的 Postgresql 编码