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.
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.
Initialize an npm project as shown below.
npm init --yes
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
Once installed, run the hardhat project in the same directory and enter the command:
npx hardhat
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.
require("@nomicfoundation/hardhat-toolbox");
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.9",
defaultNetwork: "rangers",
networks: {
hardhat: {
},
rangers: {
url: "https://robin.rangersprotocol.com/api/jsonrpc",
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
https://doc.rangersprotocol.com/network.html
Create a .env file to store your private key . You can follow Export private key
Compile smart contract
npx hardhat compile
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!!
Last modified 9mo ago