Ethereum receipts contain two Gas numbers. Which one should be recorded for this transaction?
The gasUsed in an Ethereum transaction receipt counts only the execution Gas consumed by that transaction. cumulativeGasUsed is the total execution Gas from the first transaction in the same block up to and including the current transaction. The two values can be the same for the first transaction, but for later transactions, the cumulative value also includes the Gas used by earlier transactions.
For example, the first transaction in a block used 30,000 Gas, and the second used 20,000. The second transaction’s gasUsed is 20,000, while its cumulative value is 50,000. If you add the cumulative values from both receipts, the first transaction gets counted twice. To calculate the cost of a single transaction, read its gasUsed. To verify the order within a block, compare the cumulative differences between adjacent receipts in the same block.
When preparing fee reports, you should also save the block hash and transaction index to avoid subtracting cumulative values from different blocks. Executed gas must be converted into the actual fee, which also requires reading the effective gas price for the corresponding transaction. The figures above are hypothetical and for technical discussion only.
$ETH #Ethereum
Source: https://ethereum.org/developers/docs/apis/json-rpc/#eth_gettransactionreceipt