haidarali.eth

Deploy smart contract on Energi network

Sun Aug 17 2025

In this blog post, we will learn how to deploy a smart contract on the Energi blockchain.

What is Energi ?

Energi is an EVM-compatible blockchain with a built-in governance mechanism at the protocol level, which makes the network secure. You can learn more about Energi on their official website.

Energi works like any other EVM blockchain—just more secure. You can deploy any smart contract that you would normally deploy on Ethereum, Polygon, Arbitrum, etc.

Prerequisites

To follow along with this blog, make sure you already have the following tools installed and set up:

Initialize Hardhat Project

Let’s initialize a Hardhat project where we will keep our deployment scripts, smart contracts, and all related files.

Run the following command in your terminal or command prompt:

bash
npx hardhat --init

Press Enter for every question asked in the terminal. It will install all the dependencies required for the project.

Once installed, open your IDE and you will see a folder structure like this:

Post

Configure Energi

Now let’s configure the network settings for Energi Mainnet and Energi Testnet.

Add the following code to your hardhat.config.js:hardhat.config.js

javascript
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
require("@nomicfoundation/hardhat-chai-matchers");

module.exports = {
  solidity: {
    compilers: [
      {
        version: "0.8.28",
        settings: {
          optimizer: {
            enabled: true,
            runs: 200,
          },
          evmVersion: "istanbul",
        },
      },
    ],
  },
  networks: {
    development: {
      url: "http://127.0.0.1:7545",
    },
    energiMainnet: {
      chainId: 39797,
      url: "https://nodeapi.energi.network",
      gas: 30000000,
      gasPrice: 20000000000, // 20 GWei
      accounts: [process.env.WALLET_PRIVATE_KEY],
    },
    energiTestnet: {
      chainId: 49797,
      url: "https://nodeapi.test.energi.network",
      gas: 1000000,
      gasPrice: 20000000000, // 20 GWei
      accounts: [process.env.WALLET_PRIVATE_KEY],
    },
  },
  etherscan: {
    apiKey: {
      energiTestnet: "xxxxx-no-api-key-needed-xxxxx",
      energiMainnet: "xxxxx-no-api-key-needed-xxxxx",
    },
    customChains: [
      {
        network: "energiMainnet",
        chainId: 39797,
        urls: {
          apiURL: "https://explorer.energi.network/api",
          browserURL: "https://explorer.energi.network",
        },
      },
      {
        network: "energiTestnet",
        chainId: 49797,
        urls: {
          apiURL: "https://explorer.test.energi.network/api",
          browserURL: "https://explorer.test.energi.network",
        },
      },
    ],
  },
  mocha: {
    useColors: true,
  },
};

Next, set up your deployer private key. Add it to a .env file in the root directory:

bash
WALLET_PRIVATE_KEY='YOUR_PRIVATE_KEY'

Compile the Smart Contract

We will use the default smart contract that comes with the repo. Here it is:

solidity
 // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

// Uncomment this line to use console.log
// import "hardhat/console.sol";

contract Lock {
  uint public unlockTime;
  address payable public owner;

  event Withdrawal(uint amount, uint when);

  constructor(uint _unlockTime) payable {
    require(
      block.timestamp < _unlockTime,
      "Unlock time should be in the future"
    );

    unlockTime = _unlockTime;
    owner = payable(msg.sender);
  }

  function withdraw() public {
    // Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
    // console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);

    require(block.timestamp >= unlockTime, "You can't withdraw yet");
    require(msg.sender == owner, "You aren't the owner");

    emit Withdrawal(address(this).balance, block.timestamp);

    owner.transfer(address(this).balance);
  }
}

Now compile this smart contract by running:

bash
npx hardhat compile

Deploy the Smart Contract

Create a scripts folder in the root directory and add a file named deploy.js with the following script:

javascript
const { ethers, network } = require("hardhat");

async function main() {
  const latestBlock = await ethers.provider.getBlock("latest");

  const lock = await ethers.deployContract(
    "Lock",
    [latestBlock.timestamp + 1000], // Pass the unlock time as an argument
    {
      gasLimit: "0x1000000",
    }
  );

  await lock.waitForDeployment();

  console.log(`Lock deployed to ${lock.target} on ${network.name}`);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Now execute this command in your terminal:

bash
npx hardhat run scripts/deploy.js --network energiTestnet

This will deploy your smart contract on the Energi Testnet and output the contract address in the terminal.

Example output:

bash
Lock deployed to 0x72a59883804004B0F3dD4BE56a7A901c4b438FE4 on energiTestnet

You can view your deployed contract on the Energi Testnet Explorer.
Here’s the deployed example: Lock.sol.

Conclusion

That’s it! You have successfully deployed your smart contract on the Energi network. For the mainnet, simply replace energiTestnet with energiMainnet in your deployment command.