Using Hardhat

Hardhat is an Ethereum development environment. It could interact with Ethereum's API and then deploy smart contracts into the Rangers Protocol. The following content introduces how to configure hardhat on your device, and how to compile and deploy smart contracts.

Install hardhat

Note: If you are a Windows user, it is highly recommended to use the Windows Subsystem for Linux (as known as WSL2) for a better operating experience.
The following tutorial is based on Ubuntu and guides you through the process of successfully setting up a hardhat project and deploying smart contracts on Rangers Protocol.
Using hardhat to access Rangers Protocol is also a good option. Before installing hardhat, Make sure you have git and node.js installed. Otherwise follow this instruction.
  • Git
  • Node.js
Once you have these fundamental applications installed, create a new folder that is the running space for the Hardhat project.

Step 1

Initialize an npm project as shown below.
npm init --yes

Step 2

In the terminal, go to the new folder and use the npm package manager to install hardhat, enter the command:
npm install --save-dev hardhat

Step 3

Once installed, run the hardhat project in the same directory and enter the command:
npx hardhat

Step 4

After opening “hardhat.config.js”, copy the following code to update “hardhat.config.js”, they will allow you to interact with Rangers Protocol and test your contract.
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.9",
defaultNetwork: "rangers",
networks: {
hardhat: {
rangers: {
url: "",
accounts: [process.env.PRIVATE_KEY]
paths: {
sources: "./contracts",
tests: "./test",
cache: "./cache",
artifacts: "./artifacts"
Note:Please choose the appropriate solidity version. You could attain more information about Rangers network configuration on

Step 5

Create a .env file to store your private key . You can follow Export private key

Step 6

Compile smart contract
npx hardhat compile

Step 7

Deploy smart contract
npx hardhat run scripts/sample-script.js —network rangers
You can check Rangers scan later to verify if your contract is successfully deployed on Rangers protocol.
Congratulations on completing your first hardhat deployment of a smart contract!!