<p>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.</p>

<p>The transaction itself has no values of the inputs!</p>

<p>You have the following options:</p>

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

CC BY-SA 3.0
2016-02-19T13:56:23.777Z
2016-02-19T13:56:23.777Z
Stefan
<p>I am trying to get the fee of incoming transactions in a wallet with bitcoinj. At times it was the commission using <code>Transaction.getFee()</code>, but this was throwing <code>NullPointerException</code>. 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?</p>

<p>I leave an example of the output of one of the transactions (testnet):</p>

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

<transactions><transaction-fees><bitcoinj><transaction-input>
How to get fee in a transaction with unconfirmed inputs in bitcoinj?
Ander Acosta
# How to get fee in a transaction with unconfirmed inputs in bitcoinj?

(Asked by: username_0 on 2016-02-19)

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]
        outpoint:7cd4378560d2b36f53b3d492afa815c5ae615d18bff9611c3081f591a1c0c156:0
   out  DUP HASH160 PUSHDATA(20)[49d2661baf33597c6dc3dbdbb9e7a8835fdb76b4] EQUALVERIFY CHECKSIG 0.00126081 BTC
   out  DUP HASH160 PUSHDATA(20)[372fb0d8affe634b369af9722cc48c63ad90e9df] EQUALVERIFY CHECKSIG 0.001 BTC
   prps UNKNOWN

```

**Tags:** transactions, transaction-fees, bitcoinj, transaction-input


---

## 1 answers

### Answer by username_1 on 2016-02-19. Score: 1 | Accepted answer

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


---

