2. Configure hardhat.config.js

⚠️ Important Security Warning

Do Not Commit Sensitive Information

Accidentally committing sensitive information such as seed phrases can lead to the loss of funds. Always double-check your code and configurations before committing. Use .gitignore files and environment variables to protect sensitive data.

After successfully setting up your Hardhat project, the next step is to configure the hardhat.config.js file. This will be the essential configuration file where you can customize the networks, plugins, compiler settings, and more.

  1. Open the hardhat.config.js file

⚠️Note: Avoid using import "@openzeppelin/hardhat-upgrades"; because this library calls getStorageAt, which will not work if storage is disabled.

For the scope of this tutorial, we will only configure the networks, leaving the solidity compiler at its default version 0.8.19.

  1. Set a variable with your private key

To set the variable, use the following command:

npx hardhat vars set PRIVATE_KEY

After running the command, you will be prompted to enter your private key.

You can read more about setting the configuration variables here.

  1. Setup the Swisstronik's network

require("@nomicfoundation/hardhat-toolbox");
// Remember to use the private key of a testing account
// For better security practices, it's recommended to use npm i dotenv for storing secret variables

//use configuration-variables in hardhat to set PRIVATE_KEY variable
const PRIVATE_KEY = vars.get("PRIVATE_KEY");

module.exports = {
  defaultNetwork: "swisstronik",
  solidity: "0.8.19",
  networks: {
    swisstronik: {
      url: "https://json-rpc.testnet.swisstronik.com/",
      accounts: [`0x` + `${PRIVATE_KEY}`],
    },
  },
};

Last updated