<p>It can be something like this,</p>

<pre><code>req.fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE;
</code></pre>

<p><code>REFERENCE_DEFAULT_MIN_TX_FEE</code> refers to the minimum fee required to relay a transaction in a block which is set to 1000 Satoshis as of now.</p>

<p>One must remember that the transaction fee is like an incentive brought forward by the Bitcoin user to make sure that a particular transaction will get included into a block which is generated in future(and soon enough). Hence, an appropriate value of fees must be included with a transaction. Check FeesPerKB for this too.</p>

CC BY-SA 3.0
2017-02-28T19:17:44.503Z
2017-03-01T02:23:49.073Z
2017-03-01T02:23:49.073Z
Anand Parashar
<p>You can adjust fee per kb with Context class. This is my context:</p>

<pre><code>context = new Context(this.params, 50, Coin.valueOf(500000), true);
</code></pre>

<p>Coin.valueOf(500000) is setting fee per kb. You can adjust fee with this. You can extend Wallet class and override calculateFee() method and you can set fee directly. But this is a little complex method and you must be carefully.</p>

<p>If you create context with default settings then it set fee per kb as DEFAULT_TX_FEE and it's value is Coin.valueOf(100000) (1 mBTC) This is too low. I set this with 500000 this is more good.</p>

<p>You can look to Context constructor. There is explanation for every params.</p>

<pre><code> * @param params The network parameters that will be associated with this context.
 * @param eventHorizon Number of blocks after which the library will delete data and be unable to always process reorgs (see {@link #getEventHorizon()}.
 * @param feePerKb The default fee per 1000 bytes of transaction data to pay when completing transactions. For details, see {@link SendRequest#feePerKb}.
 * @param ensureMinRequiredFee Whether to ensure the minimum required fee by default when completing transactions. For details, see {@link SendRequest#ensureMinRequiredFee}.
</code></pre>

CC BY-SA 4.0
2019-04-02T20:12:15.463Z
2019-04-02T20:12:15.463Z
kodmanyagha
<p>I believed this section of the documentation is what you are looking for
<a href="https://bitcoinj.github.io/working-with-the-wallet#using-fees" rel="nofollow noreferrer">https://bitcoinj.github.io/working-with-the-wallet#using-fees</a></p>

<p>You can edit the fees via <code>SendRequest.fee</code> or <code>SendRequest.feePerKb</code> API</p>

CC BY-SA 4.0
2019-05-02T22:30:42.087Z
2019-05-02T23:45:10.733Z
2019-05-02T23:45:10.733Z
zhiyan114
<p>I don't know if you solved this problem, but this is how I use a custom fee.</p>

<p>//Generate the request.<br>
SendRequest request = SendRequest.to( target, coin );  </p>

<p>//Update the fee.<br>
request.feePerKb = Coin.valueOf(feePerKb);  </p>

<p>//Generate the result.<br>
Wallet.SendResult result = walletAppKit.wallet().sendCoins(walletAppKit.peerGroup(), request);  </p>

<p>//Broadcast.<br>
Transaction transaction = result.broadcastComplete.get();  </p>

CC BY-SA 3.0
2017-04-28T16:34:23.223Z
2017-04-28T16:34:23.223Z
Mark
<p>Is any possible way to set fee to specific value in bitcoinj wallet? Right now I have something like this and I don't know when to set fee:</p>

<pre><code>    Address address = Address.fromBase58(params, destAddress);
    SendRequest req = SendRequest.to(address, Coin.valueOf(value));

    b_wallet.completeTx(req);
    peers.broadcastTransaction(req.tx);
</code></pre>

<transaction-fees><bitcoinj>
How to set fee in bitcoinj
Dragomirus
# How to set fee in bitcoinj

(Asked by: username_0 on 2016-09-14)

Is any possible way to set fee to specific value in bitcoinj wallet? Right now I have something like this and I don't know when to set fee:

```
    Address address = Address.fromBase58(params, destAddress);
    SendRequest req = SendRequest.to(address, Coin.valueOf(value));

    b_wallet.completeTx(req);
    peers.broadcastTransaction(req.tx);

```

**Tags:** transaction-fees, bitcoinj


---

## 4 answers

### Answer by username_1 on 2017-02-28. Score: 1

It can be something like this,

```
req.fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE;

```

`REFERENCE_DEFAULT_MIN_TX_FEE` refers to the minimum fee required to relay a transaction in a block which is set to 1000 Satoshis as of now.

One must remember that the transaction fee is like an incentive brought forward by the Bitcoin user to make sure that a particular transaction will get included into a block which is generated in future(and soon enough). Hence, an appropriate value of fees must be included with a transaction. Check FeesPerKB for this too.


---

### Answer by username_2 on 2019-04-02. Score: 1

You can adjust fee per kb with Context class. This is my context:

```
context = new Context(this.params, 50, Coin.valueOf(500000), true);

```

Coin.valueOf(500000) is setting fee per kb. You can adjust fee with this. You can extend Wallet class and override calculateFee() method and you can set fee directly. But this is a little complex method and you must be carefully.

If you create context with default settings then it set fee per kb as DEFAULT\_TX\_FEE and it's value is Coin.valueOf(100000) (1 mBTC) This is too low. I set this with 500000 this is more good.

You can look to Context constructor. There is explanation for every params.

```
 * @param params The network parameters that will be associated with this context.
 * @param eventHorizon Number of blocks after which the library will delete data and be unable to always process reorgs (see {@link #getEventHorizon()}.
 * @param feePerKb The default fee per 1000 bytes of transaction data to pay when completing transactions. For details, see {@link SendRequest#feePerKb}.
 * @param ensureMinRequiredFee Whether to ensure the minimum required fee by default when completing transactions. For details, see {@link SendRequest#ensureMinRequiredFee}.

```


---

### Answer by username_3 on 2019-05-02. Score: 1

I believed this section of the documentation is what you are looking for
<https://bitcoinj.github.io/working-with-the-wallet#using-fees>

You can edit the fees via `SendRequest.fee` or `SendRequest.feePerKb` API


---

### Answer by username_4 on 2017-04-28. Score: 0

I don't know if you solved this problem, but this is how I use a custom fee.

//Generate the request.  
SendRequest request = SendRequest.to( target, coin );

//Update the fee.  
request.feePerKb = Coin.valueOf(feePerKb);

//Generate the result.  
Wallet.SendResult result = walletAppKit.wallet().sendCoins(walletAppKit.peerGroup(), request);

//Broadcast.  
Transaction transaction = result.broadcastComplete.get();


---

