Configuring Hardhat for Development on Mode Network
In this article, we'll explore how new builders, even those who feel like baby dinosaurs handling slightly older technologies, can configure their development environment using Hardhat to integrate with Mode Network. We'll break down the configuration file, covering network setup, Solidity compiler settings, gas usage reporting, Sourcify integration, and Etherscan integration. Each step is designed to allow any developer, regardless of their level of experience, to optimize their environment and work efficiently on Mode Network-specific projects.
What is Hardhat?
Hardhat is a development environment designed for building and testing decentralized applications (dApps) on the Ethereum blockchain. It provides a robust set of tools and plugins that simplify the process of compiling smart contracts, running tests, and deploying to various networks.
What is Mode Network?
Mode Network is a blockchain platform optimized for high performance and scalability. It offers developers a reliable environment to deploy decentralized applications, with a focus on efficient transaction processing and minimal costs.
Configuration Code Example
To get started, you need to install Hardhat locally in your project. Make sure you have Node.js and npm installed. Then, follow these steps:
Install Hardhat:
npm install --save-dev hardhat
Create a Hardhat Project:
npx hardhat
Update the hardhat.config.js File:
Here's an example configuration for Mode Network Mainnet:
import { HardhatUserConfig } from 'hardhat/config' import '@nomicfoundation/hardhat-toolbox' require('hardhat-deploy') import * as dotenv from 'dotenv' dotenv.config() // Load environment variables const { DEPLOYER_PRIVATE_KEY, ETHERSCAN_API_KEY } = process.env const providerApiKey = process.env.ALCHEMY_API_KEY // Configuration object for Hardhat const config: HardhatUserConfig = { networks: { // Configuration for local development network hardhat: { forking: { // URL for forking mainnet url: `https://eth-mainnet.alchemyapi.io/v2/${providerApiKey}`, // Enable forking if MAINNET_FORKING_ENABLED is 'true' enabled: process.env.MAINNET_FORKING_ENABLED === 'true', }, }, // Configuration for ModeTest network modetest: { // URL for ModeTest network url: 'https://sepolia.mode.network', // Chain ID for ModeTest network chainId: 919, // Account(s) to use for deployments on ModeTest network accounts: [DEPLOYER_PRIVATE_KEY as string], // Gas price for transactions on ModeTest network gasPrice: 10000, }, // Configuration for Mode network mode: { // URL for Mode network url: 'https://mainnet.mode.network', // Chain ID for Mode network chainId: 34443, // Account(s) to use for deployments on Mode network accounts: [DEPLOYER_PRIVATE_KEY as string], }, }, // Solidity compiler configuration solidity: { // Version of Solidity compiler to use version: '0.8.20', settings: { // EVM version evmVersion: 'london', }, }, // Configuration for gas reporting gasReporter: { // Enable gas reporting if REPORT_GAS is defined enabled: process.env.REPORT_GAS !== undefined, // Set currency for gas reporting currency: 'USD', }, // Configuration for Sourcify sourcify: { // Enable Sourcify enabled: true, }, // Configuration for Etherscan integration etherscan: { // API key for Etherscan apiKey: { mode: ETHERSCAN_API_KEY as string, }, // Custom chains configuration for Etherscan customChains: [ // Configuration for ModeTest network in Etherscan { network: 'modetest', chainId: 919, urls: { // API URL for ModeTest network explorer apiURL: 'https://sepolia.explorer.mode.network/api', // Browser URL for ModeTest network explorer browserURL: 'https://sepolia.explorer.mode.network/', }, }, // Configuration for Mode network in Etherscan { network: 'mode', chainId: 34443, urls: { // API URL for Mode network explorer apiURL: 'https://explorer.mode.network/api', // Browser URL for Mode network explorer browserURL: 'https://explorer.mode.network/', }, }, ], }, } export default config
Environment Variables:
Make sure to have your environment variables configured in a .env file:
PRIVATE_KEY=your_private_key INFURA_PROJECT_ID=your_infura_project_id ETHERSCAN_API_KEY=your_etherscan_api_key
Property Descriptions:
Property | Description |
---|---|
networks | Configuration for different Ethereum networks. |
- hardhat | Configuration for local Hardhat network for development and testing. |
- modetest | Configuration for ModeTest network. |
- mode | Configuration for Mode network. |
solidity | Configuration for Solidity compiler. |
gasReporter | Configuration for gas usage reporting during tests. |
sourcify | Configuration for Sourcify to verify contract source. |
etherscan | Configuration for Etherscan integration, including API key and custom chain URLs. |
Conclusion:
With this setup, new builders, even those who consider themselves "very new to the ecosystem," can seamlessly integrate and contribute to development on Mode Network. The detailed configuration and provided examples ensure a straightforward and accessible process for everyone.
Let's tame Mode Network together, step by step, like true builders in this "new" era! 🦖💻
Additional Resources:
Top comments (0)