繁体   English   中英

比特币交易序列化错误

[英]Serialization error on bitcoin transaction

当我将比特币一个地址发送到另一个地址时出现序列化错误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;
^

未定义错误

bitcore使用bitpay作为默认提供商服务器,但由于某种原因,它无法正常工作。 他们还建议更改 [docs][1] 中的默认服务器。 尝试将提供程序更改为zelcore如下所示:

const explorers = require("bitcore-explorers");
const insight = new explorers.Insight("https://explorer.btc.zelcore.io");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM