BC7: Writing smart contracts in Solidity
Tools, versions and other languages
🎯You'll be able to
Compile, test and deploy with Hardhat, and explain where Vyper and Rust fit.
🏠The everyday picture
A workshop has a bench (where you build), a test rig (where you try), and a delivery van (how it leaves). You use all three every time.
📘What it really is
-
Hardhat: compiles contracts, runs tests on an in-process network, and deploys with scripts. The kit uses Hardhat 3 with ethers.js and Mocha tests.
-
Foundry: another popular toolkit, with tests written in Solidity and fast fuzzing.
- Compiler versions: fix the compiler version in your settings so builds are repeatable. The kit pins solc 0.8.38 from npm.
- Optimiser: reduces gas; keep the same settings for deployment and verification.
- Verifying source: publishing source code on an explorer lets others check the deployed bytecode matches.
- Other languages: Vyper is a Python-like language for the EVM; Rust is used for Solana programs and for some other chains. Concepts carry over: storage, access control, events, and careful testing.
📝A worked example
Input: compile and test SakhiFund from the kit.
Steps:
npm run compile: Hardhat compiles with the pinned solc, without downloading anything.npm run test:contract: runs Project 1's 10 tests on a fresh in-process network.npm run chainandnpm run deploy:local: deploys to the practice network for the app.
Expected output: a repeatable build, test and deploy.
🌍Where it's used
- Hardhat and Foundry in most Ethereum teams.
- Anchor and Rust for Solana programs.
- Explorers for verified source.
📝Case scenario
A team couldn't verify its deployed contract on an explorer because nobody had recorded the compiler version and optimiser settings used. Users couldn't check the code, and trust suffered. Pinning versions in the project's settings, and keeping deployment records, made later releases verifiable.
🖱️Try it
Open hardhat.config.js and write down the compiler version and optimiser settings. Success: 0.8.38, optimiser on, 200 runs.
⚠️Common mistakes
- Unpinned compilers. Sign: different bytecode on different machines. Fix: pin the version.
- Only testing by hand. Sign: "I clicked around in a wallet". Fix: automated tests.
- Assuming skills transfer exactly. Sign: Solidity habits in Rust. Fix: learn each chain's model.
🛠️For your project
All three projects run with npm test. The capstone's design notes can mention other languages, but the kit uses Solidity only.
✅Quick check
Why pin the compiler version?
Show the answer
So everyone gets the same bytecode, and the deployed contract can be verified.
Where is Rust used for smart contracts?
Show the answer
For Solana programs and on some other chains.
