New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Verifying Smart Contracts

BaseMon, Oct 9, 2023, 12:00 AM

Verify your deployed smart contract on Etherscan or BscScan, gaining trust from the community and enabling interaction with real money and resources. Also, discover how to set up verification in Hard Hat with ease. Ensure your smart contracts work seamlessly in the real world. 🚀💼 📚 Head to Base Camp for full courses on smart contract development: https://docs.base.org/base-camp/docs/welcome ✅ Subscribe to our channel here: https://www.youtube.com/@BuildonBase ► Build on Base: https://base.org ► Follow us on Twitter: https://twitter.com/buildonbase ► Join our Discord: https://base.org/discord

Transcript

Our contract has been deployed. So, the last thing we need to do is verify it so we can interact with it in Etherscan, BaseScan, or any other block explorer. If we open the contracts tab, we can see that this contract is not verified yet. However, it's worth noting that the system can detect if a contract identical to yours has already been deployed, so it may appear here as verified. So, if you want to try this exercise yourself using a lock contract, all you need to do is go back to the contract and make a small change, like adding a random number.

And this will change the signature when compiled. This will change the bytecode to make it unique. Then when you deploy your contract, you will find that it is not verified. We can verify by clicking on this verification and publication link as you might have done if you were using Remix. But you can also do it directly from the console with Hardhat itself.

The first thing you need to do for that is to set up the configuration. And in the Hardhat configuration for each network, we can add a new item called verify. And since BaseScan is an Etherscan product, we 'll be using Etherscan. And this requires an API URL. We'll take it and paste it to make it easier.

Then we also need an API key. And for Base Goerli, it doesn't actually require a key, but the system expects one, so we can enter something as a placeholder. But keep in mind that when you configure for Goerli or Mumbai or many other test networks , you need to go to Etherscan, create an account, generate an API key, and enter it here. With this addition, we can save our files. And then we just need to run npx hardhat etherscan-verify.

And once again, let the system know that we are using the Goerli Base network. Let's give it a moment to process. And now it's verified. So, we can go back to Base Scan, refresh the page. And now we can see our contract is here.

We can see the code for our contract. One thing to keep in mind is that there is always a bit of balance here. So, in general, the community expects you to have a publicly verified contract before they entrust you with money, NFTs, and other resources. But note that this system still stores your comments in it. So, you may want to do some cleanup before final verification and publication.

But now, we can go in, we can click read contract, and we can read some of the default things. We can see who the owner is and what time it is open. Then in the write contract section, we can connect to web3. We will select our Coinbase wallet. Hm, and keep in mind again that this is often called a beta feature.

This feature is provided as is, and usually that means you may need to refresh the screen or try a few times to get the connection established. Uh, we're still in the early stages, so sometimes you have to put in a little effort to get things going. But we're connected now, and we can see we have the deposit function we added earlier and our withdraw function . So, if we want, we can press the deposit. We can enter the amount to be paid, and we will enter only a small amount.

And write it down. Then confirm our transaction. And as usual, it took a while for the transaction to go through. Okay, this took a while, so I refreshed the screen. The display doesn't always update automatically, but we can see now that the amount of ether in the contract balance has been updated.

So, we now have a contract deployed and running on the testnet that we can interact with.

Automatic transcript — names and jargon may be misspelled.