Developers Forum for XinFin XDC Network

Cover image for Simplified Efficiency: Deploying and Verifying Smart Contracts on XDC Network using Hardhat and BlocksScan Explorer V2
Vinn
Vinn

Posted on • Updated on

Simplified Efficiency: Deploying and Verifying Smart Contracts on XDC Network using Hardhat and BlocksScan Explorer V2

Deploying and verifying smart contracts on the XDC Mainnet / Apothem Testnet / Devnet using Hardhat offers developers a reliable and efficient way to ensure the functionality and security of their decentralized applications (DApps). This comprehensive guide will walk you through the process, from setting up your environment to deploying and verifying smart contracts seamlessly.

Prerequisites:
Before diving into the deployment and verification process, ensure you have the following prerequisites in place:

  • Git Installed: You need Git installed on your system to clone the repository containing necessary files.
  • Node.js and npm: Ensure you have Node.js and npm (Node Package Manager) installed on your machine to execute commands and manage dependencies.
  • Hardhat Installed: Install Hardhat globally on your system using npm to utilize its powerful features for smart contract development and deployment.

Now, let's proceed with the deployment and verification steps.

Step 1: Clone the Repository
Begin by cloning the repository containing the essential files for deploying and verifying smart contracts on the Apothem testnet or Devnet.

git clone https://github.com/BlocksScan/Hardhat_Contract_Verify
Enter fullscreen mode Exit fullscreen mode

Step 2: Create .env File
After cloning the repository, create a .env file by copying the provided example file.

cp .example.env .env
Enter fullscreen mode Exit fullscreen mode

Step 3: Configure Environment Variables
Edit the .env file and set the following environment variables:

PRIVATE_KEY=your_private_key
Apothem_RPC_URL = https://apothem.xdcrpc.com devnet_RPC_URL=https://devnetstats.apothem.network/devnet 
xdc_RPC_URL= https://rpc.xdcrpc.com 
Enter fullscreen mode Exit fullscreen mode

Replace PRIVATE_KEY with your private key.

Step 4: Install dependencies
To install dependencies,

yarn install
Enter fullscreen mode Exit fullscreen mode

After installing you will be able to see the node_modules folder.

Image description

To deploy your smart contract code on XDC Network, add your contracts - “.sol” files under the “src” folder and deployment script under the “scripts” folder.

Step 5: Compile Smart Contracts
Compile the smart contracts and their types using Hardhat.
npx hardhat compile

Image description

Step 6: Deploy Smart Contracts
Deploying the smart contracts onto the Apothem testnet using the provided deployment scripts.

npx hardhat run --network apothem scripts/ERC20Token_deploy.ts
Enter fullscreen mode Exit fullscreen mode

Image description

Step 7: Verify Deployed Smart Contracts
Finally, verifying the deployed smart contracts on the Apothem testnet.

npx hardhat verify --network apothem <DEPLOYED_SMART_CONTRACT_ADDRESS>
Enter fullscreen mode Exit fullscreen mode

Replace with the address of the deployed smart contract you wish to verify.

Image description

On the explorer you can view the verified contracts, under Verified Contracts page:

Image description

Conclusion:

Congratulations! You have successfully mastered the deployment and verification of smart contracts on the Apothem testnet using Hardhat. By following these steps, you can ensure the integrity and security of your decentralized applications, providing a seamless experience for your users.

Now, leverage your newfound knowledge to build innovative DApps and contribute to the thriving ecosystem of decentralized finance (DeFi) and blockchain technology.

Discussion (0)