0

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

1 Answer 1

1

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.

4
  • 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
    Feb 8, 2018 at 5:03
  • 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
    Feb 8, 2018 at 6:29
  • AFAIK, the fee is .001 BTC/kb and more the miner fee, the faster it gets confirmed.
    – bitsabhi
    Feb 9, 2018 at 20:20
  • Median transactions are of sizes 226b, which is approx 24000 Satoshi
    – bitsabhi
    Feb 9, 2018 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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