Smart contract

On this page 7

A smart contract is a program stored on a blockchain that executes automatically and deterministically whenever a transaction calls it, updating shared state that every node verifies. Its code and data live at a contract address, and once deployed it runs exactly as written: no operator can quietly change the outcome of a call.

In crypto & blockchain systems, smart contracts are the foundation for tokens, decentralized exchanges, lending markets, NFTs and DAOs. The term is older than blockchains, but today it almost always means code running on a platform such as Ethereum and other EVM-compatible chains, Solana or similar networks. Despite the name, a smart contract is not necessarily a legal contract.

How a smart contract executes on a blockchain

Smart contracts follow a simple lifecycle. A developer writes source code, typically in Solidity or Vyper for Ethereum, compiles it to bytecode and deploys it in a transaction. The network assigns a contract address, and from then on anyone can call its public functions by sending transactions or read its data for free through nodes.

Every node runs the same code on the same inputs and must reach the same result. This is why execution is deterministic and isolated: a contract cannot read the internet, a clock outside the block timestamp or a random source without help. External data arrives through a blockchain oracle, which itself becomes a trust assumption.

On Ethereum, the Ethereum Virtual Machine (EVM) executes bytecode instruction by instruction and charges gas for each step. The sender sets a gas limit and pays the fee in the native currency. If execution runs out of gas or hits an error, all state changes revert, although the gas already used is still paid.

The table below lists the building blocks of a deployed smart contract.

ElementRoleExample
Contract addressUnique on-chain identifierAddress that holds code and balance
StoragePersistent state between callsToken balances, ownership records
FunctionsEntry points that read or change statetransfer, deposit, withdraw
EventsLogs emitted for off-chain indexingTransfer events read by wallets
Access controlRules about who may call whatOwner-only pause function
Building blocks of a smart contract

Key properties and the trade-offs they create

The properties that make smart contracts useful are the same ones that make them unforgiving. Immutability gives users confidence that rules will not change, but it also means bugs cannot simply be patched. Composability lets contracts call each other like building blocks, yet it lets a failure in one protocol spread to others.

PropertyBenefitCost or risk
DeterminismEvery node agrees on resultsNo native access to outside data
ImmutabilityRules cannot be altered secretlyBugs persist unless upgradeability exists
TransparencyCode and state are publicly inspectableAttackers can study the code too
ComposabilityContracts integrate without permissionRisks propagate across protocols
Metered executionGas prevents infinite loops and spamComplex logic becomes expensive
Core properties of smart contracts

Many teams therefore deploy upgradeable smart contracts using a proxy pattern, where a stable address delegates to replaceable logic. This restores the ability to fix bugs but reintroduces trust in whoever controls the upgrade key, often mitigated with multisig control and time delays.

A smart contract is one component of a larger application, not the application itself. The comparison below separates it from neighboring ideas that are often used interchangeably.

ConceptWhat it isRelation to a smart contract
dAppFull application with interface and contractsUses one or more smart contracts as back end
Legal contractEnforceable agreement between partiesMay be referenced but is not created automatically
Traditional server codeProgram run by one operatorOperator can change or stop it at will
OracleService that posts external data on-chainSupplies inputs the contract cannot fetch
Token standardAgreed interface such as ERC-20Implemented by a smart contract
Smart contract and related terms

Legal enforceability depends on jurisdiction and on whether the parties intended the code to express an agreement. Several legal systems recognize that code can evidence or perform contractual terms, but courts still interpret intent, capacity and remedies outside the chain.

Security risks and common vulnerabilities

Smart contract security is unusually demanding because deployed code controls real value and its source is public. Losses from exploited contracts have repeatedly reached hundreds of millions of dollars in single incidents. The most frequent vulnerability classes are well documented.

VulnerabilityMechanismTypical defense
Reentrancy attackExternal call re-enters before state is updatedChecks-effects-interactions, reentrancy guards
Access control flawSensitive function callable by anyoneExplicit role checks and reviews
Oracle manipulationPrice feed moved within one transactionTime-weighted or decentralized oracles
Front-running and MEVPending transactions reordered for profitCommit-reveal, slippage limits, private submission
Logic and arithmetic errorsIncorrect assumptions in business rulesTesting, fuzzing and formal verification
Frequent smart contract vulnerabilities

No single control is sufficient. Mature teams combine unit and fuzz testing in frameworks such as Hardhat or Foundry, independent smart contract audits, formal verification for critical invariants, bug bounties and staged launches with deposit caps. An audit reduces risk but never guarantees safety.

Practical design choices

Good smart contract design starts by keeping on-chain logic minimal. Storage writes are among the most expensive EVM operations, so developers move heavy computation off-chain and keep on-chain only what needs trustless enforcement.

  • Reuse audited libraries for standard functions such as tokens and access control instead of writing them from scratch.
  • Decide upgradeability early, because switching from immutable to upgradeable later requires a migration.
  • Plan emergency controls such as pause functions, and disclose who holds them.
  • Choose the execution layer deliberately: a Layer 2 network lowers gas fees but adds its own trust and bridging assumptions.

Understanding it simply

A smart contract works like a vending machine that runs on a public network. You put in the right input, and it delivers the programmed result. No shop assistant decides whether to serve you, and nobody can secretly change the prices inside.

The catch is that the machine does exactly what it was built to do, even when the builder made a mistake. If there is a flaw, anyone can use it, and there is usually no manager to call.

Applied in practice

A group of independent musicians wants to split income from a shared online release fairly. Instead of trusting one member to collect and redistribute payments, they deploy a payment-splitter smart contract on an EVM-compatible network.

The contract records four wallet addresses and fixed shares of 40, 20, 20 and 20 percent. Every stablecoin payment sent to the contract address can be released to the members by calling a withdraw function, and the shares cannot be changed without a new deployment that all members approve.

Before launch, the group uses a widely audited open-source splitter template rather than custom code and tests it with small amounts. The result is automatic, transparent revenue sharing that each member can verify on a block explorer at any time.