Skip to content
ESEN

Smart Contracts

A smart contract is a program that lives on the blockchain and executes automatically when certain conditions are met.

The vending machine analogy

Think of a vending machine:

  1. You insert money
  2. You select a product
  3. The machine automatically gives you the product

There's no employee deciding whether to give you the product or not. The rules are programmed and they execute automatically.

A smart contract works the same way, but on the blockchain:

A SMART CONTRACT, IN ESSENCE

IF you receive 1 ETH from address 0xABCTHEN send 1000 USDC to address 0xABC

That's it. The difference from a normal program is that it executes on its own, and once deployed no one can modify it or stop it — not even whoever wrote it.

What are they for?

Smart contracts are the foundation of almost everything interesting in crypto:

ApplicationHow it uses smart contracts
Decentralized exchangesAutomatic token swapping
Lending (DeFi)Collateral and automatic liquidations
NFTsOwnership and transfer of digital art
DAOsAutomatic voting and governance
StablecoinsMaintaining the dollar peg

Example: Decentralized exchange

When you swap ETH for USDC on Uniswap:

POOL ETH / USDCETH100USDC200,000Price = 200,000 ÷ 100 = $2,000 per ETHYou put in 100 USDCYou get ~0.0498 ETH
There is nobody on the other side — the pool itself is your counterparty. After the swap it holds more USDC and less ETH, so the price of ETH goes up on its own.

No one is "approving" your transaction. The code executes the same for everyone.

The risk isn't where you think

Understanding Solidity isn't what protects you. Money gets lost in one very specific moment: when your wallet asks you to sign and you accept without knowing what you're accepting.

That deserves its own page, with the four types of signature, which one is dangerous, and the checklist:

What to check before signing

Contracts also fail on their own

Even if you do everything right, the contract can have bugs. It's happened to large, audited protocols:

YearProjectLossCause
2016The DAO$60MBug in the withdrawal function
2023Euler Finance$197MVulnerability in liquidations
2023Curve Finance$73MBug in the Vyper language
2024Orbit Bridge$82MCompromised keys

That's why it's worth preferring old, heavily-used protocols over new, shiny ones: not because they're infallible, but because they've gone more years without breaking.

Code is law (but be careful)

In crypto there's a phrase, "code is law." It means whatever is programmed into the smart contract is what will happen, no exceptions.

This has advantages (no one can censor you) but also downsides (if you get robbed, there's no "customer service" to help you).

Remember

  • There's no "undo" button on the blockchain
  • There's no bank to call to cancel a transaction
  • Your security is 100% your responsibility

Sign vs Approve

To understand the critical difference between signing a message and approving a contract (where 90% of hacks happen), read the section Sign vs Approve in DeFi in 5 Minutes.

Summary

  • Smart contracts are automatic programs on the blockchain
  • They power applications like exchanges, lending, and NFTs
  • They carry risks: bugs, excessive approvals, malicious contracts
  • Always verify what you're signing before approving a transaction

If you came looking for something else:I'm about to receive crypto · I want to cash out to local currency · Start from the beginning