【发布时间】:2017-05-31 21:05:11
【问题描述】:
谁能解释我如何使用 bitcoinjs 发送比特币交易???我已经使用 bitcoinjs 设置了两个钱包。
我想从这里发送 100000 satoshis: 1G4iprWu7Q8tNbQLA8UBM2GearcnzwFrxM
到这里: 1HsrKvboax8J3X1sgsRdWybEwnUNWsDw4Y
如果这里需要它是1G4iprWu7Q8tNbQLA8UBM2GearcnzwFrxM 的最后一笔交易
我使用的代码来自 bitcoinjs.org 网站:
var tx = new bitcoin.TransactionBuilder()
// Add the input (who is paying):
// [previous transaction hash, index of the output to use]
var txId = 'aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31'
tx.addInput(txId, 0)
// Add the output (who to pay to):
// [payee's address, amount in satoshis]
tx.addOutput("1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK", 15000)
// Initialize a private key using WIF
var privateKeyWIF = 'L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy'
var keyPair = bitcoin.ECPair.fromWIF(privateKeyWIF)
// Sign the first input with the new key
tx.sign(0, keyPair)
// Print transaction serialized as hex
console.log(tx.build().toHex())
// => 0100000001313eb630b128102b60241ca895f1d0ffca21 ...
// You could now push the transaction onto the Bitcoin network manually
// (see https://blockchain.info/pushtx)
现在我假设 var txId 是上次交易 here 的交易 ID
`tx.addInput`` 是我放置费用的地方吗?如果是的话,100个就够了吗?
tx.addOutput 是 obvs,所以我可以接受!
var privateKeyWIF* 是我把来自发送地址的私钥放在哪里了吗?
不知道var keyPair 和tx.sign 做了什么!
任何可以帮助告诉我细节应该去哪里的人将不胜感激!对于这个例子,假设我的发件人地址的私钥是 5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF。
干杯
【问题讨论】:
-
你读过documentation - 我假设那是你正在使用的库
-
我记得有一次这让我很困惑,所以我放弃了。祝你好运
-
是的,我已阅读文档并进行了多次尝试。我正在使用的代码生成十六进制格式的交易,但不是所需的交易,我只需要知道它的去向
标签: javascript transactions bitcoin