我将比特币的一种地址发送给另一地址时遇到序列化错误: npm版本的“ bitcore-explorers”:“ ^ 1.0.1”, “ bitcore-lib”:“ ^ 8.22.2”
const explorers=require('bitcore-explorers')
var insight=new explorers.Insight();
var bitcore = require('bitcore-explorers/node_modules/bitcore-lib');
var privateKeyWIF='L4xkFv5sbttQcsgnTjzqJuQdNfHC5gk9zsK5HmaV822qu79zJA7L';
var privateKey = bitcore.PrivateKey.fromWIF(privateKeyWIF);
var sourceAddress = privateKey.toAddress();
var targetAddress = '1HgaQXpi9GC57zCPd1X8NHkPJaizEh6g8N'
insight.getUnspentUtxos(sourceAddress, function (error, utxos) {
if (error) {
console.log(error);
} else {
console.log(utxos);
var tx = new bitcore.Transaction();
tx.from(utxos);
tx.to(targetAddress, 10000);
tx.change(sourceAddress);
tx.fee(50000)
tx.sign(privateKey);
console.log(tx.serialize());
insight.broadcast(tx, function (error, transactionId) {
if (error) {
console.log("hii3")
console.log(error);
} else {
console.log("hiii4")
console.log(transactionId);
}
});
}
});
///////
源地址:1Mc4kW9KbVfcEWzYhXU46xxMHMFcDxUDsn 目标地址:1HgaQXpi9GC57zCPd1X8NHkPJaizEh6g8N []
throw serializationError;
^
未定义 错误
答案 0 :(得分:0)
bitcore
使用 bitpay
作为默认提供程序服务器,但由于某种原因,它无法正常工作。他们还建议更改 [docs][1] 中的默认服务器。
尝试将提供程序更改为 zelcore
,如下所示:
const explorers = require("bitcore-explorers");
const insight = new explorers.Insight("https://explorer.btc.zelcore.io");