DEV Community

Cover image for Smart Contract Verification And Deploying Using Hardhat
Muhdsodiq Bolarinwa
Muhdsodiq Bolarinwa

Posted on

Smart Contract Verification And Deploying Using Hardhat

Introduction

Verifying smart contracts on the blockchain is essential for transparency, security, and trust. It allows developers and users to inspect and interact with the smart contract’s source code. In this tutorial, we’ll utilize Hardhat, a powerful development environment for Ethereum.

Prerequisites

  • Node.js installed
  • An Ethereum account with a private key
  • An API key from a service like Etherscan for contract verification

For this tutorial we will be using Arbitrum-Sepolia

Steps

### Create your project directory folder

In your project direct run

npm install --save-dev hardhat
Enter fullscreen mode Exit fullscreen mode

or

yarn add --dev hardhat
Enter fullscreen mode Exit fullscreen mode

how to deploy hardhat and verify smart contract

Initialize Your Hardhat Project:

  • Inside the project folder, initialize Hardhat
npx hardhat init
Enter fullscreen mode Exit fullscreen mode

how to deploy hardhat and verify smart contract

Install Necessary Dependencies

  • Install additional packages for deployment, load environment variables, and verification
npm install @nomicfoundation/hardhat-toolbox dotenv
Enter fullscreen mode Exit fullscreen mode

how to deploy hardhat and verify smart contract

Create an Environment File:

  • Create a .env file in your project root.
  • Add the following variables:
PRIVATE_KEY: Your Ethereum account’s private key.
API_KEY: Your Etherscan API key for contract verification.
Enter fullscreen mode Exit fullscreen mode

how to deploy hardhat and verify smart contract

Deploy Your Smart Contract

  • Choose a smart contract. We'll use the Lock Fund from your Hardhat project.

how to deploy hardhat and verify smart contract

  • Write a deployment script "scripts/deploy.js".

how to deploy hardhat and verify smart contract

  • Set up your hardhat.config.js in the project root.

how to deploy hardhat and verify smart contract

  • Deploy the contract to the desired network. For this, We will use Arbitrum Sepolia. Run
npx hardhat run scripts/deploy.js --network arbitrum_sepolia
Enter fullscreen mode Exit fullscreen mode

how to deploy hardhat and verify smart contract

  • After deployment, an arguments.js file will be created in your root folder, storing the contract constructor arguments.

how to deploy hardhat and verify smart contract

Verify Your Smart Contract

  • To enhance trust, verify the contract
npx hardhat verify --constructor-args arguments.js <your-contract-address> --network arbitrum_sepolia
Enter fullscreen mode Exit fullscreen mode

![how to deploy hardhat and verify smart contract(https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a33yl0ymxrluynfm96uc.png)

Additional Notes:

  • Ensure your private key remains confidential.
  • Regularly review and update your contract as needed.

Remember, thorough verification contributes to the integrity of DApps built on the blockchain.

Top comments (0)