RISE Logo-Light

Get Started

Set up a Hardhat project for RISE development

Hardhat is a flexible and extensible development environment for Ethereum software. It helps you write, test, debug, and deploy your smart contracts with ease.

Prerequisites

  • Node.js v22 or later
  • A package manager like npm, yarn, pnpm, or bun
  • A wallet with testnet ETH from the RISE Faucet

Create a Project

Initialize Hardhat Project

Create a new directory and initialize a Hardhat project:

mkdir my-rise-project
cd my-rise-project

Initialize Hardhat with the setup wizard:

npx hardhat --init
yarn dlx hardhat --init
pnpm dlx hardhat --init
bun x hardhat --init

When prompted, select:

  1. Version: "Hardhat 3 Beta"
  2. Path: current directory (.)
  3. Project type: "A minimal Hardhat project"
  4. Install dependencies: true

This will create a complete project structure with all necessary dependencies.

Configure for RISE

Update your hardhat.config.ts to add the RISE Testnet:

hardhat.config.ts
import hardhatToolboxViemPlugin from "@nomicfoundation/hardhat-toolbox-viem";
import { defineConfig } from "hardhat/config";

export default defineConfig({
  plugins: [hardhatToolboxViemPlugin],
  solidity: {
    version: "0.8.30",
  },
  networks: {
    riseTestnet: {
      type: "http",
      url: "https://testnet.riselabs.xyz",
      accounts: ["<YOUR_PRIVATE_KEY>"],
      chainId: 11155931
    }
  }
});

Never commit private keys directly in config files. In the next step, you'll learn how to use Configuration Variables to keep this secure.

Secure Your Private Key

Use Hardhat's Configuration Variables (keystore) to store your private key securely:

npx hardhat keystore set RISE_PRIVATE_KEY
yarn hardhat keystore set RISE_PRIVATE_KEY
pnpm exec hardhat keystore set RISE_PRIVATE_KEY
bun x hardhat keystore set RISE_PRIVATE_KEY

Then update your config to use the variable:

hardhat.config.ts
import hardhatToolboxViemPlugin from "@nomicfoundation/hardhat-toolbox-viem";
import { configVariable, defineConfig } from "hardhat/config";

export default defineConfig({
  plugins: [hardhatToolboxViemPlugin],
  solidity: {
    version: "0.8.30",
  },
  networks: {
    riseTestnet: {
      type: "http",
      url: "https://testnet.riselabs.xyz",
      accounts: [configVariable("RISE_PRIVATE_KEY")],
      chainId: 11155931
    }
  }
});

Alternative: Using .env files

If you prefer to use a .env file with the dotenv package instead of Hardhat's keystore, you can do so, but this is not recommended as it's less secure. Make sure to never commit your .env file to version control by adding it to .gitignore.

  1. Create a .env file: PRIVATE_KEY=your_private_key_here
  2. Install dotenv: npm install dotenv
  3. Add to the top of your config: require("dotenv").config();
  4. Update accounts: accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : []

Create a Smart Contract

Make sure you're in your Hardhat project's root directory. Then create a contracts directory and add a simple Counter contract:

mkdir contracts

Create contracts/Counter.sol:

contracts/Counter.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.30;

contract Counter {
    uint256 public number;

    function setNumber(uint256 newNumber) public {
        number = newNumber;
    }

    function increment() public {
        number++;
    }
}

Compile the Contract

Compile your contract to verify everything is working:

npx hardhat compile
yarn hardhat compile
pnpm exec hardhat compile
bun x hardhat compile

This generates artifacts in the artifacts/ directory.

Next Steps