Setting Up a Hardhat Development Environment
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`
Configure Hardhat to connect to Maroo Testnet. Open
hardhat.config.ts and add the network entry. Pull your private key from .env (do not commit it).import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import * as dotenv from 'dotenv';
dotenv.config();
const PRIVATE_KEY = process.env.PRIVATE_KEY || "";
const config: HardhatUserConfig = {
solidity: "0.8.22",
networks: {
maroo_testnet: {
url: "https://rpc-testnet.maroo.io",
chainId: 450815, // Mainnet: 815
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
},
};
export default config; Warning: Never commit private keys to Git. Use environment variables (`.env` file). For testnet funds, request from the [faucet](https://faucet.maroo.io) instead of generating a key from a validator.
3. Compile and Deploy
With the configuration in place, compile and deploy. Hardhat's sample project ships a
Lock.sol contract and a deployment script.# Compile the contracts
npx hardhat compile
# Deploy to Maroo Testnet
npx hardhat run scripts/deploy.ts --network maroo_testnet