A smart contract is a piece of code placed on a blockchain that writes the rules of an agreement as a program. When the specified conditions occur, the network executes it automatically, and no one can stop or tamper with it midway unless the code itself allows it.

The vending machine example#

In a vending machine the condition is simple: if you insert the money, the drink comes out. A smart contract has the same logic in the digital world: if the payment arrives, the token or asset is transferred, with no seller, bank, or lawyer.

Uses#

  • Trading and lending in DeFi
  • Creating and issuing tokens and NFTs
  • Self-governing organizations (DAOs)
  • Escrow for deals

Limitations#

  • "Smart" does not mean "intelligent" or "necessarily legally valid"; it only means automatic
  • Once the code is published, it is hard to fix
  • Any bug can cause millions of dollars of damage, because execution is irreversible
  • The code cannot directly access data outside the blockchain

Security notes#

Many scams happen through malicious contracts; for example, a request to "approve" a permission that in practice allows the contract to withdraw from your wallet. Before approving any permission, read carefully what you are agreeing to. Contracts with no security audit, or whose admin can change them at will, carry more risk.