1
Project overview
2
Gas Basics
3
Fee Models
4
Publish your story
๐
Transaction Gas Limits
So far, we've assumed that the user is aware of the number of gas units required by the transaction.
This is true for ETH transfers, which always consume 21,000 gas units.
This is not the case for other transactions involving smart contract execution. Since smart contracts are lines of code, they can take different code paths during execution. It will not be known until the transaction is completed.
As a result, one can't determine upfront how many gas units they are going to consume.
So, how much should a user set?
Users can set a gas limit, i.e., the maximum number of gas units they are willing to spend.
If any gas units remain after execution, they will be refunded to the user.

What happens if the gas units provided is insufficient?
The transaction will revert, but it will be recorded on the blockchain with a failed status. However, the miner(validator) has already done the required work to execute the transaction until no more gas is available. As a result, the consumed gas will not be refunded.

Let us find out the last 10 transactions that failed due to out of gas.
EVM records only the status in Transaction Receipt Trie
. To figure out the failure reason, We have to look at the run time data which is captured in traces
.

SELECT block_number, tx_hash, error, 'https://etherscan.io/tx/' || tx_hash AS etherscan_tx_link, 'https://etherscan.io/vmtrace?txhash=' || tx_hash || '&type=gethtrace2' AS etherscan_trace_link FROM ethereum.traces WHERE error = "Out of gas" AND block_time > NOW() - INTERVAL '1 hour' ORDER BY block_time DESC LIMIT 10;
๐จ๐ฝโ๐ป Fork the above query and give it a try.
ย
Navigate to the above etherscan trace link and try to understand the trace structures. We will dissect them in our upcoming project.
How cool would it be to create an AI system that alerts the user in advance that the transaction will fail?
You may be wondering if people really pay that much as gas fees?
Let's find it out.
๐๏ธ Let's query the chain
What was the maximum gas price paid in the month of Aug'22 for a (out-of-gas) failed transaction?
Hint: Solve https://dune.com/queries/1275527