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));


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.


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}.

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


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);

Transaction transaction = result.broadcastComplete.get();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.