I am trying to get the fee of incoming transactions in a wallet with bitcoinj. At times it was the commission using Transaction.getFee(), but this was throwing NullPointerException. I got to do a little more research and I realized that it happens when the transaction has unconfirmed inputs. I've tried adding the value of all the inputs and subtracting the value of all the outputs, so you would get the fee, but on these occasions the sum of the inputs is 0 BTC. Is there any other way to get the commission?

I leave an example of the output of one of the transactions (testnet):

04f570fdd0cb8c973d8c9b3adf09b803ef70941ec239685d479a93b089e4d621: Seen by 1 peer. Pending/unconfirmed.
   in   PUSHDATA(72)[3045022100fe750e43c3bc46eddb390dad98acd6ef0646e00386770de542e7e5c581f8118102206924cd243b459645ae8626e948e1d33404d29c651a8a59c24ed5cd902d7e939201] PUSHDATA(33)[02a40db91b59058375fe7f13810beb6609e63a8974ce355b76d01692058eaac9f9]
   out  DUP HASH160 PUSHDATA(20)[49d2661baf33597c6dc3dbdbb9e7a8835fdb76b4] EQUALVERIFY CHECKSIG 0.00126081 BTC
   out  DUP HASH160 PUSHDATA(20)[372fb0d8affe634b369af9722cc48c63ad90e9df] EQUALVERIFY CHECKSIG 0.001 BTC
   prps UNKNOWN

1 Answer 1


In case of a SPV node you don't have the values of the inputs of a transaction, as you don't have the full blockchain and thus all the UTXOs.

The transaction itself has no values of the inputs!

You have the following options:

  • Query a trusted server for the UTXOs (e.g. electrum servers)
  • Query a webservice (e.g. blockcypher)
  • of course have a full copy of the blockchain, you could use java bindings to query a local bitcoind

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.