<p>As the block id is known, the fee can be found from the coinbase itself without an overhead. Maintain a simple map for reward points saying blocks between 0-149 gives 50 BTC, next 149 25 etc.</p>

<p>Now, the first transaction in any block is always a coinbase tran. 
Coinbasetran->vout[0] - reward = Fee (actual fee + unclaimed change)</p>

CC BY-SA 3.0
2016-03-21T11:15:00.977Z
2016-03-21T11:15:00.977Z
Rohith SP
<p>Here is a simple workaround.</p>

<ol>
<li>Enable the flag passed to <code>txDetails</code> of <code>blockToJSON()</code> in <code>rpcblockchain.cpp</code></li>
</ol>

<p><strong>Changes Needed:</strong></p>

<pre><code>--- a/src/rpcblockchain.cpp
+++ b/src/rpcblockchain.cpp
@@ -423,7 +423,7 @@ UniValue getblock(const UniValue&amp; params, bool fHelp)
         return strHex;
     }

-    return blockToJSON(block, pblockindex);
+    return blockToJSON(block, pblockindex, true);
 }
</code></pre>

<ol start="2">
<li>Use the <code>getblock &lt;HASH&gt;</code> JSON RPC command. Now, it will throw all the transaction details. Coinbase transaction can help you infer your fees (NOTE that the logic can also be incorporated in above code but I am keeping it simple) </li>
</ol>

<p><strong>Example output:</strong></p>

<pre><code>.....

          "vout": [
            {
              "value": 25.04810000,
              "n": 0,
              "scriptPubKey": {
                "asm": "02b551067a9159d3964cb5c5b15d57169c0b2e24fefcfe768c6624ff1a6cedf7b5 OP_CHECKSIG",
                "hex": "2102b551067a9159d3964cb5c5b15d57169c0b2e24fefcfe768c6624ff1a6cedf7b5ac",
                "reqSigs": 1,
                "type": "pubkey",
                "addresses": [
                  "mqu1hVy32hcojhq12kt21kVaCd7g4nwPU5"
                ]
              }
            }
          ]
        }
      ],
.....
</code></pre>

CC BY-SA 3.0
2016-02-09T06:23:44.940Z
2016-02-09T06:23:44.940Z
visweshn92
<p>I want to know how one can query bitcoin core via json rpc or other methods to find all the transaction fees in a block? API queries are not useful as they have a rate limit.</p>

<p>Here is an example block, for which i want to calculate transaction fees </p>

<p><a href="https://blockchain.info/block/0000000000000000059134ebb840559241e8e2799f3ebdff56723efecfd6567a" rel="nofollow">block number 395545</a></p>

<bitcoind><bitcoin-core><transaction-fees>
calculate transaction fee in a block
user32635
# calculate transaction fee in a block

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

I want to know how one can query bitcoin core via json rpc or other methods to find all the transaction fees in a block? API queries are not useful as they have a rate limit.

Here is an example block, for which i want to calculate transaction fees

[block number 395545](https://blockchain.info/block/0000000000000000059134ebb840559241e8e2799f3ebdff56723efecfd6567a)

**Tags:** bitcoind, bitcoin-core, transaction-fees


---

## 2 answers

### Answer by username_1 on 2016-03-21. Score: 1

As the block id is known, the fee can be found from the coinbase itself without an overhead. Maintain a simple map for reward points saying blocks between 0-149 gives 50 BTC, next 149 25 etc.

Now, the first transaction in any block is always a coinbase tran.
Coinbasetran->vout[0] - reward = Fee (actual fee + unclaimed change)


---

### Answer by username_2 on 2016-02-09. Score: 0

Here is a simple workaround.

1. Enable the flag passed to `txDetails` of `blockToJSON()` in `rpcblockchain.cpp`

**Changes Needed:**

```
--- a/src/rpcblockchain.cpp
+++ b/src/rpcblockchain.cpp
@@ -423,7 +423,7 @@ UniValue getblock(const UniValue& params, bool fHelp)
         return strHex;
     }

-    return blockToJSON(block, pblockindex);
+    return blockToJSON(block, pblockindex, true);
 }

```

2. Use the `getblock <HASH>` JSON RPC command. Now, it will throw all the transaction details. Coinbase transaction can help you infer your fees (NOTE that the logic can also be incorporated in above code but I am keeping it simple)

**Example output:**

```
.....

          "vout": [
            {
              "value": 25.04810000,
              "n": 0,
              "scriptPubKey": {
                "asm": "02b551067a9159d3964cb5c5b15d57169c0b2e24fefcfe768c6624ff1a6cedf7b5 OP_CHECKSIG",
                "hex": "2102b551067a9159d3964cb5c5b15d57169c0b2e24fefcfe768c6624ff1a6cedf7b5ac",
                "reqSigs": 1,
                "type": "pubkey",
                "addresses": [
                  "mqu1hVy32hcojhq12kt21kVaCd7g4nwPU5"
                ]
              }
            }
          ]
        }
      ],
.....

```


---

