Hardhat

Hardhat is a powerful Ethereum development environment that supports editing, compiling, deploying, and verifying smart contracts. This guide walks you through deploying smart contracts to the Neura Testnet using Hardhat in a TypeScript project setup.

Tooling Requirements

Before getting started, ensure your system has the following items:

  • Node.js version v24.2.0 or later

  • A modern package manager (npm or yarn)


Project Setup

Follow the steps below to create a TypeScript Hardhat project configured for Neura.

  1. Create and initialize the project:

mkdir neura-hardhat-template
cd neura-hardhat-template
npm init -y
npm install --save-dev hardhat
npx hardhat init
  1. Install required dependencies:

npm install --save-dev @nomicfoundation/hardhat-toolbox
npm install --save-dev @nomicfoundation/hardhat-verify
npm install dotenv

Environment Configuration

Create a .env file in the root directory and add your deployer private key:

PRIVATE_KEY=0xYOUR_PRIVATE_KEY

⚠️ Security Warning:

  • Never commit your .env file to version control. Make sure .env is listed in .gitignore.

  • Do not expose your private key in any frontend or client-side code.

  • Use dedicated accounts and rotate keys regularly for test deployments.


Hardhat Configuration for Neura

Configure hardhat.config.ts with the Neura testnet settings:

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import * as dotenv from "dotenv";

dotenv.config();

const config: HardhatUserConfig = {
  solidity: "0.8.28",
  networks: {
    neura_testnet: {
      url: "https://testnet.rpc.neuraprotocol.io",
      accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
    },
  },
  sourcify: {
    enabled: false,
  },
  etherscan: {
    apiKey: {
      "neura-testnet": "empty",
    },
    customChains: [
      {
        network: "neura-testnet",
        chainId: 267,
        urls: {
          apiURL: "https://testnet-blockscout.infra.neuraprotocol.io/api",
          browserURL: "https://testnet-blockscout.infra.neuraprotocol.io",
        },
      },
    ],
  },
};

export default config;

Example Smart Contract

You can use either of the following sample contracts:

  • contracts/SimpleStorage.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleStorage {
  uint256 public value;

  function set(uint256 _value) public {
    value = _value;
  }
}
  • contracts/Lock.sol (optional) — use this contract for parameterized deployment examples.

Smart Contract Deployment

Supported Deployment Methods:

  • Hardhat scripts (manual)

  • Hardhat Ignition (modular, preferred for parameterized setups)

Deploy to Local Hardhat Node

  1. Start the local node:

npx hardhat node
  1. In a separate terminal, deploy using Hardhat Ignition:

npx hardhat ignition deploy ignition/modules/SimpleStorage.ts

Or deploy manually via a script:

npx hardhat run scripts/deploy.ts

Deploy to Neura Testnet

  • Script-based deployment:

npx hardhat run scripts/deploySimpleStorage.ts --network neura_testnet
  • Ignition-based deployment:

npx hardhat ignition deploy ignition/modules/SimpleStorage.ts --network neura_testnet
npx hardhat ignition deploy ignition/modules/Lock.ts --network neura_testnet
  • Redeploy with a new address:

npx hardhat ignition deploy ignition/modules/SimpleStorage.ts --network neura_testnet --reset
  • Deploy with constructor parameters:

npx hardhat ignition deploy ignition/modules/Lock.ts --network neura_testnet --parameters '{"unlockTime": 1893456000, "lockedAmount": "1000"}'

Deployment Scripts

Deploy Using a Hardhat Script

  1. Create scripts/deploy.ts:

import { ethers } from "hardhat";

async function main() {
  const SimpleStorage = await ethers.getContractFactory("SimpleStorage");
  const storage = await SimpleStorage.deploy();
  await storage.waitForDeployment();
  console.log("SimpleStorage deployed to:", await storage.getAddress());
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
  1. Deploy with the following command:

npx hardhat run scripts/deploy.ts --network neura_testnet

Deploy Using Hardhat Ignition

  1. Create ignition/modules/SimpleStorageModule.ts:

import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";

const SimpleStorageModule = buildModule("SimpleStorageModule", (m) => {
  const storage = m.contract("SimpleStorage");
  return { storage };
});

export default SimpleStorageModule;
  1. Deploy with the following command:

npx hardhat ignition deploy ignition/modules/SimpleStorageModule.ts --network neura_testnet

Testnet Faucet

To deploy contracts on the Neura Testnet, you'll need testnet ANKR tokens for gas.

Claim testnet funds from the faucet:

Neura Testnet Faucet


Deployment Output Examples

Here’s what successful deployments look like using both Hardhat scripts and Hardhat Ignition:

Script-Based Deployment

  • Deployment:

npx hardhat run scripts/deploySimpleStorage.ts --network neura_testnet
  • Output:

SimpleStorage deployed to: 0xdbEADf884418D8466F1f6b1a8334AdBb1F7D57b2

Ignition-Based Deployment

  • Deployment:

npx hardhat ignition deploy ignition/modules/SimpleStorage.ts --network neura_testnet
  • When prompted:

✔ Confirm deploy to network neura_testnet (267)? … yes
  • Output:

[ SimpleStorageModule ] Nothing new to deploy based on previous execution stored in ./ignition/deployments/chain-267

Deployed Addresses

SimpleStorageModule#SimpleStorage - 0x335F0BCE3980813517f5cc30ae779236fcaeD3AA

Last updated