How to set fee in raw bitcoin transaction using btcutil

Viewed 1289

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?

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.

Related