<p>When you use bitcoind's internal wallet and its related RPCs, it will automatically calculate the transaction fee for you and include that in the transaction. You can then retrieve the transaction fee used by using the <code>gettransaction</code> command. If you want the fee rate that was used, you can use the fee from <code>gettransaction</code> and divide that by the size returned by <code>gettransaction</code>.</p>

<p>Edit: To get the fee before you send, you can create the transaction with only the outputs you want (i.e. no inputs) with <code>createrawtransaction</code>. Then you can use <code>fundrawtransaction</code> to fill out the transaction with inputs. That will also give you the fee that the transaction is paying. Then you sign it with <code>signrawtransaction</code> and send it with <code>sendrawtransaction</code>. There is no other way as the other <code>send*</code> RPCs create the transaction, select coins, sign, and send all in one command.</p>

CC BY-SA 3.0
2017-07-06T20:03:32.297Z
But I want to estimate the fee before the transaction is sent.
Marc Alexander
CC BY-SA 3.0
2017-07-06T20:32:52.937Z
I've edited with further instructions to get the fee before the transaction is sent.
Ava Chow
CC BY-SA 3.0
2017-07-06T20:52:42.393Z
Thanks for the update. So basically I do createrawtransaction and fundrawtransaction and it returns the size of the transaction, then I can set a custom fee based on how many bytes it is.. then of course sendrawtransaction.
Marc Alexander
CC BY-SA 3.0
2017-07-06T20:59:57.160Z
No, you can't set the fee after the transaction has been created. The fee has to be set when the transaction is being funded. `fundrawtransaction` has an option to set the fee rate. Just read the help text for it.
Ava Chow
CC BY-SA 3.0
2017-07-06T16:43:12.557Z
2017-07-06T20:32:36.333Z
2017-07-06T20:32:36.333Z
Ava Chow
<p>We're using bitcoind on our server.</p>

<p>When people withdraw from our system we want to have the correct miner fee.</p>

<p>I understand that we can get the good miner fee from txconfirmtarget or the API from: <a href="https://bitcoinfees.21.co/api" rel="nofollow noreferrer">https://bitcoinfees.21.co/api</a></p>

<p>But when we send a transaction how do we know which miner fee to put if we want to enter it into the database?</p>

<p>EDIT:
I do notice this: bitcoin-cli estimatefee 2 but then how do we find out how many bytes are being sent?</p>

CC BY-SA 3.0
2017-07-05T23:17:37.640Z
Are you using bitcoind's internal wallet or just using it to create and broadcast a raw transaction?
Ava Chow
CC BY-SA 3.0
2017-07-06T16:25:52.493Z
bitcoind on a centos server
Marc Alexander
CC BY-SA 3.0
2017-07-06T16:31:08.030Z
That doesn't answer my question. Are you using bitcoind as a wallet (i.e. using sendtoaddress, sendmany, etc. RPCs) or just as a node to broadcast your transactions with?
Ava Chow
CC BY-SA 3.0
2017-07-06T16:37:24.417Z
as a wallet with RPCs
Marc Alexander
<bitcoind><transaction-fees>
Bitcoind When sending a payment how can I know how many inputs and outputs there are?
Marc Alexander
# Bitcoind When sending a payment how can I know how many inputs and outputs there are?

(Asked by: username_0 on 2017-07-05)

We're using bitcoind on our server.

When people withdraw from our system we want to have the correct miner fee.

I understand that we can get the good miner fee from txconfirmtarget or the API from: <https://bitcoinfees.21.co/api>

But when we send a transaction how do we know which miner fee to put if we want to enter it into the database?

EDIT:
I do notice this: bitcoin-cli estimatefee 2 but then how do we find out how many bytes are being sent?

**Tags:** bitcoind, transaction-fees

> **Comments:**
> **username_1**: Are you using bitcoind's internal wallet or just using it to create and broadcast a raw transaction?  
> **username_0**: bitcoind on a centos server  
> **username_1**: That doesn't answer my question. Are you using bitcoind as a wallet (i.e. using sendtoaddress, sendmany, etc. RPCs) or just as a node to broadcast your transactions with?  
> **username_0**: as a wallet with RPCs  

---

## 1 answers

### Answer by username_1 on 2017-07-06. Score: 1 | Accepted answer

When you use bitcoind's internal wallet and its related RPCs, it will automatically calculate the transaction fee for you and include that in the transaction. You can then retrieve the transaction fee used by using the `gettransaction` command. If you want the fee rate that was used, you can use the fee from `gettransaction` and divide that by the size returned by `gettransaction`.

Edit: To get the fee before you send, you can create the transaction with only the outputs you want (i.e. no inputs) with `createrawtransaction`. Then you can use `fundrawtransaction` to fill out the transaction with inputs. That will also give you the fee that the transaction is paying. Then you sign it with `signrawtransaction` and send it with `sendrawtransaction`. There is no other way as the other `send*` RPCs create the transaction, select coins, sign, and send all in one command.

> **Comments:**
> **username_0**: But I want to estimate the fee before the transaction is sent.  
> **username_1**: I've edited with further instructions to get the fee before the transaction is sent.  
> **username_0**: Thanks for the update. So basically I do createrawtransaction and fundrawtransaction and it returns the size of the transaction, then I can set a custom fee based on how many bytes it is.. then of course sendrawtransaction.  
> **username_1**: No, you can't set the fee after the transaction has been created. The fee has to be set when the transaction is being funded. `fundrawtransaction` has an option to set the fee rate. Just read the help text for it.  

---

