testnet
GitHub

Setting Up a Hardhat Development Environment

quickstart beginner

A step-by-step guide to configuring a Hardhat project to compile, test, and deploy smart contracts on the Maroo network.

Prerequisites

  • Node.js (18+)
  • A local Maroo testnet running or access to a public testnet.

1. Initialize a Hardhat Project

Start by creating a new project directory and initializing a sample Hardhat project within it.
mkdir maroo-project
cd maroo-project
npm init -y
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox

npx hardhat
Note: When prompted by `npx hardhat`, choose 'Create a TypeScript project' for the best development experience.

2. Configure `hardhat.config.ts`

Next, you need to configure Hardhat to connect to your Maroo network. Open the hardhat.config.ts file and add a network configuration for your local testnet. You'll also need to import your validator's private key securely.
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

// It's recommended to use a .env file for private keys
// npm install dotenv
import * as dotenv from 'dotenv';
dotenv.config();

const PRIVATE_KEY = process.env.PRIVATE_KEY || "";

const config: HardhatUserConfig = {
  solidity: "0.8.22", // Maroo recommends this version
  networks: {
    maroo_local: {
      url: "http://127.0.0.1:8545", // Default RPC URL for marood
      chainId: 450815, // Maroo Chain ID
      accounts: [PRIVATE_KEY],
    },
  },
};

export default config;
Warning: Never commit private keys to Git. Use environment variables (e.g., via a `.env` file) to manage them securely. You can export your local validator's private key using `marood keys export validator --unarmored-hex`.

3. Compile and Deploy

With the configuration in place, you can now compile and deploy your contracts. Hardhat's sample project comes with a Lock.sol contract and a deployment script. Let's use them.
# Compile the contracts
npx hardhat compile

# Deploy to your local Maroo network
npx hardhat run scripts/deploy.ts --network maroo_local
Source: maroo
ESC
Type to search