Verify & Publish Smart Contracts using POA Network’s Blockscout Block Explorer
In this guide, I will be showing you how to Verify a Smart Contract using POA Network’s Blockscout Block explorer. As of now, Blockscout does NOT offer Ethereum Mainnet on their platform, but is supported by many other EVM Based networks. Some of these networks include, but not limited to: POA Core mainnet & POA Sokol test network, along with POA’s Stablecoin project xDai. You can also use Blockscout for Ethereum Classic & RSK Blockchains to explore the block’s data within these chains. This guide can also be used on other networks whom clone & use Blockscout for their own deployed network, seeing how Blockscout is now offered as an application to install provided by Amazon’s AWS Computing Industry.
Before verifying smart contract.
To follow along with this guide, you will need a smart contract already deployed to a network supported by Blockscout. If you have your deployed only on Ethereum network, you have two options; deploy one on POA’s Sokol test network for the purpose of this guide or use these instructions towards Etherscan as the data will all be the same.
Need a contract to verify?
If you do not have a smart contract deployed to POA’s Sokol network yet, consider following my other guide on ‘Deploying ERC20 Token to POA Network‘ or by watching the YouTube guide on my YouTube Channel. While you are there, hit that Subscribe Button! I’d appreciate it! Also, share to you favorite social media platform to help the cryptoverse grow!
ABI Encoded Constructor Arguments.
There are a few ways to obtain the ABI Encoded Constructor Arguments needed to verify a solidity smart contract. In this guide, we will be using the simplest way I could think that you cannot run into problems. Some compilers or solidity tools end up compiling the bytecode without the arguments, thus needing to add an extra step to your verification process. You will find in this guide, how to eliminate this step to be more direct.
Note software versions.
This guide uses Truffle to handle our smart contract deployment & management. This simplifies our process of handling multiple applications in one, to compile & deploy to an Ethereum network. While we configure our
truffle-config.js we need to make note of a few options provided to us in order to successfully verify & publish our contracts. Always make note of the exact ‘solc‘ compiler version used to compile & whether or not your compiler is using smart contract optimization. If you are using optimization, make sure to note the amount of runs the compiler makes. You may also need to note which version of Ethereum you are using. With all the hard forks and side-chains, this option may need to be researched if the ‘default’ option does not work for you.
Smart contract verification process
Flattening our contract.
If your project has multiple files & includes imports in your main
.sol contract, you will need to flatten your contract to a single file. Flattening a contract will combine all file imports into a single contract in the order needed. We will be using an application called
truffle-flattener to do this for us, but requires an extra step afterwards, read on.
truffle-flattener globally using your favorite node package manager, such as npm || yarn.
npm i -g truffle-flattener
yarn global add truffle-flattener
To run this tool against your current project, run the following command with replacing
HashGuideCoin with the name of your project. Make sure you are inside of your project’s root directory.
truffle-flattener ./contracts/HashGuideCoin.sol > ./contracts/HashGuideCoin_flattened.sol
This will create a new solidity file in the
contracts folder with the complete contract in a single document.
You will need to remove the additional
SPDX-License-Identifier statements within the flattened file in order for verification to be successful
Navigating Blockscout block explorer
On the Blockscout.com website, find the address used to deploy the smart contract or the smart contract address itself & find the transaction used to deploy the contract. Below you can see what block data looks like on Blockscout.com.
First, we need to obtain our ABI Encoded Constructor Arguments needed to verify a smart contract on an Ethereum (EVM) network. There are many ways to obtain these, but for the sake of an easy beginner’s guide, we will be using the deployed data which will never be different seeing how it is deployed to a blockchain and blockchain data cannot change. To do this, click on the Transaction Hash of the transaction used to deploy the smart contract you wish to verify.
For this step in the guide, we will be focusing on our
Raw Input for this transaction. See images below to see how to copy
Raw Input & use that data to obtain our ABI encoded constructor arguments.
In the image above, you can see I have a small chunk of data selected at the end of the
Raw Input I had taken from my transaction data. The Constructor Arguments for each contract deployed, if any, can always be found at the end of the
Raw Input in the contract creation transaction data. The string you are looking for begins with a bunch of 0’s. Copy the string of characters starting from the very first 0 until the end of the last character of the Raw Input. These are your Constructor Arguments needed to verify solidity contracts.
Above, we have our Smart Contract Verification form on Blockscout block explorer. Smart contracts can be verified on numerous networks supplied by POA Network but this information also may be useful as more & more projects will be using Blockscout for their own projects.
Fill out the form with the data retrieved in the respective fields using the flattened contract we created & the bytecode of the ABI Encoded constructor arguments from the transaction used to deploy your smart contracts. If you notice the additional fields concerning the compiler version, evm version & optimization, this is where I mentioned earlier about always taking note of the versions & options used to compile & deploy smart contracts to evm based networks.
If you are just learning to write solidity code, or maybe, you may have used my ERC20 guide to begin your learning experience. In either case, there is a good chance you have not used smart contract libraries for your deployment. This is good. It can get confusing learning too much at once & if you follow my guides, my goal is to keep it simple. We will go over deploy & using smart contract libraries in a different guide, in the future.
After verification process
After your smart contract has been verified, you will notice a difference in the UI on your Blockscout screen. Now you can see a green checkmark next to your code on your Contract Details page. This is a verified checkmark & proves to the people that your code can be trusted. Also, you may now interact with your smart contracts right from the Blockscout UI. You may read your contract’s parameters or write to your smart contract using a web3 wallet such as; metamask or nifty wallet.
See below for examples of verified contract.
Full Video Guide on YouTube
Watch the Full Video Guide on YouTube