Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set fee in raw bitcoin transaction using btcutil

Tags:

go

bitcoin

According to the docs (http://godoc.org/github.com/btcsuite/btcrpcclient) the fee can be set by using

SetTxFee(fee btcutil.Amount) // hard coded0.0006 BTC

I set the fee to 0.0000016 bitcoin/kilobyte and do as follow:

  1. ListUnspent
  2. SetTxFee
  3. CreateRawTransaction
  4. SignRawTransaction
  5. SendRawTransaction

But when i try to send transaction i get

-26: 256: absurdly-high-fee

Is there any other way to set the fee using this library?

Debug.log

ThreadRPCServer method=listunspent
ThreadRPCServer method=settxfee
ThreadRPCServer method=createrawtransaction
ThreadRPCServer method=signrawtransaction    
ThreadRPCServer method=sendrawtransaction

Amounts:

amounts := map[btcutil.Address]btcutil.Amount{
     destAddress: destAmount,
}

UPDATE It seems like it tries to send whole sum of the transaction, not the amount i want it to send.

If transaction in to A is 1 BTC and i want to send 0.3 BTC to another address, how to achieve this when setting amounts?

like image 611
Amidii Avatar asked Aug 13 '17 17:08

Amidii


People also ask

How do I add a transaction fee to Bitcoin?

On the main page of your wallet, select your unconfirmed transaction. 2. Tap Increase fee. If your wallet balance is close to zero, you may not have enough funds in your wallet to pay for the additional transaction fees.

What is the transaction fee for 1 Bitcoin?

Two of the main factors that determine Bitcoin transaction fees are the data volume of the transaction and the speed at which the user wants their transaction completed. As of Aug. 23, 2022, the average Bitcoin transaction fee is 0.000044 BTC, or $0.957.

Who pays the transaction fee on Bitcoin?

This fee is paid to cryptocurrency miners, which are the systems that process the transactions and secure the respective network. Coinbase incurs and pays these fees directly. Accordingly, Coinbase will charge a fee based on our estimate of the network transaction fees for a stand-alone wallet-to-wallet send.


1 Answers

settxfee is not for createrawtransaction command.

if you have one input with 1 BTC and you would send 0.9 BTC so remaining amount is the transaction fee.

if you don't want to set transaction fee for 0.1 BTC you could send 0.09 to change address and leave that 0.01 and it's your transaction fee.

like image 76
Adam Avatar answered Oct 06 '22 06:10

Adam