Smart Contract Verification And Deploying Using Hardhat
Tags: blockchain, solidity, web3, javascript
Published: 2024-03-27 21:33:39

## 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
```
or 

```
yarn add --dev hardhat
```

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

 Initialize Your Hardhat Project:

- Inside the project folder, initialize Hardhat

```
npx hardhat init
```

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

### Install Necessary Dependencies
 

- Install additional packages for deployment, load environment variables, and verification

```
npm install @nomicfoundation/hardhat-toolbox dotenv
```

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

### 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.
```

![how to deploy hardhat and verify smart contract](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jjvjnudnsegyh645xmkv.png)
### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/02j396b60nfaj0hlz900.png)

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

![how to deploy hardhat and verify smart contract](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ppn7655kchhxpphcepl2.png)
- Set up your hardhat.config.js in the project root.

![how to deploy hardhat and verify smart contract](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2483fcxld5i4av9h67sr.png)
- Deploy the contract to the desired network. For this, We will use Arbitrum Sepolia. Run
```
npx hardhat run scripts/deploy.js --network arbitrum_sepolia
```

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

- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wu8l38ueb9q89a23xpgm.png)

### Verify Your Smart Contract

- To enhance trust, verify the contract

```
npx hardhat verify --constructor-args arguments.js <your-contract-address> --network arbitrum_sepolia
```

![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.