Configure Hardhat

Configure Hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software. It helps developers manage the entire development cycle of their smart contracts. Hardhat is a popular choice for developers who want to build, test, and deploy smart contracts on the Ethereum network.

This guide will walk you through configuring Hardhat to work with Citrea. You will learn how to set up Hardhat to deploy smart contracts on Citrea Devnet.

Hardhat Installation

Before you begin, make sure you have Node.js installed on your machine. If you haven't installed Node.js yet, you can download it from the official website.

To install Hardhat, run the following command in your terminal:

npm install --save-dev hardhat

This command will install Hardhat as a development dependency in your project.

Create a Hardhat Project

To create a new Hardhat project, run the following command in your terminal:

npx hardhat init

Select the default options when prompted. This command will create a new Hardhat project in your current directory.

Configure Hardhat for Citrea

To configure Hardhat for Citrea, you need to update the hardhat.config.js file in your project directory. Open the hardhat.config.js file in your code editor and add the following configuration:

"REST_OF_YOUR_CONFIG_GOES_HERE",
module.exports = {
    "REST_OF_YOUR_CONFIG_GOES_HERE",
    networks: {
        citrea: {
            url: "https://rpc.devnet.citrea.xyz",
            chainId: 62298,
            accounts: ["YOUR_PRIVATE_KEY"],
        },
    },
    "REST_OF_YOUR_CONFIG_GOES_HERE",
};

Replace YOUR_PRIVATE_KEY with your private key. Make sure to keep your private key secure and never share it with anyone. You can obtain a private key from your Citrea Devnet wallet (e.g., Metamask).

Implement Your Smart Contract and Deploy

For the rest of the development process, you can follow the official Hardhat documentation to compile, deploy, test, and debug your smart contracts. You can find more information on the Hardhat website.

Once you have implemented your smart contract, you can deploy it to Citrea Devnet using the following command:

npx hardhat run --network citrea scripts/deploy.js

This command will deploy your smart contract to the Citrea Devnet network. You can interact with your smart contract using the Citrea Devnet explorer or other tools.

Congratulations!

You have successfully configured Hardhat to work with Citrea. You can now start building and deploying smart contracts on Citrea Devnet. If you have any questions or need help, feel free to ask in the Citrea Discord.

Last updated