My first Solidity smart contracts, written and tested while learning Ethereum development — using both Hardhat and Foundry side by side on the same codebase.
Contracts (contracts/):
MyFirstContract.sol— an ETH-holding contract withdeposit(),withdraw(), andtransfer(), using the checks-effects-interactions pattern to guard against reentrancy. Originally prototyped by hand in Remix.SimpleToken.sol— a from-scratch ERC20-style token:name/symbol/totalSupply,balanceOf,transfer,approve/allowance/transferFrom, and owner-restrictedmint.Animals.sol— a small inheritance exercise (Animalbase contract,cowoverride).
Tests, written both ways to compare the two ecosystems:
- Foundry (Solidity,
test/*.t.sol) — fast, no JS involved - Hardhat (JavaScript/Mocha,
test/*.test.js)
Deployment, also written both ways:
- Foundry script:
script/DeploySimpleToken.s.sol— a SolidityScriptcontract run viaforge script - Hardhat script:
scripts/deploy.js
Foundry:
forge build
forge test
forge script script/DeploySimpleToken.s.sol --rpc-url http://127.0.0.1:8545 --private-key <key> --broadcastHardhat:
npm install
npx hardhat compile
npx hardhat test
npx hardhat run scripts/deploy.js --network localhostLocal chain: either anvil (Foundry) or npx hardhat node works as the local Ethereum node these scripts deploy to.
Core Solidity concepts: mappings (including nested mappings for allowances), events, payable, view/pure, custom modifiers, access control (onlyOwner), inheritance/virtual/override, and the checks-effects-interactions security pattern — plus the practical side: compiling, testing, and deploying with two different toolchains against a local Ethereum node, and inspecting transactions with a local block explorer (Otterscan).