A smart contract is a program on a blockchain that every validating computer runs the same way, so it can hold tokens and move them by fixed rules without anyone's permission at the moment of execution. What it cannot do by itself is learn facts from outside the chain, produce unbiased random numbers, keep its data secret, reverse a transfer, or make anything happen in the physical world. Each gap is filled by an outside party, and each such party is a point of trust.
Key takeaways
- Contract code runs the same way on every node, which makes its rules enforceable without a middleman, within hard limits on computation.
- Anything the chain cannot see, from a price to a delivery, comes from an oracle, arbiter or bridge verifier, and false input is executed as faithfully as true input.
- On Ethereum, deployed code is fixed unless the contract was built upgradeable, and upgradeability means whoever holds the admin key can change the rules. Other chains set different defaults.
- US law recognizes electronic records and, in some states such as Arizona, smart-contract terms, but "code is law" is a slogan: courts still apply ordinary contract, property and criminal law.
How a contract runs on every node
On Ethereum, a smart contract is code and stored data (its "state") living at an address. ethereum.org's introduction to smart contracts compares it to a vending machine: the right inputs guarantee a given output. Every node executes each call in the Ethereum Virtual Machine (EVM), which the EVM documentation says behaves like a mathematical function, as specified in the Ethereum Yellow Paper. Because many independent machines must agree, no single operator can quietly decide differently.
The same design sets hard limits. The Yellow Paper calls the EVM "quasi-Turing-complete" because all computation is bounded by gas, a unit charged for every operation. Since the Fusaka upgrade went live on December 3, 2025, EIP-7825 caps any single transaction at 16,777,216 gas (2^24). Blocks have their own, adjustable limit: a public Ethereum node reported 60,000,000 gas for block 26,182,985 on October 13, 2026, so one transaction could use at most about 28% of that block. Contract code is also limited to 24KB, and a loop over an ever-growing list will eventually hit the cap and fail.
Worked example: what a token transfer costs
ethereum.org's gas documentation gives the fee, paid in ETH, as:
fee (gwei) = gas used × (base fee + priority fee)
fee (ETH) = fee (gwei) ÷ 1,000,000,000
The base fee is set by the protocol and burned, the priority fee is a tip to the validator, and one gwei is one-billionth of an ETH. A plain ETH transfer uses 21,000 gas. Receipts from a public Ethereum node for all 455 successful transfer calls to the USDC contract in blocks 26,182,966 to 26,182,985 (October 13, 2026) show gas used from 40,324 to 62,272, with a median of 45,160. The roughly 17,100-gas gap between the median and the top matches storage pricing in EIP-3529: writing a balance that was zero costs 20,000 gas against 2,900 for updating a non-zero one, and emptying a balance earns a 4,800 gas refund.
Illustrative example: assume a combined fee of 2 gwei and an ETH price of $3,000, used only to show scale. The base fee in the block above was about 0.64 gwei; fees change every block.
| Action | Gas used | Fee at 2 gwei | At an assumed $3,000/ETH |
|---|---|---|---|
| Plain ETH transfer | 21,000 | 0.000042 ETH | about $0.13 |
| Token transfer, median | 45,160 | 0.0000903 ETH | about $0.27 |
| Token transfer, highest observed | 62,272 | 0.0001245 ETH | about $0.37 |
At 20 gwei, all three are ten times higher: about $1.26, $2.71 and $3.74. A token transfer costs roughly two to three times a plain one because the contract reads and writes balances.
What the code can reliably do
Hold assets and release them by rule
A contract can have its own balance and send it only when coded conditions are met; Arizona's A.R.S. § 44-7061 defines a smart contract by exactly this power to take custody of assets and instruct their transfer. Common patterns are escrow (funds locked until a condition is met), multisignature wallets (a transfer needs, say, two of three designated keys) and vesting (tokens released on a schedule). None of these depends on the deployer's goodwill, as long as the code contains no override.
Follow shared interfaces
ERC-20 fixes the functions every fungible token exposes, such as balanceOf, transfer, approve and transferFrom, and ERC-721 does the same for non-fungible tokens. So a lending program can accept any ERC-20 token as collateral without custom work, and it also inherits the weaknesses of everything it calls. An ERC-20 approval lets another address withdraw a holder's tokens repeatedly up to the approved amount, so an approval granted to a malicious or flawed contract is a loss route of its own.
Show anyone what it does
Bytecode and transactions are public, and block explorers let developers publish source code shown to compile to the deployed bytecode. ethereum.org's page on verifying smart contracts sets out the limits: a "partial match," the more common kind, does not check the embedded metadata hash, and verification shows only that source and bytecode correspond, not that the logic is correct or safe. For a proxy contract (explained below), the verified code shown may belong to the current logic contract, which can later be swapped.
What it cannot do on its own
Know anything off the chain
Per ethereum.org's oracles page, contracts cannot fetch outside data because nodes querying a website at different moments could get different answers and fail to agree. An oracle writes the data onto the chain so every node reads the same value, but trusting its operators undermines the "trustless" claim, and the page warns that even reputable providers can go rogue or be hacked.
False input is executed as faithfully as true input. In the Mango Markets case described below, the oracle averaged a token's price from three exchanges, so trades that pushed that price up inflated a trader's collateral. In April 2026, according to Chainalysis's analysis of the KelpDAO bridge exploit, attackers fed a forged cross-chain message to a token configured with a single off-chain verifier, and an Ethereum contract released about $292 million in tokens. Chainalysis stresses this was not a smart contract hack but an attack on off-chain infrastructure.
Produce fair random numbers
Deterministic code has no natural source of chance. Contracts can read a value from the beacon chain's RANDAO process, but EIP-4399 warns that each block proposer has one bit of influence per slot, for example by withholding a block, and recommends relying on randomness well in the future (at least four epochs of lookahead). The alternative is a verifiable random function (VRF) delivered by an oracle with a cryptographic proof, which adds that oracle as a dependency.
Keep secrets
The Solidity documentation's security considerations are blunt: everything used in a smart contract is publicly visible, even variables marked private. The commit-and-reveal pattern in the Solidity docs' blind auction example posts a hash first and the value later, which hides a bid only until the reveal.
Change, unless built to
ethereum.org's guide to upgrading smart contracts says contracts are immutable by design. The workaround is a proxy, which holds the data and forwards each call to a logic contract whose address can be replaced. EIP-1967 standardizes where a proxy stores that logic address and an optional admin address, the address allowed to upgrade it. Users must then trust developers not to change contracts arbitrarily; the guide suggests multisig or DAO control plus timelocks, which give users time to exit but slow emergency fixes. The default differs by chain: on Solana, a program deployed with the upgradeable loader can be changed while an upgrade authority is set, and becomes immutable only once that authority is revoked.
Undo a mistake
ethereum.org states that interactions with a contract are irreversible. There is no chargeback: tokens sent to a wrong address, or to a contract with no way to return them, stay there. If someone, such as a token issuer, can move or freeze them, that power is another trust point, not a default protection.
An escrow, line by line
Illustrative example: a buyer pays 1 ETH for a used camera through an escrow contract. The pseudocode below is written for this article and is not deployable code.
state: AWAITING_PAYMENT
price = 1 ETH
deadline = 14 days after payment
on deposit(amount) from buyer:
require state == AWAITING_PAYMENT and amount == price
state = PAID; record payment time
on confirmReceipt() from buyer:
require state == PAID
send price to seller; state = DONE
on refund() from arbiter:
require state == PAID
send price to buyer; state = DONE
on claimAfterDeadline() from seller:
require state == PAID and now > deadline
send price to seller; state = DONE
The code guarantees that the 1 ETH leaves only through one of three paths, each triggered only by its named address, and only once. It has no idea whether the camera shipped, arrived or works. That fact enters only through the buyer, the arbiter or the deadline: if the seller never ships and the arbiter does nothing, the seller can still claim after 14 days. The protection is as good as those people and that timer.
The Solidity docs' safe remote purchase example uses incentives instead: for a 1 ETH item each side deposits 2 ETH, and on confirmation the buyer gets 1 ETH back while the seller gets 3 ETH. If neither cooperates, the deposits stay locked. The docs say there is no way to determine for sure that the item arrived.
| Task | Can do on its own | Cannot do | Needs an outside party |
|---|---|---|---|
| Lock funds and release them by coded rules | Yes | Release under a rule the code lacks | No, unless an admin override exists |
| Pay out when goods arrive | Pay out once told | See the delivery | Buyer, arbiter or delivery oracle |
| Value collateral or settle a bet on a price | Apply the formula | Know the market price | Price oracle |
| Pick a random winner | Use a supplied random value | Generate an unbiased one | RANDAO with lookahead, or a VRF oracle |
| Keep bids or personal data secret | Store a hash | Hide stored values | Off-chain storage or privacy systems |
| Fix a bug after launch | Only if built upgradeable | Edit deployed code | Admin key or governance vote |
| Reverse a mistaken transfer | Only via a coded refund path | Issue a chargeback | Recipient's cooperation, issuer or court |
| Prove who signed | Check a key's signature | Know the person's legal identity | Identity verifier |
When the code itself is wrong
Bugs execute as faithfully as intended rules. The SEC's July 2017 report on The DAO (Release No. 81207) records that on June 17, 2016 an attacker used a flaw in The DAO's code to divert about 3.6 million ETH, one-third of what its offering raised. The code did not recover the money: a hard fork adopted by most of the network on July 20, 2016 moved the funds to a recovery address, while a minority kept the old chain.
ethereum.org's smart contract security page cites a multisig wallet bug that left over $300 million in ETH locked forever, and warns that audits will not catch every bug.
Code is not the same as law
"Code is law," the idea that whatever a contract permits is fair, is a slogan no US statute adopts. What the law does is recognize electronic forms. For transactions in or affecting interstate or foreign commerce, the federal ESIGN Act, 15 U.S.C. § 7001, says a contract may not be denied legal effect solely because it is electronic or was formed by electronic agents, provided their actions are legally attributable to the person to be bound. Section 7003 excludes areas such as wills, family law, most of the UCC and certain foreclosure and eviction notices. Arizona's § 44-7061 adds that a contract may not be denied effect solely because it contains a smart contract term. "Solely" matters: the arrangement still has to meet ordinary requirements, such as agreement between the parties, to be enforceable.
The Uniform Law Commission's 2022 amendments to the Uniform Commercial Code add Article 12 on "controllable electronic records," a category that can include crypto tokens. Under New York's version, N.Y. UCC § 12-105, control means the power to obtain substantially all of a record's benefit, the exclusive power to stop others from doing so and to transfer control, and a way to identify oneself, such as a cryptographic key. States adopt the amendments individually, so whether Article 12 applies depends on the jurisdiction.
The Mango Markets case shows how courts treat an exploit the code allowed. In 2024 a jury convicted Avraham Eisenberg of commodities fraud, commodities manipulation and wire fraud. On May 23, 2025, Judge Arun Subramanian's opinion in United States v. Eisenberg vacated the two commodities convictions because the government had not shown the offenses occurred in the Southern District of New York, and acquitted him of wire fraud because the platform had no terms, policies or rules about borrowing, so the evidence showed no false representation. The outcome turned on venue and misrepresentation, not on the code permitting the trades. News reports say prosecutors appealed; check for a Second Circuit ruling before relying on this outcome.
Frequently asked questions
Is a smart contract a legally binding contract?
Not automatically. Whether a binding agreement exists depends on ordinary contract law, such as offer, acceptance and the parties' intent; ESIGN and laws like Arizona's only stop a court from rejecting it solely for being electronic or coded. A lawyer licensed in the relevant state can assess a specific arrangement.
Can a smart contract run itself on a schedule?
No. Code on Ethereum runs only when a transaction calls it, so "automatic" monthly payments need a person or an automated service to send that transaction and pay the gas. A vesting contract can make tokens claimable after a date, but someone still has to submit the claim.
Can someone delete a deployed contract?
On Ethereum, effectively no. Since the Dencun upgrade of March 13, 2024, EIP-6780 lets the SELFDESTRUCT instruction delete a contract only within the transaction that created it; called later, it just sends the contract's ETH elsewhere and leaves the code and storage in place. An admin can still pause it or swap an upgradeable contract's logic if the code grants those powers.
Does the person who deployed a contract still control it?
Only through powers written into the code. ethereum.org's vending-machine example lets anyone buy but only the owner's address restock, and a real contract can likewise reserve pausing, minting or upgrading for one address. Which functions are restricted, and to whom, shows how much control the deployer kept.
What happens if a transaction runs out of gas?
Under the Yellow Paper rules, the call's changes are reverted as if it never ran, but the gas consumed is not refunded. The sender still pays a fee for a transaction that did nothing, so wallets estimate gas in advance and senders set a limit above that estimate.
Questions before relying on one
- Is it upgradeable? Block explorers read the EIP-1967 slots to show whether an address is a proxy and which logic contract it currently uses.
- Who holds the admin or upgrade key: one address, a multisig with how many signers, or a governance vote? Is there a timelock that gives users time to leave?
- What outside inputs does it trust? Name each oracle, bridge verifier or arbiter, how many independent sources stand behind it, and what the contract does if a value is wrong or stops arriving.
- Has the code been audited, and has it changed since? An audit covers one version.
- What happens if it fails, and who can pause it, refund or trigger a deadline?
- Which promises can the code not check, such as delivery, identity or legal title, and who stands behind each?
- Which law applies if things go wrong, and do written terms exist? The Mango ruling shows how much can turn on them.
Sources
- ethereum.org: Introduction to smart contracts
- ethereum.org: Ethereum Virtual Machine
- Ethereum Yellow Paper (Shanghai version, 2025-02-04)
- EIP-7825: Transaction gas limit cap
- ethereum.org: Fusaka upgrade
- ethereum.org: Gas and fees
- EIP-3529: Reduction in refunds
- Arizona Revised Statutes § 44-7061
- ERC-20: Token standard
- ERC-721: Non-fungible token standard
- ethereum.org: Verifying smart contracts
- ethereum.org: Oracles
- Chainalysis: Inside the KelpDAO bridge exploit (April 23, 2026)
- EIP-4399: Supplant DIFFICULTY opcode with PREVRANDAO
- Solidity documentation: Security considerations
- Solidity documentation: Solidity by example
- ethereum.org: Upgrading smart contracts
- ERC-1967: Proxy storage slots
- Solana documentation: Programs
- SEC: Report of investigation, The DAO (Release No. 34-81207)
- ethereum.org: Smart contract security
- 15 U.S.C. § 7001 (ESIGN Act)
- 15 U.S.C. § 7003: Specific exceptions
- Uniform Law Commission: Uniform Commercial Code, including 2022 amendments
- N.Y. UCC § 12-105: Control of controllable electronic record
- United States v. Eisenberg, No. 23-cr-10 (S.D.N.Y. May 23, 2025), opinion and order
- EIP-6780: SELFDESTRUCT only in same transaction