What is a smart contract? How it works and key risks
A plain-language smart-contract example, what on-chain code can verify, and where bugs, oracles and upgrade permissions add risk.
In this guide · 6 sections
A contract can enforce code, not every promise
Consider an on-chain escrow that releases funds after a delivery signal. Three distinct checks matter:
What the program knows
It can check balances, signatures, deadlines and a submitted delivery signal, then update its recorded state.
What an oracle reports
The program cannot inspect a physical parcel. An outside party or data service must report that delivery occurred.
What still needs trust
Someone must assess a false delivery report, a bug, or a team with permission to pause or upgrade the code.
Key question: Which part is checked by the network, and which part is only asserted by a website, oracle or administrator?
A “smart contract” is on-chain software, not automatically a legally enforceable agreement. A transaction calls its functions, and the network checks the programmed result. The useful question is which conditions the code can actually verify—and which still depend on people, data feeds or an administrator.
The core idea
A smart contract is deployed code called by a transaction or another contract. For example, it might hold funds until an authorized party submits a release instruction. It cannot independently know that a parcel arrived or decide what a buyer “really meant”; outside information must come from a user or an oracle, adding another trust point. Some contracts are immutable, while others can be upgraded or paused by designated parties. Check the actual permissions before assuming the rules cannot change.
What actually happens when a smart contract runs
A contract has an address and exposes functions. A transaction calling one of them is executed and checked by the chain’s validating participants according to its rules; not every device connected to the network runs every call. The resulting state change is recorded if the transaction succeeds. On Ethereum, the caller pays gas for the work, even when a call fails after consuming computation. The code’s result can be verifiable without making the inputs, oracle or upgrade administrator trustworthy.
A swap is two permissions, not one click
When an app asks you to swap a token, it may first ask for a token approval that permits a specified contract to spend up to a limit from your wallet. A later transaction performs the swap. Those are different actions, each with its own contract address, network and potential fee. An approval can remain active after the swap. A wallet prompt showing an unlimited allowance should be understood as continuing authority, not just the amount in the current trade.
Before signing, compare the connected site’s domain, target contract, token, allowance and network with the app’s own documentation. Use a wallet or explorer’s permission view to review and, where supported, revoke approvals you no longer need. Revoking is itself an on-chain transaction and may cost gas; it does not reverse a completed transfer or recover funds from an exploit.
Older than blockchains, made practical by Ethereum
Nick Szabo described the idea in the 1990s, before blockchains. Bitcoin supports limited scripting; Ethereum’s 2015 launch made more general-purpose on-chain programs practical. The useful distinction is not the history of the name but the scope of the rules: a smart contract enforces code against blockchain state, not every promise made in a website’s marketing.
What smart contracts don’t guarantee
Executing exactly as coded includes executing bugs. The 2016 DAO exploit exposed a reentrancy flaw in application code and helped trigger the split between Ethereum and Ethereum Classic. An audit may reveal weaknesses, but it is not a warranty. Before depositing, check the contract address, audit scope and date, and whether the application can be paused or upgraded.
| Claim on an app page | More useful question |
|---|---|
| “Audited” | Which deployed contract version was reviewed, when, by whom, and were the findings resolved? |
| “Non-custodial” | Can an administrator freeze, redirect, upgrade or otherwise affect the funds? |
| “Decentralized” | Which oracle, bridge, website, signer or governance group does this action still depend on? |
Published source code helps a reader inspect what was deployed, but it does not make the program safe by itself. A proxy contract may delegate to upgradeable implementation code. A front end may also point to a different address from the one previously audited. Match the chain and address in the wallet prompt to the project’s own official records before treating any audit as relevant.
Where smart contracts actually get used
Decentralized exchanges can use contracts to manage a trading pool or settle orders. Lending protocols can use them to track collateral and execute liquidations. NFT contracts can record token ownership and define transfer rules, but a creator royalty is not guaranteed on every resale. In every case, inspect the specific contract, its administrators and its external dependencies. “On-chain” does not remove all intermediaries or operational risk.
When the input is wrong, correct code can still lose money
Consider a lending contract that liquidates collateral when an oracle reports a price below a threshold. The contract may execute that rule perfectly. If the oracle is manipulated, stale or unavailable, the decision can still be harmful. Likewise, a bridge can represent an asset on another chain while depending on signers or custody outside the receiving contract. The failure mode is not always a broken blockchain; it can sit at the boundary between on-chain rules and outside facts.
The practical takeaway
A smart contract can replace one intermediary for a specific on-chain action while adding dependence on code, administrators and data feeds. Upgradeability can let a team fix bugs, but it can also change the rules after you deposit. Treat “audited” and “decentralized” as claims to inspect, not safety labels. For a large transaction, test the full deposit and withdrawal route with an amount whose loss you could tolerate.
If a contract interaction fails, distinguish a reverted on-chain call from a pending wallet request or an app error. A failed call may still consume gas. If it succeeds but the app balance is unchanged, check the transaction on the correct chain and the token contract address before signing a second transaction. Do not follow an unsolicited “recovery” link or share a seed phrase with purported contract support.