Calculate tx fees before sending with sendtoaddress I see this question time and time again, but I only find answers for calculating the fees in creating raw transactions.

I am using sendtoaddress and would like to be able to calculate the tx fee needed prior to calling the api. I would like to avoid creating a raw transaction if reasonably possible.

how might i do this using the json-rpc api? (i'm using bitcoind)
If you call

bitcoin-cli settxfee &lt;fee&gt;


just before call

bitcoin-cli sendtoaddress "1LipeR1AjHL6gwE7WQECW4a2H4tuqm768N" &lt;value&gt;


Then the fee will be &lt;fee&gt;.

Important note: make sure in the graphic mode (when you start with bitcoin-qt command) the "custom" is selected, otherwise your command settxfee will be ignored (see image bellow).

Also, I'm not sure if this option is selected by default, and I am not sure as well if it you can set "custom" via API. If someone knows that, please edit this answer and fix it.

Note 2: I'm not sure if this is strictly necessary, maybe not. I didn't make many tests. The test I made was starting bitcoin with bitcoin-qt -txindex -server &amp; and then letting the interface open. If "recommended" is selected the command settxfee will be ignored. I didn't tested e.g. what if let the "recommended" option selected, close the interface and then start with bitcoind -txindex for example.