Execution
1 min read
Pronunciation
[ek-si-kyoo-shuhn]
Analogy
Imagine a smart contract is like a vending machine with programmed rules. 'Execution' is what happens when you put in coins and press a button (send a transaction). The internal mechanisms of the vending machine whir and follow their programming (the code runs) to dispense a snack and give change (state changes, events emitted).
Definition
In the context of smart contracts and blockchains, execution refers to the process of running the code within a smart contract in response to a transaction or an internal message call. This process consumes computational resources (gas) and can result in changes to the smart contract's state or the blockchain's overall state.
Key Points Intro
Execution is the active process of a smart contract performing its programmed operations.
Key Points
The running of smart contract code by a blockchain's virtual machine (e.g., EVM).
Triggered by transactions or calls from other contracts.
Consumes computational resources, typically measured in 'gas'.
Can read from and write to the blockchain state (e.g., update balances, change data).
Results are deterministic: given the same initial state and input, the execution will always produce the same output and state changes on all nodes.
Example
When you call a function on an ERC-20 token contract to transfer tokens, the Ethereum Virtual Machine (EVM) executes the `transfer` function's code within the smart contract, which updates the token balances of the sender and receiver.
Technical Deep Dive
Smart contract execution involves interpreting and running bytecode on a virtual machine. Each operation (opcode) in the bytecode has an associated gas cost. The execution environment provides access to the contract's storage, the transaction's details (sender, value, data), and an interface to interact with other contracts or query blockchain information. If execution runs out of gas or encounters an error (e.g., a `revert` operation), all state changes made during that execution are typically rolled back, but the gas consumed up to that point is still paid.
Execution - Related Articles
15 min read
Due Diligence on Tokenized Private Credit — A Practitioner's Guide
Evaluating tokenized private credit requires moving beyond on-chain metrics....
Read