<p>If you call</p>

<pre><code>bitcoin-cli settxfee &lt;fee&gt;
</code></pre>

<p>just before call</p>

<pre><code>bitcoin-cli sendtoaddress "1LipeR1AjHL6gwE7WQECW4a2H4tuqm768N" &lt;value&gt;
</code></pre>

<p>Then the fee will be <code>&lt;fee&gt;</code>.</p>

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

<p>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.</p>

<p><strong>Note 2:</strong> 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 <strong><code>bitcoin-qt -txindex -server &amp;</code></strong> and then letting the interface open. If "recommended" is selected the command <strong><code>settxfee</code></strong> will be ignored. I didn't tested e.g. what if let the "recommended" option selected, close the interface and then start with <strong><code>bitcoind -txindex</code></strong> for example.</p>

<p><a href="https://i.sstatic.net/6rd9i.png" rel="noreferrer"><img src="https://i.sstatic.net/6rd9i.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2021-12-03T17:32:42.890Z
But what if you want to use the floating recommend fee and simply get a rough approximation of it before sending the coins? The question is about calculating the fee, not setting it. I can't believe using raw transactions is the only way to solve it.
Martin Braun
CC BY-SA 3.0
2015-08-24T05:24:59.010Z
2015-08-24T05:31:08.637Z
2015-08-24T05:31:08.637Z
Felipe
<p>A bit late but you might take a look at <a href="https://github.com/bitcoin/bitcoin/pull/5503" rel="nofollow">https://github.com/bitcoin/bitcoin/pull/5503</a>
It's not merged (yet) but it would give you the opportunity to get the fee before sending the transaction (with 4 steps: createrawtransaction, fundrawtransaction [get fee], signrawtransaction, sendrawtransaction)</p>

CC BY-SA 3.0
2015-01-07T09:30:00.377Z
2015-01-07T09:30:00.377Z
Jonas Schnelli
<p>I see this question <a href="https://bitcoin.stackexchange.com/questions/24406/deduct-fee-from-transaction-amount">time</a> and <a href="https://bitcoin.stackexchange.com/questions/1195/how-to-calculate-transaction-size-before-sending">time</a> again, but I only find answers for calculating the fees in creating raw transactions.</p>

<p>I am using <code>sendtoaddress</code> 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.</p>

<p>how might i do this using the json-rpc api? (i'm using bitcoind)</p>

<transactions><bitcoind><transaction-fees><sending>
Calculate tx fees before sending with sendtoaddress
Jon B
# Calculate tx fees before sending with sendtoaddress

(Asked by: username_0 on 2014-06-06)

I see this question [time](https://bitcoin.stackexchange.com/questions/24406/deduct-fee-from-transaction-amount) and [time](https://bitcoin.stackexchange.com/questions/1195/how-to-calculate-transaction-size-before-sending) 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)

**Tags:** transactions, bitcoind, transaction-fees, sending


---

## 2 answers

### Answer by username_1 on 2015-08-24. Score: 5

If you call

```
bitcoin-cli settxfee <fee>

```

just before call

```
bitcoin-cli sendtoaddress "1LipeR1AjHL6gwE7WQECW4a2H4tuqm768N" <value>

```

Then the fee will be `<fee>`.

**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 &`** 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.

[![enter image description here](https://i.sstatic.net/6rd9i.png)](https://i.sstatic.net/6rd9i.png)

> **Comments:**
> **username_2**: But what if you want to use the floating recommend fee and simply get a rough approximation of it before sending the coins? The question is about calculating the fee, not setting it. I can't believe using raw transactions is the only way to solve it.  

---

### Answer by username_3 on 2015-01-07. Score: 0

A bit late but you might take a look at <https://github.com/bitcoin/bitcoin/pull/5503>
It's not merged (yet) but it would give you the opportunity to get the fee before sending the transaction (with 4 steps: createrawtransaction, fundrawtransaction [get fee], signrawtransaction, sendrawtransaction)


---

