BC7: Writing smart contracts in Solidity

Lesson 1 of 5 · reading 15–25 minutes; practice and project time is on the module page

What a smart contract is, and isn't

🎯You'll be able to

Explain what a smart contract can and can't do.

🏠The everyday picture

A vending machine: put in the right coins, press a button, and it gives the item by its fixed rules, for anyone, without a shopkeeper. It can't decide to be kind, and it can't fetch things from outside itself.

📘What it really is

📝A worked example

Input: the group wants "pay each member 2% interest on 1 January".

Steps:

  1. The contract can't wake up on 1 January; someone must call it.
  2. It can check block.timestamp is after 1 January when called.
  3. A loop over all members could run out of gas (BC5), so each member claims their own interest instead.

Expected output: a design that fits what contracts can do: called, checked, and bounded.

🌍Where it's used

📝Case scenario

A team built a contract that paid out when the price of a crop reached a level, reading the price from one website through a single oracle. The website showed a wrong price for an hour, and the contract paid out by mistake. Using several independent price sources would have reduced the risk.

🖱️Try it

For each, say whether a contract can do it alone: hold ether; send a reminder SMS; check that a caller is a member; pay interest at midnight automatically. Success: yes, no, yes, no.

⚠️Common mistakes

🛠️For your project

SakhiFund in Project 1 holds deposits and pays withdrawals when members call it; it does nothing on its own.

✅Quick check

Why can't a contract fetch data from a website by itself?

Show the answer

Every node must get the same result, so contracts can't read outside data directly.

What wins on the chain if the code and the intended agreement differ?

Show the answer

The code.

← BackBC7
ProLearners Assist