Publish and Verify your Smart Contract for it’s Authenticity on Etherscan
We will learn how to verify our deployed solidity Smart Contract on Etherscan for its Authenticity.
Note: This is the next stage of our previous work where we learnt how to interact with a deploy a Smart Contract on a Blockchain.
Why to Verify our Smart Contract?
It’s always good to publish your smart contract so that it can be verified as a proof of authenticity. The source code of a smart contract or token contract becomes publicly available and verifiable once it has been validated. Through this process transparency and trust are established.
For newbies, Etherscan is a Ethereum block explorer. Any user can access Etherscan to obtain statistics about the Ethereum network. The platform’s prime objective is to present data about the network’s blocks and transactions.
Create Etherscan Account and Generate API Key
For the verification process first of all we need to create an account in Etherscan which can be done using the link. Once our Etherscan account is created then using My Profile link we can navigate to Account Overview screen and select API Keys
Create Etherscan API Key
Creating an Etherscan API key is very simple you have provide an App Name and hit the Create New API Key
button. Voila!!!! it’s done
Make a note of API Key token from the newly created API Key as we will be using it later as a configuration parameter in our project.
Smart Contract Project
Refer to Smart Contract project setup section if you haven’t done the project set-up earlier, as we will go through the configuration files to verify our deployed smart contract. What we have done in our previous stages is checked-out the greetings smart-contract project code from Github into our local directory.
After cloning the project, you will see the project structure as
.env Configuration Updation
We had .env
file created during our contract interaction and deployment process which has our Smart Contract project configurations.
To publish and verify our Smart Contract, we will update our .env
file by adding ETHERSCAN_API_KEY
as an updated configuration. Remember we will use the same API Key that we have noted in our previous step i.e. Create Etherscan API Key right after creating Etherscan Account.
Note: In the previous post section we have done configuration for interacting with our deployed Smart Contracts
With this our .env
file will looks like
Verifying your deployed Smart Contract
Run the command in the CLI to start the source code publishing and verification process
npx hardhat verify CONTRACT_ADDRESS 'Hello and Welcome'
As per our .env
configuration the command will look like below where 0xac2726........672ba6
represents the CONTRACT_ADDRESS
npx hardhat verify 0xac2726........672ba6 'Hello and Welcome'
Note: Change the CONTRACT_ADDRESS
with the mentioned .env
file configuration param value which refers to our deployed Smart Contract address. You can refer to previous post where we have created and deployed a Smart Contract.
Running the above command in CLI will produce output as
Successfully submitted source code for contract
contracts/GreetingMessages.sol:GreetingMessages at 0xac2726........672ba6 for verification on Etherscan.
Waiting for verification result...Successfully verified contract GreetingMessages on Etherscan.
https://goerli.etherscan.io/address/0xac2726........672ba6#code
In your CLI / Terminal screen, copy the verified Smart Contract URL and navigate to the link which will show the Etherscan page having published details for our verified Smart Contract
Yeeeeyyyy….. our Smart Contract is published and verified on Etherscan. Now anyone can have a look at the source code to verify the Authenticity as whether our Smart Contract is really doing what it’s supposed to perform.
Along with this through Etherscan, we can also play with our published Smart Contract as it has Read Contract
and Write Contract
features which acts as an add-on to verify the operations through exposed interfaces.
Congratulations!! We have done it and at the end let’s do some super celebration.
Images Credit: Paramount Pictures and Leonardo DiCaprio.
Glossary:
Ethereum: Ethereum is a decentralized, open-source blockchain with smart contract functionality. From Wikipedia
Etherscan: Etherscan is a service on which any user can view Ethereum network statistics. From Wikipedia
Solidity: Solidity is an object-oriented programming language for implementing smart contracts on blockchain platforms. It’s influenced by C++, JavaScript and Python.
Hardhat: Hardhat is a development environment to compile, deploy, test, and debug Ethereum based softwares.
Other recommended articles
Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing