Rootstock Hardhat Ignition Starter Kit
This guide provides a step-by-step approach to deploying smart contracts on the Rootstock using Hardhat Ignition.
While standard Hardhat guides cover general Rootstock development, this guide specifically showcases how Hardhat Ignition can make deployment more efficient by enabling programmatic and declarative approaches tailored for Rootstock.
Hardhat Ignition streamlines smart contract deployment by enabling programmatic definition, testing, and execution of deployment plans. This declarative approach significantly improves efficiency and manageability, making the deployment process smoother and more predictable.
With Ignition, you can easily manage complex deployment workflows, handle dependencies between contracts, and ensure smooth deployment processes.
Donβt worry if youβre new to thisβevery step will be explained in simple terms, making it accessible even if youβre just starting out.
What You'll Learnβ
- Set up a project to deploy smart contracts on Rootstock.
- Understand the project structure.
- Deploy a contract to the Rootstock Testnet using Hardhat Ignition.
What You Need Before Startingβ
-
Node.js
- This is a tool developers use to run JavaScript code.
- Download Node.js here. Install the LTS version (the one marked as βRecommended for Most Usersβ).
-
npm or Yarn
- These are tools that help manage project dependencies (software libraries your project needs to work).
- If you installed Node.js, you already have npm installed. You can check by typing this in your terminal:
npm -v
-
Hardhat
- A tool that helps developers create and test Ethereum-like projects (Rootstock is Ethereum-compatible).
-
Hardhat Ignition
- A plugin that makes deploying smart contracts easier.
-
Rootstock RPC API endpoint
- This is like an access point that connects your computer to the Rootstock blockchain. You can use the Testnet (for testing) or Mainnet (for real transactions).
- If you find the
deployments
andartifacts
folder inside the ignition directory, delete it.
Getting Startedβ
Clone the Repository
Open your terminal (Command Prompt, PowerShell, or any terminal you like) And type this command.
git clone https://github.com/rsksmart/rootstock-hardhat-ignition-starterkit.git
cd rootstock-hardhat-ignition-starterkit
Open this folder in an IDE like Visual Studio Code.
Install Dependenciesβ
In your terminal, run this command:
npm install
This will download and set up everything the project needs.
Understand the Project Structure
Once youβve set up everything, your project files will look like this:
.
βββ contracts # Your smart contracts live here.
βββ ignition
β βββ modules # Deployment scripts for your contracts.
βββ test # Files to test your smart contracts.
βββ package.json # Lists project dependencies (like a grocery list for software).
βββ hardhat.config.ts # Configuration for Hardhat.
βββ README.md # A file explaining your project.
βββ tsconfig.json # Configuration for TypeScript.
Modules Folderβ
The Modules folder contains essential scripts used for the deployment of smart contracts. Specifically, it includes two main files: Box.ts
and Lock.ts
.
-
Box.ts β Box Moduleβ
This script sets up and exports a module that handles the deployment of the Box contract.
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
// Create and configure the BoxModule using Hardhat's Ignition library
const BoxModule = buildModule("BoxModule", (m) => {
// Deploy the Box contract with no initial parameters
const box = m.contract("Box", []);
// Return an object containing the deployed contract
return { box };
});
// Export the module for use in deployment
export default BoxModule;
buildModule
: A function from@nomicfoundation/hardhat-ignition/modules
used to create and configure modules for contract deployment.m.contract
: Deploys a contract with the given name and constructor parameters.