What is smart contract?

A program stored on a blockchain that executes automatically when its conditions are met.

Not yet verifiedHow we verify

3 min read

In this entry

A program stored on a blockchain that executes automatically when its conditions are met.

Smart contracts power defi, tokens, and NFTs. Bugs in smart contracts can be exploited, and transactions cannot be reversed. The name is misleading in both halves: they are neither smart nor contracts in any legal sense. They are deployed code that runs the same way for everyone and cannot be argued with.

For a buyer the relevant fact is that most tokens are smart contracts. When an exchange lists an asset it is listing a specific contract address, and a token with the same name and symbol at a different address is a different asset.

How it works

A contract is deployed to an address on a chain that supports them, and its code and storage become part of the chain's state. Anyone can call its functions by sending a transaction to that address. The network executes the code, charges for the computation in gas, and records the resulting state change in a block.

Three properties follow from that and matter more than the mechanics.

Determinism. Every node runs the same code on the same input and must reach the same result, which is why contracts cannot fetch data from the internet on their own and need an oracle instead.

Immutability by default. Deployed code cannot be edited. Projects that need to ship fixes use a proxy contract, where a small permanent contract forwards calls to an implementation that an administrator can swap. That is a convenience and also a trust assumption, because whoever holds that administrative key can change what the contract does.

Finality. A call that drains a wallet is a valid transaction. There is no reversal, no chargeback, and no operator with authority to undo it.

Example

Illustrative. A token contract is a table mapping addresses to balances plus a few functions. Calling transfer moves an entry from your row to someone else's. Calling approve writes a separate allowance saying another address may move up to a stated amount on your behalf, which is what a decentralized exchange needs before it can swap for you. If that other address is later exploited, the allowance you granted is still live and still usable, which is the mechanism behind a large share of wallet drains. See token approval.

Why it matters when you buy

If you buy on a centralized exchange, the venue handles contract interaction and you never sign one. If you buy on a decentralized venue, every purchase is a contract call you authorize yourself, and the approvals it leaves behind persist. The guide on verifying a token contract covers checking you are dealing with the right address, and the guide comparing venue types covers which set of risks you are taking on.

Questions

Are smart contracts legally binding?

Not by virtue of being code. They execute regardless of intent or error, and whether any legal obligation attaches is a question for the law of the jurisdiction involved, not for the chain.

Can a contract be changed after deployment?

Not directly. Many projects deploy behind an upgradeable proxy so an administrator can replace the implementation, which means asking who holds that key is part of assessing the contract. See upgradeable contract.

Do I interact with contracts when buying on an exchange?

Generally not. The exchange trades internally and only touches a chain on deposit and withdrawal, which is why exchange buying involves no approvals to manage. See cex.

Guides that use this term

  • Address Poisoning and Clipboard Attacks: How They Work and How to Avoid Them

    Address poisoning and clipboard hijacking both attack the same habit, which is copying a destination address from somewhere convenient instead of from the recipient, and both are defeated by verifying the full address at the moment you send rather than recognizing the first and last few characters.

  • Gas Fees Explained: Why They Change and How to Pay Less

    A gas fee is the amount of computational work your transaction uses multiplied by the price you pay per unit of that work, and it changes minute to minute because the price rises automatically when blocks are fuller than the network's target.

  • How to Use a Block Explorer to Check a Transaction

    A block explorer is a public search engine for a blockchain, and you check a transaction by pasting its hash into the search box and reading three fields: the status, the number of confirmations, and the receiving address.

  • Layer 1 vs Layer 2: What the Difference Means When You Buy and Move Crypto

    A layer 1 is a blockchain that settles its own transactions, while a layer 2 is a separate network that processes transactions off the main chain and posts them back to the layer 1 for settlement, which matters to you because the same token on two networks costs different amounts to move and does not share a deposit address.

  • Self-Custody vs Exchange Custody: How to Decide

    Deciding between self-custody and exchange custody means choosing which failure you would rather be exposed to, a company that loses or freezes your assets or a mistake of your own that nobody can undo, and most people resolve it by splitting holdings rather than picking one for everything.