我正在使用比特币测试网创建一个原始交易,但是当我将原始交易推送到网络上时,它会占用我所有的余额。我是否应该将剩余的“零钱”发回给自己?这是我用来创建原始交易的代码:
var bitcoin = require('bitcoinjs-lib');
var keyPair = bitcoin.ECPair.fromWIF('cMvPQZiG5mLARSjxbBwMxKwzhTHaxgpTsXB6ymx7SGAeYUqF8HAT', bitcoin.networks.testnet);
var tx = new bitcoin.TransactionBuilder(bitcoin.networks.testnet);
tx.addInput('87502f792d477f0514a92486c875fa1fb631fd68c95ccf458c264155165a95c6', 1);
tx.addOutput('msWccFYm5PPCn6TNPbNEnprA4hydPGadBN', 10000);
tx.sign(0, keyPair);
console.log(tx.build().toHex());
我是否正确地认为我也必须将剩余的金额寄回给自己?例如,如果我的原始余额是 0.00114 BTC,我会这样做:
tx.addInput('87502f792d477f0514a92486c875fa1fb631fd68c95ccf458c264155165a95c6', 1);
// senders address
tx.addOutput('ms9ySK54aEC2ykDviet9jo4GZE6GxEZMzf ', 104000);
// receivers address
tx.addOutput('msWccFYm5PPCn6TNPbNEnprA4hydPGadBN', 10000);
这是正确的方法吗?