Hardhat
Hardhat (opens in a new tab) is an Ethereum development environment. Compile your contracts and run them on a development network. Get Solidity stack traces, console.log and more.
You can use Hardhat to edit, compile, debug, and deploy your smart contracts to Mint.
Creating a Hardhat Project
- Create a directory for your project:
mkdir hardhat && cd hardhat- Initialize the project, which will create a
package.jsonfile
npm init -y- Install Hardhat
npm install hardhat- Create a project
npx hardhat- Create an empty
hardhat.config.jsand install the Ethers plugin to use the Ethers.js library to interact with the network.
npm install @nomiclabs/hardhat-ethers ethersCreating Your Smart Contract
- Create a
contractsdirectory
mkdir contracts && cd contracts- Create
your_contract.solfile incontractsdirectory
touch your_contract.solCreating Your Configuration File
Modify the Hardhat configuration file and create a secure file to store your private key in.
- Create a
secrets.jsonfile to store your private key
touch secrets.json- Add your private key to
secrets.json
{
"privateKey": "YOUR-PRIVATE-KEY-HERE"
}-
Add the file to your project’s
.gitignore, and never reveal your private key. -
Modify the
hardhat.config.jsfile- Import the Ethers.js plugin
- Import the
secrets.jsonfile - Inside the
module.exportsadd the Mint network configuration
require('@nomiclabs/hardhat-ethers');
const { privateKey } = require('./secrets.json');
module.exports = {
solidity: "0.8.20",
defaultNetwork: "mint-local",
networks: {
// for mainnet
"mint-mainnet": {
url: "https://rpc.mintchain.io",
accounts: [process.env.PRIVATE_KEY as string],
gasPrice: 1000000000,
},
// for Sepolia testnet
"mint-sepolia": {
url: "https://sepolia-testnet-rpc.mintchain.io",
accounts: [process.env.PRIVATE_KEY as string]
gasPrice: 1000000000,
},
// for local dev environment
"mint-local": {
url: "http://localhost:8545",
accounts: [process.env.PRIVATE_KEY as string],
gasPrice: 1000000000,
},
},
}