Smart contracts are the building blocks of DeFi and Web3. Here's how they work.
What is a Smart Contract?
A smart contract is code stored on a blockchain that automatically executes when conditions are met. No middleman needed.
Simple Example
Escrow smart contract:
- Buyer sends payment to contract
- Seller sends goods
- Buyer confirms receipt
- Contract releases payment to seller
If conditions aren't met, funds return automatically.
Use Cases
- DeFi protocols
- NFT minting and sales
- DAOs and governance
- Insurance
- Supply chain
Limitations
- Can't access outside data (need oracles)
- Bugs can be exploited
- Immutable (hard to fix mistakes)
- Gas costs for complex operations