<p>You cannot know the size in bytes of a transaction without knowing the inputs to the transaction. Just knowing the amount you want to transfer and just the output does not tell you anything.</p>

<p>Using the <code>sendCoins()</code> method and setting <code>feePerKb</code> in your <code>SendRequest</code> should create a transaction that pays the specified fee rate. If you want to get the transaction details after you send, the <code>SendResult</code> that you get has a field named <code>tx</code> which is a <code>Transaction</code> object. You can then get the necessary information from there.</p>

<p>If you want to know the size before you send, then you need to craft the transaction yourself as <code>sendCoins()</code> will automatically create and send the transaction for you.</p>

CC BY-SA 3.0
2018-02-08T05:03:38.297Z
Thank you for the answer, So my next question is how should I know the fee per kb for a transaction.For example if transaction is 2.0 BTC and fatest fee is 240/kb so how much in total fee I should include. @Andrew Chow
Aman Vyas
CC BY-SA 3.0
2018-02-08T06:29:49.323Z
As I said in my answer, you need to know the size of the transaction, which can only be known after inputs are selected.
Ava Chow
CC BY-SA 3.0
2018-02-09T20:20:19.913Z
AFAIK, the fee is .001 BTC/kb and more the miner fee, the faster it gets confirmed.
bitsabhi
CC BY-SA 3.0
2018-02-09T21:06:16.793Z
Median transactions are of sizes 226b, which is approx 24000 Satoshi
bitsabhi
CC BY-SA 3.0
2018-02-06T16:15:46.913Z
2018-02-06T16:15:46.913Z
Ava Chow
<p>The calculation of a transaction fee uses fee/kb. So how do I get the size in bytes for a transaction using BitcoinJ?</p>

<pre><code>SendRequest req = SendRequest.to(address, value);

req.feePerKb = Coin.parseCoin("0.0000100");

Wallet.SendResult result = kit.wallet().sendCoins(req);
</code></pre>

<transactions><bitcoinj>
How to size in bytes for a transaction using BitcoinJ
Aman Vyas
# How to size in bytes for a transaction using BitcoinJ

(Asked by: username_0 on 2018-02-06)

The calculation of a transaction fee uses fee/kb. So how do I get the size in bytes for a transaction using BitcoinJ?
SendRequest req = SendRequest.to(address, value);

req.feePerKb = Coin.parseCoin("0.0000100");

Wallet.SendResult result = kit.wallet().sendCoins(req);

**Tags:** transactions, bitcoinj


---

## 1 answers

### Answer by username_1 on 2018-02-06. Score: 1 | Accepted answer

You cannot know the size in bytes of a transaction without knowing the inputs to the transaction. Just knowing the amount you want to transfer and just the output does not tell you anything.

Using the `sendCoins()` method and setting `feePerKb` in your `SendRequest` should create a transaction that pays the specified fee rate. If you want to get the transaction details after you send, the `SendResult` that you get has a field named `tx` which is a `Transaction` object. You can then get the necessary information from there.

If you want to know the size before you send, then you need to craft the transaction yourself as `sendCoins()` will automatically create and send the transaction for you.

> **Comments:**
> **username_0**: Thank you for the answer, So my next question is how should I know the fee per kb for a transaction.For example if transaction is 2.0 BTC and fatest fee is 240/kb so how much in total fee I should include. @Andrew Chow  
> **username_1**: As I said in my answer, you need to know the size of the transaction, which can only be known after inputs are selected.  
> **username_2**: AFAIK, the fee is .001 BTC/kb and more the miner fee, the faster it gets confirmed.  
> **username_2**: Median transactions are of sizes 226b, which is approx 24000 Satoshi  

---

