Deploying a Smart Contract

This tutorial explains how to create, compile, deploy, and verify a simple smart contract on the Nero modular chain Testnet using Hardhat.

Hardhat

Hardhat is a toolset that allows you to compile, deploy, test, and verify your smart contracts.

Setting Up Your Workspace

Starting a New Project

  • To initiate a new project, run the following command:

npm init
  • To install Hardhat in your project, run the following command:

npm install --save-dev hardhat
  • To create a Hardhat project by running npx hardhat in your project directory.

  • Then, you will be presented with several options for project creation. Select the appropriate options.

Create Smart Contract

You can create your own smart contract or use the Openzeppelin token smart contract template, and place it in the contracts directory of your project.

Modify Hardhat for NERO

The updates to the <hardhat-config-file> and ./ignition/module/<deploy-file>files should resemble the following example (specific content should be adjusted according to requirements).

You'll need a variables with the following contents:

NERO_TESTNET_PROVIDER_URL=https://testnet.nerochain.io
PRIVATE_KEY=add your own private key
API_KEY=add your own etherscan api key

You'll need a hardhat.config.js and hardhat.config.ts with the following contents:

require("@nomicfoundation/hardhat-toolbox");
require("@nomicfoundation/hardhat-ignition-ethers");
const { vars } =  require("hardhat/config");

const NERO_TESTNET_PROVIDER_URL = vars.get("NERO_TESTNET_PROVIDER_URL");
const PRIVATE_KEY = vars.get("PRIVATE_KEY");


module.exports = {
  solidity: "0.8.24",
  defaultNetwork: "nero_testnet",
  networks: {
    nero_testnet: {
      url: NERO_TESTNET_PROVIDER_URL,
      accounts: [PRIVATE_KEY],
    },  
  },
  etherscan: {
    apiKey: API_KEY,
    customChains: [
      {
        network: "nero_testnet",
        chainId: 6660001,
        urls: {
          apiURL: "https://testnetscan.nerochain.io/api",
          browserURL: "https://testnetscan.nerochain.io",
        },      
      },
    ],
    enabled: true
  },
};

Note:

  • You can obtain test coins from this faucet and refer to this page.

  • For further information on how to add NERO Chain on MetaMask, please refer to this link.

Deploy Smart Contract on Nero Network

  1. Compile the contract by running npx hardhat compilein the terminal.

  2. Run npx hardhat ignition deploy ./ignition/modules/<deploy-file> --network <select-network> in the root of the project directory.

  3. Visit the Testnet Explorer to view the deployed contract.

Congratulations! You have successfully deployed your own Smart Contract.

Conclusion

This tutorial has walked you through creating and deploying a basic smart contract using Hardhat. Although the tutorial used the testnet, you can follow the same process for the mainnet.​​

Last updated