3

I'm using bitcoin core full node on ubuntu. When I call listtransactions some transactions coming up with no fee key.

  [8] => Array
    (
        [account] => 
        [address] => 1MTLEprpnQwLHMeYh51CQrCWxSuZPGSZ6T
        [category] => send
        [amount] => -0.0028107
        [vout] => 0
        [fee] => -1.13E-5
        [confirmations] => 0
        [trusted] => 1
        [txid] => 6c74d8ac3b9b57184ed5dff72d48474c5ecf8dac4ec9388cb0ff33bf8e3bfcbc
        [walletconflicts] => Array
            (
            )

        [time] => 1511008107
        [timereceived] => 1511008107
        [bip125-replaceable] => no
        [abandoned] => 
    )

[9] => Array
    (
        [account] => 
        [address] => 12zJ7ZbDW59mmNBPrxBAEjtWf8JzwgLNum
        [category] => receive
        [amount] => 0.00240164
        [label] => 
        [vout] => 0
        [confirmations] => 0
        [trusted] => 
        [txid] => 25d0812c7dcf3c938430dc5c61566b8346b6e6d300b1e3cd3fc7d4031eb93cbe
        [walletconflicts] => Array
            (
            )

        [time] => 1511010977
        [timereceived] => 1511010977
        [bip125-replaceable] => no
    )

)

Transaction on blockchain: https://blockchain.info/tx/25d0812c7dcf3c938430dc5c61566b8346b6e6d300b1e3cd3fc7d4031eb93cbe

I have read that just now on bitcoin.org,

If sending payment, the fee paid as a negative bitcoins value. May be 0. Not returned if receiving payment or for move category payments

Which answers my question, but now i'm wondering how to get the fee of received transaction.

1 Answer 1

4

To find the fee of the transaction, you need to know the value of the inputs and outputs and find the difference between those two values.

Unfortunately this is much more difficult for receiving transactions, because by default bitcoin core only holds the information for transactions which are related to your wallet, not all transactions (this can be enabled with txindex=1 argument).

What this means is that, to find the fee for a receive transaction, you can call getrawtransaction "txid" true with the txid you obtain from listtransactions. The last argument, true is set to make the output "verbose" so that it includes more information about the transaction than just the hex encoded transaction itself. It will return a JSON object with vin and vout arrays which you can iterate over. You can simply sum the output values. The trouble is finding the input values. Input values are not given in transactions, so you must look them up individually. This is a problem for receiving transactions because the transactions they spend from are usually unrelated to your wallet and thus cannot be looked up without txindex=1.

3
  • You are right, The trouble in here finding the input values!! How does blockchain.info and other chains get these info?
    – Tailer
    Commented Nov 19, 2017 at 3:22
  • I assume blockchain.info and similar sites use their own databases of information rather than querying it from a node every time Commented Nov 19, 2017 at 11:26
  • Yeah I guess they update each new transaction to their database.
    – Tailer
    Commented Nov 19, 2017 at 20:42

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.