A smart contract is a collection of code (functions) and data (state) residing at a specific address on the blockchain. It serves as an autonomous program that manages assets and logic based on pre-defined rules, functioning as a decentralized agent within the EVM ecosystem.
Code that can hold value
Smart contracts are distinct from regular accounts (EOAs) because they possess code. They function as autonomous agents that can receive, hold, and send native assets like ETH, or track balance mappings for tokens defined by standards like ERC-20.
Unlike an EOA, which is controlled by a private key, a contract is controlled by the logic within its bytecode. When a contract is deployed, it effectively becomes an addressable entity capable of receiving transactions and executing state-changing logic.
From source to deployed bytecode
Deployment is the process of taking Solidity source code, compiling it into EVM bytecode, and broadcasting a transaction to the network. During deployment, the constructor function is executed once to set initial state variables, and only the runtime bytecode is permanently stored on-chain.
For standard CREATE transactions, the resulting address is derived from the sender's address and their account nonce using the Keccak-256 hash of the RLP encoding of the sender address and the nonce. Under EIP-1014, the CREATE2 opcode allows for deterministic address generation by using a salt, which is essential for counterfactual deployments where the contract address must be known before deployment.
State, calls and events
Every contract possesses its own persistent storage, a key-value store mapping 32-byte keys to 32-byte values. This state is public; while developers may use privacy-preserving techniques or encryption, the raw data written to the blockchain is accessible to any node operator or indexer.
When a contract is called, the execution context is defined by global variables:
msg.sender: The immediate caller of the function.tx.origin: The EOA that initiated the original transaction.msg.value: The amount of Wei attached to the current call.
When Contract A calls Contract B, msg.sender inside Contract B becomes the address of Contract A. This behavior is a common source of vulnerabilities, as developers often mistakenly verify access based on tx.origin or fail to account for the indirect caller.
The trust assumptions nobody writes down
Contracts are immutable by default, meaning the logic deployed cannot be changed. This creates a specific trust model where users must audit the deployed bytecode to understand the rules governing their assets.
| Mechanism | Trust Assumption | | :--- | :--- | | EOA Signer | Dependent on secret key security | | Smart Contract | Dependent on code correctness | | Proxy Pattern | Dependent on admin honesty |
Because code is immutable, many protocols employ upgradeable patterns. This introduces an administrative layer, often a multisig or a DAO, that can replace the underlying implementation, creating a centralized point of failure.
What contracts cannot do
Smart contracts are reactive; they cannot initiate actions autonomously. They require an external transaction—typically from an EOA, a multisig, or an automation bot (keeper)—to trigger state changes.
Time-dependent actions or external data feeds require oracle systems like Chainlink or automated cron-job style networks. Furthermore, external calls between contracts are subject to gas limits. If a call runs out of gas or reverts, the entire execution context is rolled back to the last stable state, preventing inconsistent data across the system.