Time to read: 1 min
For the complete documentation index, see llms.txt
Shared Setup
This setup guide is shared by multiple Rootstock use-case tutorials. Complete it once, then return to the tutorial you’re following.
Prerequisites
- Node.js 18+
- A wallet (e.g., MetaMask) configured for Rootstock testnet
Project initialization
mkdir rootstock-use-cases
cd rootstock-use-cases
npm init -y
npm install --save-dev hardhat
Install dependencies
npm install --save-dev @nomicfoundation/hardhat-toolbox
npm install @openzeppelin/contracts
npm install dotenv
Hardhat initialization
npx hardhat
If you already have a Hardhat project, you can skip initialization and only install the dependencies you need.
Recommended quickstarts (official)
If you prefer to follow the official Rootstock walkthroughs for Hardhat setup:
Dependencies
Optional: Configure Hardhat Using Ethers v5 (For Compatibility with Some Guides)
Some tutorials use ethers.utils.* in test snippets. If your project uses ethers v6 tooling, those snippets will not match. In that case, install the ethers v5-style dependencies below and configure Hardhat accordingly.
npm install --save-dev hardhat @nomiclabs/hardhat-ethers ethers chai
Your hardhat.config.js should include:
require("@nomiclabs/hardhat-ethers");
module.exports = {
solidity: "0.8.30",
};
Testnet configuration (Rootstock)
Create a .env file (do not commit it):
PRIVATE_KEY=your_testnet_private_key_here
ROOTSTOCK_TESTNET_RPC_URL=https://public-node.testnet.rsk.co
Then add a Rootstock testnet network entry to your Hardhat config.
// hardhat.config.js
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
module.exports = {
solidity: "0.8.30",
networks: {
rootstockTestnet: {
url: process.env.ROOTSTOCK_TESTNET_RPC_URL || "https://public-node.testnet.rsk.co",
chainId: 31,
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
},
},
};