إعداد Hardhat أو Truffle
ثبّت إطار عمل احترافيًا لتطوير Solidity، مثل Hardhat أو Truffle، وهيّئه لإدارة المشاريع بكفاءة.
إعداد Hardhat أو Truffle درس مجاني في Blockchain Smart Contracts with Solidity على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Blockchain Smart Contracts with Solidity، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Blockchain Smart Contracts with Solidity 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Beyond Remix: Why Use a Framework?
Remix is fantastic for quick tests and learning Solidity basics. However, for building real-world smart contract projects, you need more robust tools.
Development frameworks like Hardhat and Truffle provide a professional environment for managing your entire project lifecycle. They streamline tasks like:
- Automated testing of your contracts
- Managing deployments to different networks
- Running a fast, local blockchain for development
- Organizing complex project structures
They make development faster, more efficient, and more reliable.
Meet the Contenders: Hardhat & Truffle
Hardhat and Truffle are the two most popular development frameworks in the Ethereum ecosystem.
- Hardhat: A modern, flexible framework built specifically for Ethereum. It's known for its speed, extensive plugin system, and excellent developer experience.
- Truffle: An older, more established framework with a broader ecosystem. It supports various EVM-compatible chains and has a large community.
Both are powerful tools. For this lesson, we'll primarily focus on setting up Hardhat due to its growing popularity and developer-centric design.
What You'll Need to Get Started
Before we install a framework, you'll need two essential tools on your computer:
- Node.js: A JavaScript runtime environment.
- npm (Node Package Manager): Comes bundled with Node.js, used for installing software packages.
These are crucial for managing project dependencies and running development tools. You can check if they're installed by typing node -v and npm -v in your terminal.
If you don't have them, download and install Node.js from the official Node.js website.
Installing Hardhat in Your Project
Let's get Hardhat installed! First, create a new empty directory for your project and navigate into it using your terminal. Then, install Hardhat as a development dependency.
Installing it this way ensures each project can use its own specific Hardhat version, avoiding conflicts between projects.
mkdir my-hardhat-project
cd my-hardhat-project
npm install --save-dev hardhatInitializing Your Hardhat Project
Once Hardhat is installed locally, you can initialize a new project. This command will prompt you with a few options to set up a basic project structure.
Choosing 'Create a basic sample project' is a great way to start. It generates a sample contract, test file, deployment script, and the crucial hardhat.config.js file.
npx hardhat initYour Project's Brain: hardhat.config.js
The hardhat.config.js file is the central configuration hub for your entire Hardhat project. It's written in JavaScript and allows you to define:
- The Solidity compiler version to use (e.g.,
0.8.19) - Custom networks for deployment (like testnets or mainnet)
- Plugins you want to use (e.g., for Ethers.js, Waffle)
- Custom tasks to extend Hardhat's functionality
Here's what a minimal hardhat.config.js might look like:
require("@nomicfoundation/hardhat-toolbox");
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.19", // Your desired Solidity compiler version
networks: {
// Configuration for different networks goes here
// For example, a testnet like Sepolia or Goerli
}
};Instant Blockchain: The Hardhat Network
One of Hardhat's most powerful features is its built-in Hardhat Network.
This is a local Ethereum network designed specifically for development and testing. It's incredibly fast, isolated, and automatically resets on each run, providing a clean slate every time you test your contracts.
You don't need to run a separate local blockchain client (like Ganache) when using Hardhat; it's all integrated, making your development workflow seamless and efficient!
(Optional) Setting Up Truffle
While we're focusing on Hardhat, it's good to know how to set up Truffle, as it's also widely used. The process is similar to Hardhat:
- Install Truffle globally using npm.
- Create a new directory for your project.
- Initialize a new Truffle project within that directory.
Truffle often works hand-in-hand with Ganache, a personal Ethereum blockchain for local development, which you would typically run separately.
npm install -g truffle
mkdir my-truffle-project
cd my-truffle-project
truffle initTruffle Project Structure at a Glance
A Truffle project also follows a logical structure to organize your smart contract development:
contracts/: This is where all your Solidity source code files (.sol) live.migrations/: Contains JavaScript files that help you deploy your contracts to the blockchain.test/: Your JavaScript and Solidity test files for verifying contract logic.truffle-config.js: The main configuration file for your Truffle project.
Understanding these standard project layouts helps you navigate and manage your smart contract projects effectively.
Test Your Knowledge
Let's check your understanding of development frameworks for smart contracts.
Recap: Frameworks for Success
Congratulations! In this lesson, you've taken the first big step into professional smart contract development.
We learned why frameworks like Hardhat and Truffle are essential, how to set up a new Hardhat project, and understood the importance of the hardhat.config.js file.
You also got a glimpse of Hardhat's powerful built-in local network and an optional overview of Truffle setup. A solid development environment is your foundation for building robust and reliable smart contracts!
الأسئلة الشائعة
هل درس «إعداد Hardhat أو Truffle» مجاني؟
نعم — نص درس «إعداد Hardhat أو Truffle» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Blockchain Smart Contracts with Solidity، انتقل إلى CoddyKit PRO. تتضمن دورة Blockchain Smart Contracts with Solidity 4 دروس في المجموع.
ماذا ستتعلم في «إعداد Hardhat أو Truffle»؟
ثبّت إطار عمل احترافيًا لتطوير Solidity، مثل Hardhat أو Truffle، وهيّئه لإدارة المشاريع بكفاءة. تتمرن على Blockchain Smart Contracts with Solidity مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Blockchain Smart Contracts with Solidity؟
لا تُشترط خبرة سابقة. Blockchain Smart Contracts with Solidity على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «إعداد Hardhat أو Truffle»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Blockchain Smart Contracts with Solidity هذا؟
نعم. كل درس في Blockchain Smart Contracts with Solidity يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- إعداد Hardhat أو Truffle
- ترجمة العقود ونشرها
- التفاعل مع العقود المنشورة
- كتابة اختبارات العقود وتشغيلها