Foundry مقابل Hardhat
أدوات مبنية على Rust
Foundry مقابل Hardhat درس مجاني في Web3 & DApp Development Fundamentals على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Web3 & DApp Development Fundamentals، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Web3 & DApp Development Fundamentals 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
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.
الأسئلة الشائعة
هل درس «Foundry مقابل Hardhat» مجاني؟
نعم — نص درس «Foundry مقابل Hardhat» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Web3 & DApp Development Fundamentals، انتقل إلى CoddyKit PRO. تتضمن دورة Web3 & DApp Development Fundamentals 4 دروس في المجموع.
ماذا ستتعلم في «Foundry مقابل Hardhat»؟
أدوات مبنية على Rust تتمرن على Web3 & DApp Development Fundamentals مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Web3 & DApp Development Fundamentals؟
لا تُشترط خبرة سابقة. Web3 & DApp Development Fundamentals على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «Foundry مقابل Hardhat»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Web3 & DApp Development Fundamentals هذا؟
نعم. كل درس في Web3 & DApp Development Fundamentals يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- Foundry مقابل Hardhat
- اختبار forge
- الاختبار العشوائي والثوابت
- cast وanvil