Foundry a Hardhat
Narzędzia oparte na Rust
Foundry a Hardhat to bezpłatna lekcja Web3 & DApp Development Fundamentals na CoddyKit. To lekcja 1 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Web3 & DApp Development Fundamentals, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Web3 & DApp Development Fundamentals zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
What Is Foundry
Foundry is a fast, Rust-based toolkit for Ethereum development. It lets you write tests, scripts, and deployments entirely in Solidity, with no JavaScript layer required.
Its speed and Solidity-native testing have made it the dominant choice for many professional smart contract teams.
The Four Tools
Foundry ships as four command-line tools:
- forge — build, test, and deploy contracts
- cast — interact with chains and contracts from the CLI
- anvil — a local development blockchain
- chisel — a Solidity REPL
Together they cover the full development lifecycle.
What Is Hardhat
Hardhat is a JavaScript and TypeScript based development environment. Tests and scripts are written in JS/TS using libraries like ethers.js or viem, and it has a rich plugin ecosystem.
It is well suited to teams comfortable in the Node.js world and projects with heavy off-chain tooling.
Language for Tests
The biggest difference is the testing language:
- Foundry — tests are Solidity contracts; no context switch from your contract code
- Hardhat — tests are JavaScript/TypeScript using a chai-style assertion library
Solidity tests give Foundry direct access to internal state and low-level cheatcodes.
// Foundry test (Solidity)
function testIncrement() public {
counter.increment();
assertEq(counter.number(), 1);
}Speed
Foundry's Rust implementation and native EVM make it dramatically faster than Hardhat's Node-based runner, often by an order of magnitude on large suites.
Fast feedback loops matter: when tests run in milliseconds, developers run them constantly, catching bugs earlier.
Project Layout
A Foundry project has a conventional structure:
src/— your contractstest/— Solidity test files (suffix.t.sol)script/— deployment scripts (suffix.s.sol)lib/— dependencies installed as git submodulesfoundry.toml— configuration
myproject/
src/Counter.sol
test/Counter.t.sol
script/Deploy.s.sol
lib/forge-std/
foundry.tomlDependency Management
Foundry installs dependencies as git submodules via forge install, with import remappings instead of an npm registry. Hardhat uses npm packages.
Submodules keep exact source pinned in your repo, while npm offers familiar versioning and a vast package ecosystem.
$ forge install OpenZeppelin/openzeppelin-contracts
# adds to lib/ and updates remappingsCheatcodes
Foundry's killer feature is cheatcodes: special calls via the vm object that manipulate EVM state in tests. You can warp time, set balances, impersonate addresses, and expect reverts.
Hardhat offers similar capabilities through helper plugins, but Foundry's are built in and accessible directly from Solidity.
vm.warp(block.timestamp + 1 days);
vm.prank(alice);
vm.expectRevert("not owner");Scripting and Deployment
Foundry deployments are Solidity scripts run with forge script, using vm.startBroadcast() to send real transactions. Hardhat deployments are JS scripts run with hardhat run.
Solidity scripting keeps deployment logic in the same language as the contracts, reducing context switching.
function run() external {
vm.startBroadcast();
new Counter();
vm.stopBroadcast();
}Choosing Between Them
There is no universal winner:
- Choose Foundry for speed, fuzzing, and Solidity-native testing
- Choose Hardhat for rich JS/TS tooling and a large plugin ecosystem
Many teams use both: Foundry for unit and fuzz tests, Hardhat for complex deployment and integration tasks. They can coexist in one repo.
Installing Foundry
Foundry installs via foundryup, a version manager that fetches the latest binaries. Once installed, forge init scaffolds a new project ready to build and test.
$ curl -L https://foundry.paradigm.xyz | bash
$ foundryup
$ forge init my_projectQuick Check
In what language are Foundry tests written?
Recap
You compared the two main toolkits:
- Foundry is Rust-based with Solidity tests; Hardhat is Node-based with JS/TS tests
- Foundry tools: forge, cast, anvil, chisel
- Foundry is faster and has built-in cheatcodes and fuzzing
- Dependencies via git submodules vs npm
Next we dive into writing tests with forge.
Często zadawane pytania
Czy lekcja „Foundry a Hardhat” jest bezpłatna?
Tak — pełny tekst „Foundry a Hardhat” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Web3 & DApp Development Fundamentals, przejdź na CoddyKit PRO. Kurs Web3 & DApp Development Fundamentals zawiera 4 lekcji w sumie.
Co nauczysz się w „Foundry a Hardhat”?
Narzędzia oparte na Rust Ćwiczysz Web3 & DApp Development Fundamentals z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Web3 & DApp Development Fundamentals?
Nie wymagamy żadnego doświadczenia. Web3 & DApp Development Fundamentals w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 1 z 4.
Ile czasu zajmuje lekcja „Foundry a Hardhat”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Web3 & DApp Development Fundamentals?
Tak. Każda lekcja Web3 & DApp Development Fundamentals zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Foundry a Hardhat
- Testowanie za pomocą forge
- Fuzzing i niezmienniki
- cast i anvil