Why And How To Verify Smart Contracts

FacebooktwitterredditlinkedinmailFacebooktwitterredditlinkedinmail

A Few Reasons For Why You Should Verify Your Smart Contracts

There are several reasons why you might want to verify contracts you have deployed, and here are a few examples.

  • It lets you (and others) interact with the contract directly in the blockchain explorer.
  • Anyone is able to view the code of the contract.
  • It’s a sign of transparency on your part.
  • No one will purposely interact with an unverified contract unless they are looking to be scammed.
Verify smart contracts for transparency
Verify for transparency

With that said it’s also important to point out that just because a contract is verified, it doesn’t mean you can trust it! However, it is easier to expose a scam contract that is verified since the code is public.

Compared
Difference between the two in the blockchain explorer

Verifying Simple Contracts

Often when you want to verify a contract it isn’t that complicated, and all you need to do is fill in which compiler and license you have used as well as your source code. But sometimes the blockchain can’t figure out the constructor arguments, in which cases you have to provide the correct ones manually.

Constructor argument

The constructor arguments provides various types of information about the contract and token in the “contract” tab in the blockchain explorer. This is how to figure out the code you need to provide, in case it’s not filled out correctly when verifying your contact.

The first thing you need to do is go to the tx hash where the contract was made, choose “click to see more” and then check the textbox that says “input data”.

input data

Next thing is to go the actual address of the contract (preferably by opening a new tab), press “contract” to see the ByteCode of the contract.

bytecode

Now you need to compare the end of the two pieces of code and find where they start to differ from each other (it’s usually pretty far down towards the end). In the example above the last match of the two codes is “7373”.

Next, you copy the code from the tx hash page that comes after the last matching numbers in the two codes.

constructor code

Now go back to the address of the contract, and under the “contract” tab click “verify and publish”. You will be asked to pick which compiler type (single or multi-file) you used, the version you used (which you can find in Remix if you used that) as well as the type of license (if any).

After you have clicked “continue”, you will find yourself on a new page which asks you to provide the source contract as well as the ABI-encoded constructor arguments.

Source code

Paste your source code in the top textbox, and then replace the code in the bottom textbox with the one you copied from the tx hash page.

It will look something like this.

abi encoded

Now all you have to do is solve the reCAPTCHA and click “verify and publish”.

You will get a message saying that ByteCode and ABI have successfully been generated for your contract.

verified contract
Your contract is now verified!

Verifying Advanced Contracts

Some contracts are made up of several different contracts, which makes them a bit more complicated to verify. For this, I will use the contract used in a previous post about Mint On Demand.

Now, this contract is actually three different contracts in one code. It has the actual Token, the sales contract and the deployer contract. Trying to verify any of these contracts by just copying the code from Remix will not work.

To verify these contracts, you have to split the code up, so each of the contracts has a fully functional and complete code. Something to think about is that you might have to use some code in each and every contract, and not just pick out part of it.

To verify the coin itself (which can be found at Bscscan) you have to pick out all the code that is used when creating the coin and leave out the code that’s not relevant to the specific creation of the coin.

The code just for the Token contract (and for this purpose, the ABI code) can be found here:

GitHub

You can find the code for verifying the sales contract (and the ABI code) here:

GitHub

And finally, the code for verifying the salesDeployer can be found here:

GitHub

Note that there is no real reason for verifying the deployer contract as it will only show the address of the token and the wallet receiving the funds, information that is already provided in the other contracts.


Promoted Exchanges

Note: Investing and trading with cryptocurrencies can result in significant loss

Binance and Crypto.com offer everything you need, along with a $20 welcome bonus.

freebtc

BitPanda is the easiest cryptotrading platform, and perfect for the beginner.

ExpressVPN is the fastest and most secure on the market. Try it for FREE for 30 days!

youtubeinstagramyoutubeinstagram

FacebooktwitterredditlinkedinmailFacebooktwitterredditlinkedinmail