DEV Community

Mahima Thacker
Mahima Thacker

Posted on

Ever wonder what happens when you send a transaction on Ethereum? πŸ‘€

Let's break it down in simple termsπŸ‘‡:

1. Setup: When you send a transaction from your wallet to a smart contract, the EVM (Ethereum Virtual Machine) gets ready. It creates a new environment to run your transaction.
The EVM loads the smart contract's code, sets up an empty stack and memory (kind of like a workspace), and prepares all the important variables.

2. Execution: Now, the EVM starts executing the transaction. It goes through each instruction (called opcodes) one by one.
As it works, it uses up the gas you provided (think of gas as the fuel that powers the transaction).
It updates the stack, memory, and storage as needed. Once it finishes, the EVM clears out the stack and memory, wiping the workspace clean.

3. Success: If everything runs smoothly, the EVM saves the changes made during the transaction to the blockchain.
Any leftover gas is returned to you.

4. Out of Gas: If the transaction runs out of gas before finishing, the EVM stops. All the changes are undone, so nothing gets saved. And you don’t get back any gas.

5. Exception: If something goes wrong (like hitting a require, revert, or assert statement), the transaction is reverted. This means no changes are made to the blockchain. And no refund for unused gas from the gas limit

Image description

This is how Ethereum manages your transactions behind the scenes, ensuring everything runs smoothly or is safely undone if something goes wrong πŸ’β€β™€οΈ

Top comments (0)