Verify Smart Contracts
Last updated
Was this helpful?
Last updated
Was this helpful?
Smart contracts aim to be trustless, requiring users to trust the contract execution without depending on third parties. This is ensured through source code verification, allowing users to confirm that some source code matches the code executed on the IoTeX blockchain.
Source code verification differs from formal verification, which checks if the contract behaves as intended. Typically, "contract verification" refers to the former, focusing on the match between high-level source code and the blockchain's bytecode.
If you are the contract owner and would like to verify your contract using a UI, please go to the following page and follow the requested steps:
Follow the guide below to verify multiple contracts using Hardhat:
In this tutorial, we will guide you through the entire process of verifying a smart contract using . Starting with contract creation, we'll then deploy it to the IoTeX testnet, and conclude by verifying the contract through .
Or you can refer this repository
Install NodeJS: Ensure NodeJS is installed on your system.
Install Hardhat: Execute the following command to install Hardhat:
Initialize a Hardhat Project: To start a new Hardhat project, run:
For further details on creating smart contracts with Hardhat, refer to the official tutorial.
Create the Contract File: Inside your Hardhat project directory, navigate to the contracts
subfolder and create a file named greeter.sol
. Insert the following code:
Install OpenZeppelin Contracts: Run the following command to include the OpenZeppelin contracts package:
Compile Your Contract: Compile the smart contract with:
Setup IoTeX Testnet Account: Ensure you have a developer account on the IoTeX testnet with a balance of test IOTX tokens. Visit the IoTeX documentation for instructions on account creation and funding.
Configure Hardhat: Modify hardhat.config.js
to add the IoTeX network configurations, including your IoTeX Developer account private key:
Deploy Script: Edit scripts/deploy.js
with the following code to deploy your contract:
Deploy the Contract: Deploy your contract to the IoTeX testnet by running:
Note the contract address provided in the deployment log.
Install hardhat-verify Plugin: To enable contract verification, install the hardhat-verify plugin:
Update Hardhat Configuration: Edit hardhat.config.js
by adding the configuration for contract verification, make sure you use your API key:
Verify the Contract: Execute the following command, replacing <address>
with your contract's address:
Upon successful execution, you'll receive a link to your contract's verified code on IoTeXscan.