Smart contract
A smart contract is a program that lives on a blockchain and executes automatically when its conditions are met. Its code is public, it usually cannot be changed after deployment, and nobody can halt its execution.
How it works
A contract is published to the network once and gets its own address. After that anyone can call its functions by sending a transaction, and the network executes the code identically on every node and writes the result to the chain.
The caller pays for the computation through a gas fee. The more complex the operation the more it costs, and if the gas runs out the changes revert while the fee spent does not come back.
Immutability is what makes contracts both useful and dangerous. You need not trust a counterparty, because code enforces the terms; equally, a flaw in that code usually cannot be patched.
What they are used for
- Issuing tokensAlmost every token, USDT and USDC included, is a contract keeping a ledger of who holds what.
- Swapping without a middlemanA DEX is a contract holding a pool of two assets and swapping one for the other by formula, with no exchange and no account.
- Collateralised lendingA contract takes collateral, issues a loan, and sells that collateral itself when its price falls below a threshold.
- Running a projectA DAO votes with tokens, and the decision is carried out by a contract rather than by a manager.
What to weigh
- Who can change itMany contracts are upgradeable, which means somebody holds the upgrade key. Convenient for development, risky for you.
- Whose audit it hasThe report has to open, name the auditor, and cover the same contract address rather than some "project version".
- How much it holds, and for how longA contract holding a lot of money that has run for years unbroken is an argument in itself, though not a guarantee.
- What you have approvedA spending approval lasts indefinitely until you revoke it by hand. Review the ones you have granted.