Smart Contract
A smart contract is a program stored on a blockchain that runs automatically when called and its coded conditions are met. Every node executes it the same way, so no intermediary is needed to enforce the outcome.
A smart contract is deployed to a blockchain such as Ethereum, where it gets its own address and can hold code, data and funds. Users or other contracts trigger it by sending a transaction and paying a gas fee. Every node runs the same code and must reach the same result, which is why execution is deterministic. Contracts cannot fetch outside information on their own, because relying on external data could jeopardise consensus. Services called oracles are used to bring prices and other real-world data on-chain.
Smart contracts are the building blocks of most of crypto beyond simple payments. Tokens, NFTs, decentralized exchanges, lending protocols and DAOs all run on them. When a wallet asks you to approve or sign something in a dApp, you are usually interacting with a smart contract.
For example, on a decentralized exchange, an automated market maker contract holds pools of two tokens. You send it token A, it calculates a price from the pool's reserves and sends token B back in the same transaction. If a condition fails, such as the price moving beyond your slippage limit, the whole transaction reverts.
The main risk is that the code does exactly what it says, including its mistakes. Bugs have led to exploits and lost funds, and deployed code often cannot be changed. Some contracts are upgradeable, which means their administrators can alter them. Despite the name, a smart contract is not intelligent and is not automatically a legal agreement.