Part 3: Publish your Smart Contract to Etherscan
You did all the hard work of bringing your smart contract to life - now it's time to share it with the world!
By verifying your smart contract on Etherscan, anyone can view your source code and interact with your smart contract. Let's get started!
Step 1: Generate an API Key on your Etherscan account
An Etherscan API Key is necessary to verify that you're the owner of the smart contract that you're trying to publish.
If you don't have an Etherscan account, first sign up using this link.
Once logged in, press your username on the top right, and select the "My profile" button:
Once you've followed the steps above, you should be able to view your new API key, which we've highlighted in red below. Copy this API key to your clipboard.
If you were following the Truffle tutorial, your .env file should look like this:
Step 2: HardHat-deployed smart contracts
This is where our steps diverge for HardHat and Truffle deployed smart contracts, as they require different plugins. Skip to the Step 3: Truffle-deployed smart contracts section if you deployed your contract using Truffle.
Step 2.1 Install the hardhat-etherscan plugin
Step 2.2 Verify your smart contract on Etherscan!
Make sure that DEPLOYED_CONTRACT_ADDRESS is the address of your deployed smart contract on the Ropsten test network. Also, the last argument, 'Hello World!' must be the same string value that you used during the deploy step in Part 1.
If all goes well, you should see the following message in your terminal:
Congrats! Your smart contract code should be on Etherescan! Check out Step 4 to see how to view your smart contract code!
Step 3: Truffle-deployed smart contracts
Skip this section if you deployed your smart contract with HardHat.
Step 3.1: Install the truffle-plugin-verify plugin
You're almost at the finish line! 😅
Step 3.2 Verify your smart contract on Etherscan!
Last but not least, run the following command in your terminal:
If all goes well, you should see the following message in your terminal.
Step 4: Check out your smart contract on Etherscan!
When you navigate to the link provided in your terminal, you should be able to see your smart contract code and ABI published on Etherscan!
Wahooo - you did it champ! Now anyone can call or write to your smart contract! We can't wait to see what you build next! 🎉
Once you complete this tutorial, let us know how your experience was or if you have any feedback by tagging us on Twitter @alchemyplatform!