简体   繁体   English

使用 moneybutton/bsv js 库创建比特币 SV 交易

[英]Create Bitcoin SV transaction with moneybutton/bsv js library

I want to create a raw transaction using the BSV JavaScript library from MoneyButton ( https://github.com/moneybutton/bsv/ ) When creating a bitcoin Satoshi Vision (BSV) transaction I always get an error.我想使用 MoneyButton ( https://github.com/moneybutton/bsv/ ) 中的 BSV JavaScript 库创建原始交易 在创建比特币 Satoshi Vision (BSV) 交易时,我总是收到错误消息。

'node_modules/bsv/lib/encoding/base58check.js:58 if (csum.toString('hex') !== hash4.toString('hex')) { throw new Error('Checksum mismatch') }'

I have also tried to generate the transaction using the JavaScript BitbossIO/keyring library and I was also not able to generate a raw transaction.我还尝试使用 JavaScript BitbossIO/keyring 库生成交易,但也无法生成原始交易。 I don't know which part I'm getting wrong.我不知道我弄错了哪一部分。

const bsv = require('bsv');


var privateKey = new bsv.PrivateKey.fromWIF('pL3yyzZEc96qU8PUyAtk3TBzyosTVGhA1eMWc6icZzS2ZKTnHGuAh');


var utxo = new bsv.UnspentOutput({
  "txId" : "600fee0e6eca8eb19c40f5bfae5871446e617d44c39a3ad44782c571dbf59650",
  "outputIndex" : 1,
  "address" : "12cyVmfJVwkBA4MUSUDarUL2jXiM98JEoe",
  "script" : "76a91411c5d84f5eca47921b0b92042de543f209c301a188ac",
  "satoshis" : 6691
});


var transaction = new bsv.Transaction()

console.log(transaction)
  .from(utxo)
  .to('1PM2zxJArgHFxqYkrFqN7aKQV8nfnEGA56', 5000)
  .change('1PM2zxJArgHFxqYkrFqN7aKQV8nfnEGA56')
  .sign(privateKey);

console.log(transaction.toString());´

I wish I could generate a transaction.我希望我可以生成一个交易。 Also, please find above the private key to the transaction.另外,请在上面找到交易的私钥。 You may use the 10cents, but please help me with the transaction.您可以使用 10 美分,但请帮助我进行交易。 ;) ;)

I believe the key you're using is incorrect, as that's the line that's causing the error because the format is incorrect.我相信您使用的密钥不正确,因为这是导致错误的行,因为格式不正确。

Make sure you're using the correct WIF key.确保您使用的是正确的 WIF 密钥。

It's a while ago.这是前一段时间。 Found it when I was searching for building transactions.在我搜索构建交易时找到了它。

Yes, the key is incorrect.是的,密钥不正确。 I have figured out which is the correct key, and processed the transaction.我已经弄清楚哪个是正确的密钥,并处理了交易。

Here is the code with the correct key:这是带有正确密钥的代码:

"use strict";

const bsv = require("bsv");

//const privateKey = new bsv.PrivateKey.fromWIF('pL3yyzZEc96qU8PUyAtk3TBzyosTVGhA1eMWc6icZzS2ZKTnHGuAh');
const privateKey = bsv.PrivateKey.fromWIF('L3yyzZEc96qU8PUyAtk3TBzyosTVGhA1eMWc6icZzS2ZKTnHGuAh');

const utxo = new bsv.Transaction.UnspentOutput({
  "txId" : "600fee0e6eca8eb19c40f5bfae5871446e617d44c39a3ad44782c571dbf59650",
  "outputIndex" : 1,
  "address" : "12cyVmfJVwkBA4MUSUDarUL2jXiM98JEoe",
  "script" : "76a91411c5d84f5eca47921b0b92042de543f209c301a188ac",
  "satoshis" : 6691
});

const transaction = new bsv.Transaction()
.from(utxo)
.to('1PM2zxJArgHFxqYkrFqN7aKQV8nfnEGA56', 5000)
.change('1PM2zxJArgHFxqYkrFqN7aKQV8nfnEGA56')
.sign(privateKey);

console.log(transaction.toString());

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

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