How to get block's tx fees from RPC?

Hi, I can’t seem to find a method that would return information about tx fees (per tx or summarized, any form is ok) in a mined block, could anyone point me in the right direction?

1 Like

Thanks, so from what I understand this is not implemented, same for the default fee. So how do the blockchain explorers get the tx fees?

You can get all the information at the transaction level. Note you’d need to set -txindex=1 when launching zcashd or adding this to zcash.conf.

Find the latest block:
zcash-cli getbestblockhash

Get the info about the block
zcash-cli getblock 00000000000681529cd55765207b1130b575500cf4fba0e7456195b41785ea21

This includes an array of transactions, so from that get the raw transaction:

zcash-cli getrawtransaction 868c510a5c3df4672b8911c010c2555041b454854b0ebd23e52615f82752fbce

Then finally get the details of the transaction:
zcash-cli decoderawtransaction <output of previous command>

You can then calculate the fees as sum of all outputs minus sum of all inputs as fees are always transparent.

1 Like

Ah, I was missing the -txindex=1 flag, I’ve used decoderawtransaction but only got zatoshi for vouts. Thanks.

1 Like

How do you calculate the fees for shielded or deshielded transactions? I tried using decoderawtransaction, but since the vin or vout sections are empty, I can’t sum the inputs/outputs. Here are some examples:

0d3082487047c3bab9b88e506ca9a9047310727ecced1d34d5bdafc5eb087a5f is shielded, so the outputs are hidden. The ZCash Block Explorer shows .0001 ZEC as the transaction fee.

eed722ec844a9f43b514d1e9a307bd736408f4433cbf851061a8bed4d6816dd7 is deshielded, so the inputs are hidden. The ZCash Block Explorer shows 0.00295 ZEC as the transaction fee.

1 Like

The inputs/outputs/actions of sapling/orchard are hidden but the value balance is public. You can add them to the value of vins - vouts to get the fee.


The same issue was posted recently, I meant to post the link here, just a minute.

For those that are interested, I looked into many transaction examples from the raw JSON and I believe I have figured out the fields that are involved with transaction fees. It depends on the version:

*Note that valueBalance contains a negative value in V4,V5 for Shielded Transactions
Shielded Transactions(V2,V3): Fee = InputTotal - vpub_old
Shielded Transactions(V4): Fee = InputTotal + valueBalance(transaction root)
Shielded Transactions(V5): Fee = InputTotal + (valueBalance(orchard) + valueBalance(transaction

Deshielded Transactions(V2,V3): Fee = vpub_new - OutputsTotal
Deshielded Transactions(V4): Fee = vpub_new - OutputsTotal
Deshielded Transactions(V5): Fee = valueBalance(orchard) - OutputsTotal

Private Transactions(V2,V3): Fee = vpub_new
Private Transactions(V4): Fee = valueBalance(transaction root)
Private Transactions(V5): Fee = valueBalance(Orchard)

One thing I have noticed is that for Deshielded transactions in V4, the vjoinsplit object(which is an array) contains one item for every input. However, in each example I have looked at, all of the vpub_new values are 0 except for one, which contains the sum of all input values along with the transaction fee. I don’t know if there are any cases where multiple items in the vjoinsplit array will contain a vpub_new value > 0, but a safe bet might be to sum all vpub_new values within that array.

Please let me know if any of the information I have included is incorrect. I am doing a deep dive into the blockchain because my company is looking into potentially creating a block explorer.

1 Like

Fees can be rather dynamic. Theres nothing that really enforces wallet fee practices beyond the wallet developers themselves. The best way to calculate is to find the difference in the visible values. That’s speaking generically, but if it’s FULLY shielded then the only visible value will be the fee itself. A fully cross-shielded pool transaction will reveal the entire value all. A partial cross-shielded transaction will reveal some of the value, the fee and the amount that crosses but not what was in the same pool. Maybe they were naughty and paid no fee. Coal in the stockings for sure! (It is a possibility) If the block is small, or otherwise completely transparent, then you can also correlate the fees to the excess in the mining reward beyond the block reward, which is the sum of all the tx fees.

Have you read the protocol specs? The fees can be calculated with the formula above.

1 Like