5

I am using sendtoaddress API call. The problem is that I need to specify amount that includes fees. For example, if I withdraw 1 btc, I need bitcoind to deduct fees from that amount and in example to send 0.999 as transaction amount and 0.001 as fee (or any other fee amount that recommended for this transaction)

Please, help and tell if that possible to achieve such result.

3 Answers 3

2

https://chainquery.com/bitcoin-api/sendtoaddress

You can use last (5th) parameter:

  1. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent. The recipient will receive less bitcoins than you enter in the amount field.
1
  • 1
    bitcoind accepts this as well now Aug 11, 2017 at 5:54
1

Considering that whatever program (or human) you use to call the API will be able to perform a simple addition or subtraction, this boils down to determining the exact fee to be used. The getinfo (returning the current default fee as in field paytxfee) and settxfee (for changing it) API calls should do that for you. Be careful about details---the blockchain.info API reference warns that the changes you make via settxfee are only valid for the next 24 hours. I have not checked if that information is up-to-date, and if it indeed refers to the bitcoin core behavior or merely to blockchain.info's "Bitcoind compatible" API.

3
  • I figured this out, however in some cases bitcoin forces to add fee and as I know amount may vary... How could I be sure I set right tx fee?
    – murich
    Apr 8, 2014 at 10:30
  • You can't have figured this out! See my answer.
    – T9b
    Apr 16, 2014 at 13:06
  • @murich You're right, my answer only applies in the (frequent and possibly typical) situation where you can guess that you pay the default fee. The bitcoin client may make you pay more if it has to combine many unspent transactions.
    – user6049
    Apr 16, 2014 at 14:07
0

Transaction fees are taken if you construct a transaction in such a way as to imply that a fee is being paid.

For example

  • You have two unspent transaction out puts of 0.6BTC and 0.4BTC
  • You use these two outputs as inputs (which total 1BTC) in your transaction where you pay 1 output address 0.99999BTC.
  • The fee of 0.00001BTC is implied. It is not sent to any address or collected by the software.
  • Your friend receives 0.99999BTC and when the transaction is included in a block, the miner gets 0.00001BTC.

That's basically how it works. You need to consider what is going in to the transaction, as well as what is coming out at the other end.

2
  • You describe how it works when the caller explicitly constructs a raw transaction (e.g. via createrawtransaction). But using sendtoaddress, as the OP specified, the Bitcoin client itself determines which unspent transactions to use and how much the appropriate fee to be included is.
    – user6049
    Apr 16, 2014 at 14:05
  • @pyramids agreed. I assumed the OP was trying to work out how it can be done so that they control the fee. In anycase creating a raw transaction would also mean they should consider minimum fees etc...
    – T9b
    Apr 23, 2014 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.