The Crypto Linkup

Learn / Beginner · DeFi and Apps

What is a smart contract?

Beginner · DeFi and Apps · about 5 min read

A smart contract is a program stored on a blockchain that runs by itself when its conditions are met.

How it works

Keep in mind

An example you can picture

Ethereum's guide gives the example of a contract that holds money for a child and releases it after a set date. No bank manager needs to approve it, and no one can stop it because they changed their mind. Another simple case is a sale: the contract receives the buyer's payment, checks that the seller delivered a digital item, and releases the money. If the conditions are not met, nothing moves.

What makes them useful

What they cannot do

A contract follows its code, whether or not the code does what its author meant. It does not judge whether a deal is fair, and it does not fix a mistake. If you send tokens to the wrong place under its rules, they stay there. Because most contracts cannot be changed after they are created, a bug can stay in place for good. This is why reading and auditing code matters, and why an audit is a help and not a guarantee.

Reading what you sign

Ethereum's guide warns that raw transaction data is hard for humans to read, which causes "blind signing", where people approve something they do not understand. Two kinds of request look similar in a wallet but are very different. A transfer sends tokens once. An approval gives a contract permission to spend a token on your behalf, sometimes with no limit, and that permission stays until you cancel it. Before you sign, ask what is being approved, for which token and how much, and to whom.

Common mistakes

Try it yourself

  1. Write the rules for a lemonade stand as "if this, then that" lines: if the buyer pays the price, then the cup is handed over. Then add one rule for what happens when the buyer pays too little. This is how a contract is built.
  2. Look up a well-known stablecoin's contract on a block explorer. Note when it was created and how many transactions it has handled. You do not need a wallet.
  3. Write down what you would want to check before approving a contract to spend your tokens.

Key terms

Smart contract, code, on-chain, deploy, wallet approval.

Sources and credits

What smart contracts are, their properties and limits: ethereum.org, Intro to smart contracts. Security and approvals: ethereum.org, Stay safe. General information, not financial advice.

Module quiz

3 questions. Tap an answer to see if you are right and why. Get 2 right to complete the module.

1. What is a smart contract?

2. What does the vending machine comparison show?

3. Why should you be careful with smart contracts?

Back to Learn →