简体   繁体   English

如何使用BitcoinJS设置交易费用金额?

[英]How to set amount of transaction fee using BitcoinJS?

How to setup transaction fee using BitcoinJS? 如何使用BitcoinJS设置交易费用?

For example, i have unspent TX on 0.2 BTC lets call it myTx , and i want send to Bob 0.1 BTC, but if i do something like this: 例如,我在0.2 BTC上有未使用的TX,可以将其myTx ,我想发送给Bob 0.1 BTC,但是如果我做这样的事情:

 var tx = new bitcoin.TransactionBuilder(); tx.addInput(myTx, 0) var keyPair = bitcoin.ECPair.fromWIF(privateKeyWIF) tx.sign(0, keyPair) tx.addOutput("1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK", 10000000) tx.sign(0, keyPair) 

It send 0.1 BTC to Bob and take 0.1 as fee, so how to set fee manually when you sending not all BTC from input? 它向Bob发送0.1 BTC并收取0.1手续费,那么当您从输入中未发送所有BTC时如何手动设置费用?

One possibility could be that you sent yourself the amount of bitcoin that you don't want to pay as a fee. 一种可能是您向自己发送了不想支付的比特币金额。 For example: 例如:

Send x=0.1 BTC to bob, Send y=0.05 BTC to yourself -> Fee is z=0.05 将x = 0.1 BTC发送给bob,将y = 0.05 BTC发送给自己->费用为z = 0.05

Change y as you desire. 根据需要更改y。

函数TransactionBuilder (network, maximumFeeRate)接受第二个参数,该参数表示为交易设置的最高费用。

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

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