<p>Yes, this is actually what the raw transaction API is for.</p>

<p>The ordinary send RPCs (<code>sendtoaddress</code> and <code>sendmany</code>) do everything at once:</p>

<ul>
<li>Construct outputs based on the addresses/amounts you want to send.</li>
<li>Do coin selection to find inputs to satisfy the amounts, determine the fee, and add change if necessary.</li>
<li>Sign the inputs with the keys in your wallet.</li>
<li>Broadcast the transaction to the network.</li>
</ul>

<p>Since the fee depends on the size of the transaction, which depends on the coin selection, you cannot "intervene" in the middle of these RPCs.</p>

<p>The raw transaction API lets you do all these steps independently:</p>

<ul>
<li>Constructing outputs based on addresses/amount using <code>createrawtransaction</code>.</li>
<li>Do coin selection to find inputs, determine the fee, and add change using <code>fundrawtransaction</code>.</li>
<li>Sign the inputs using <code>signrawtransaction</code>.</li>
<li>Broadcast the transaction using <code>sendrawtransaction</code>.</li>
</ul>

<p>If you need to know the actual fee before broadcasting, you can use <code>createrawtransaction</code> + <code>fundrawtransaction</code> + <code>signrawtransaction</code> to construct a fully valid transaction without broadcasting. You can then inspect it, and decide to broadcast it using <code>sendrawtransaction</code> or not.</p>

CC BY-SA 4.0
2019-12-17T01:54:32.387Z
can you post a link for this?
coder123
CC BY-SA 4.0
2019-12-19T21:02:02.737Z
A link to what?
Pieter Wuille
CC BY-SA 4.0
2019-12-20T05:59:47.163Z
the raw transaction api documentation if you know where it is?
coder123
CC BY-SA 4.0
2021-11-01T19:09:14.770Z
Seems to me that it would be useful to  allow for user to input the current fees that result in acceptable delay (in satoshis per byte, as published, for example at https://bitcoinfees.earn.co), , and then do these steps automatically up to "signrawtransaction", caculate a transaction fee accordingly , and then as for an OK before setting the tx fee and actually broadcasting the transaction.
dbkeys
CC BY-SA 3.0
2017-07-06T22:43:42.747Z
2017-07-06T22:43:42.747Z
Pieter Wuille
<p>I want to know the size (in bytes) of a transaction before it's sent.</p>

<p>Is it possible? Maybe with raw transactions? or..</p>

<p>EDIT:</p>

<p>Not a duplicate. The 'duplicate' doesn't address how to find out how big it is. Just addresses how to calculate the bytes (inputs and outputs). I even commented on that thread. How do you find how many inputs and outputs there are. I understand how to calculate it. But how do I figure out if there are 10 outputs or 5 outputs? </p>

CC BY-SA 3.0
2017-07-07T16:16:17.070Z
Not a duplicate. The 'duplicate' doesn't address how to find out how big it is. Just addresses how to calculate the bytes (inputs and outputs). I even commented on that thread. How do you find how many inputs and outputs there are. I understand how to calculate it. But how do I figure out if there are 10 outputs or 5 outputs?
Marc Alexander
CC BY-SA 3.0
2017-07-07T18:11:40.043Z
I've voted to reopen.
Pieter Wuille
CC BY-SA 3.0
2017-07-07T21:05:24.597Z
@MarcAlexander: Thank you for clarifying. I've also voted to reopen.
Murch
<bitcoind><transaction-fees>
Can I figure out the size of a transaction before its sent?
Marc Alexander
# Can I figure out the size of a transaction before its sent?

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

I want to know the size (in bytes) of a transaction before it's sent.

Is it possible? Maybe with raw transactions? or..

EDIT:

Not a duplicate. The 'duplicate' doesn't address how to find out how big it is. Just addresses how to calculate the bytes (inputs and outputs). I even commented on that thread. How do you find how many inputs and outputs there are. I understand how to calculate it. But how do I figure out if there are 10 outputs or 5 outputs?

**Tags:** bitcoind, transaction-fees

> **Comments:**
> **username_0**: Not a duplicate. The 'duplicate' doesn't address how to find out how big it is. Just addresses how to calculate the bytes (inputs and outputs). I even commented on that thread. How do you find how many inputs and outputs there are. I understand how to calculate it. But how do I figure out if there are 10 outputs or 5 outputs?  
> **username_1**: I've voted to reopen.  
> **username_2**: @username_0: Thank you for clarifying. I've also voted to reopen.  

---

## 1 answers

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

Yes, this is actually what the raw transaction API is for.

The ordinary send RPCs (`sendtoaddress` and `sendmany`) do everything at once:

* Construct outputs based on the addresses/amounts you want to send.
* Do coin selection to find inputs to satisfy the amounts, determine the fee, and add change if necessary.
* Sign the inputs with the keys in your wallet.
* Broadcast the transaction to the network.

Since the fee depends on the size of the transaction, which depends on the coin selection, you cannot "intervene" in the middle of these RPCs.

The raw transaction API lets you do all these steps independently:

* Constructing outputs based on addresses/amount using `createrawtransaction`.
* Do coin selection to find inputs, determine the fee, and add change using `fundrawtransaction`.
* Sign the inputs using `signrawtransaction`.
* Broadcast the transaction using `sendrawtransaction`.

If you need to know the actual fee before broadcasting, you can use `createrawtransaction` + `fundrawtransaction` + `signrawtransaction` to construct a fully valid transaction without broadcasting. You can then inspect it, and decide to broadcast it using `sendrawtransaction` or not.

> **Comments:**
> **username_3**: can you post a link for this?  
> **username_1**: A link to what?  
> **username_3**: the raw transaction api documentation if you know where it is?  
> **username_4**: Seems to me that it would be useful to  allow for user to input the current fees that result in acceptable delay (in satoshis per byte, as published, for example at https://bitcoinfees.earn.co), , and then do these steps automatically up to "signrawtransaction", caculate a transaction fee accordingly , and then as for an OK before setting the tx fee and actually broadcasting the transaction.  

---

