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-projectInitialize Hardhat with the setup wizard:
npx hardhat --inityarn dlx hardhat --initpnpm dlx hardhat --initbun x hardhat --initWhen prompted, select:
- Version: "Hardhat 3 Beta"
- Path: current directory (
.) - Project type: "A minimal Hardhat project"
- 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:
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_KEYyarn hardhat keystore set RISE_PRIVATE_KEYpnpm exec hardhat keystore set RISE_PRIVATE_KEYbun x hardhat keystore set RISE_PRIVATE_KEYThen update your config to use the variable:
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.
- Create a
.envfile:PRIVATE_KEY=your_private_key_here - Install dotenv:
npm install dotenv - Add to the top of your config:
require("dotenv").config(); - 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 contractsCreate 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 compileyarn hardhat compilepnpm exec hardhat compilebun x hardhat compileThis generates artifacts in the artifacts/ directory.