Docs
  • FlexNet
  • Build on FlexNet
    • Network Information
    • FlexLabs Incubator
    • Network Fees
  • Tools
    • Bridges
    • Block Explorers
    • Faucets
    • Wallets
  • Deploy Your App
    • Hardhat
    • Foundry
    • Remix
Powered by GitBook
On this page
  • Hardhat
  • Creating a Hardhat Project
  • Creating Your Smart Contract
  • Creating Your Configuration File
Export as PDF
  1. Deploy Your App

Hardhat

PreviousWalletsNextFoundry

Last updated 12 days ago

Hardhat

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

  1. Create a directory for your project:

mkdir hardhat && cd hardhat
  1. Initialize the project, which will create a package.json file

npm init -y
  1. Install Hardhat

npm install hardhat
  1. Create a project

npx hardhat
  1. Create an empty hardhat.config.js and install the Ethers plugin to use the Ethers.js library to interact with the network.

npm install @nomiclabs/hardhat-ethers ethers

Creating Your Smart Contract

  1. Create a contracts directory

mkdir contracts && cd contracts
  1. Create your_contract.sol file in contracts directory

touch your_contract.sol

Creating Your Configuration File

Modify the Hardhat configuration file and create a secure file to store your private key in.

  1. Create a secrets.json file to store your private key

touch secrets.json
  1. Add your private key to secrets.json

{  "privateKey": "YOUR-PRIVATE-KEY-HERE"}
  1. Add the file to your project’s .gitignore, and never reveal your private key.

  2. Modify the hardhat.config.js file

    • Import the Ethers.js plugin

    • Import the secrets.json file

    • Inside the module.exports add the FlexNet TestNet network configuration

require('@nomiclabs/hardhat-ethers');
const { privateKey } = require('./secrets.json');
 
module.exports = {
  solidity: "0.8.20",
  defaultNetwork: "flexnet-local",
  networks: {

    // for FlexNet testnet
    "flexnet-testnet": {
      url: "https://rpc-testnet.flexnet.tech",
      accounts: [process.env.PRIVATE_KEY as string]
      gasPrice: 1000000000,
    },
    // for local dev environment
    "flexnet-local": {
      url: "http://localhost:8545",
      accounts: [process.env.PRIVATE_KEY as string],
      gasPrice: 1000000000,
    },
  },
}

Hardhat