Blockchain and Trust Infrastructure Engineer · Focus area 3: Smart contracts
BC7: Writing smart contracts in Solidity
Goal: explain what a smart contract is and isn't, write Solidity with the right types, visibility and storage, control who can do what with modifiers, custom errors and events, handle ether safely, and use Hardhat to compile, test and deploy, knowing where Rust and other languages fit.
You'll need: BC5, Module 17 (JavaScript Basics), Module 23 (Functions and Scope), Module 27 (TypeScript Foundations), and the
SakhiKosh practice kit (contracts/SakhiFund.sol, hardhat.config.js, docs/FORMATS.md).
Where this is used: tokens, payments and escrow, voting, registries, multi-signature wallets and lending protocols are all smart contracts, and Solidity is the most widely used language for writing them.
How it differs: an ordinary backend can be patched tonight if there's a bug. A deployed contract's code can't be changed, anyone can call it, and every mistake is public and may move real money, so contracts are kept small and written carefully.
Time: reading about 3 hours · practice (the Try it tasks) about 3 hours · assignment about 4 hours.
Lessons
- 1What a smart contract is, and isn'tReading 15–25 minutes, plus practice✓
- 2Solidity basics: types, storage and functionsReading 15–25 minutes, plus practice✓
- 3Who may do what: modifiers, errors and eventsReading 15–25 minutes, plus practice✓
- 4Handling ether safelyReading 15–25 minutes, plus practice✓
- 5Tools, versions and other languagesReading 15–25 minutes, plus practice✓
🛠️Assignment: SakhiFund's first version
- Read the starter's
contracts/SakhiFund.soland list every function, its visibility and who should be allowed to call it. - Add
totalDeposits, custom errors and events fromdocs/FORMATS.md. - Replace the
tx.origincheck with anonlyAdminmodifier usingmsg.sender, and addsetPausedwithwhenNotPaused. - Rewrite
withdrawwith checks, effects, interactions, and check the result ofcall. - Run
npm run test:contractand note which tests pass now (at least 1, 2, 4, 6 and 7).
Self-check before you finish:
- [ ] Every function that changes state has the right access check.
- [ ] Every state change people care about emits an event.
- [ ] No
tx.originis used for authorisation. - [ ] The contract compiles with the pinned compiler.
✅Module check
Explain in a few sentences, in your own words:
What should a well-written smart contract look like?
Show a good answer
A good answer mentions: code and storage at an address that runs only when called, is deterministic and public, and can't be
changed; current Solidity with suitable types, immutable values and minimal storage; access checks on msg.sender with modifiers,
custom errors and events; ether handled with checks, effects and interactions, checked call results, pull payments and records that
match the balance; and pinned compilers, automated tests, verified source, and awareness of Vyper and Rust.
📚Official references
Official documentation and guidance for this module's topics, chosen on 2 November 2026. Tools, laws and standards change, so check the current version before you rely on a detail. If a link has moved, search the same site.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
