How to Deploy dApps on the Ropsten Testnet

In January 2022, I did a 30-day project on “Why Your Business Needs to Adapt to Blockchain”. This post is a part of it. To know what I covered, learned, and executed in the project, visit this page.

This is the last post of what I call the ‘blog’chain. It is an important one. In this post, I finally move from my local blockchain to a truly decentralized Global blockchain or the Ropsten Testnet. How I moved to the Ropsten Testnet? Read on.

Deployment on the Ropsten Testnet

Ropsten Testnet has the same architecture as the Ethereum Mainnet. But it is a testnet, so we don’t have to pay actual Ethers.

I don’t have any money on my recly-test02 account on the Ropsten Testnet. To deploy the contracts on the testnet, I needed Ethers. Even to get fake Ethers on the Testnet, I needed faucets to send them to me.

So, I submitted my public key to the faucets to get free fake Ethers for testing. Now, had I used the Hardhat account IDs for testing, I would not have got Ethers for testing because everyone has the same public keys, so my Ethers would have been stolen.

So, I selected my recly-test02 account for the testing which was only known to me. I copied its public address.

Next, I searched ropsten faucets on google and pasted my public key on 5-6 search results. Only one worked and I received 0.3 Eth after a while.

Next, unlike the local network where the deploy command was enough to deploy the contract on the blockchain, to deploy the contracts on the global testnet, I needed an endpoint to send a deployment request.

This endpoint acted as my node in pushing the contracts. I used infura.io to create the endpoint. I went to infura.io and created an account using my email id. Once logged in, I clicked on Ethereum from the dropdown and then “CREATE NEW PROJECT”. Infura allows three free projects.

I gave the project a name.

Next, I changed the endpoints to Ropsten → copied the first of the two endpoints

https://ropsten.infura.io/v3/941b12a3f073468087a444d4e5e94440

Next, I went to the Security tab and pasted my recly-tes02 account’s public key under Contract Addresses → Add. This specified the addresses that are allowed to send contracts to this project.

Next, I had to add the Ropsten network in my Hardhat configuration in addition to the hardhat network. So, I went to the Terminal and typed vi hardhat.config.js to edit the file.

I added the ropsten network under the hardhat network. In the url, I pasted the endpoint I had copied earlier. In accounts, I pasted the private key of the recly-test02 account.

I pasted the private key after taking the screenshot as the private key is secret. You can get your private key from your Account details in Metamask.

I saved the configuration and quit the editor. Since the contracts were already compiled, I need not compile them again. I just needed to deploy them by changing the network: npx hardhat run scripts/deploy.js –network ropsten

Being a global network, it took some time to deploy and I had some time to take a screenshot mid-way.

And finally, it was deployed!

This is what my Eth balance looked like in Metamask after deployment:

Now, you can also see that the KB01 token doesn’t show on my assets yet. This is because I need to import the token from the Ropsten Testnet as I did for the local network. To do that, I need to copy the Token contract address shown above and paste it inside the Import tokens option.

And, I just received 1000 KB01 tokens from the global Ropsten testnet. Isn’t it cool? Let me know if you want some in your Metamask account.

Creating a similar token on the Mainnet works the same way. The only two differences are that instead of copying the endpoint of the Ropsten Testnet from infura.io, you need to copy the Mainnet’s endpoint, and you need to spend real Ethers to deploy.

So, this is the end of the ‘blog’chain. I created a Greeter dApp, a Token of my own, and at the end deployed both on the global Ropsten Testnet. 

Take a look at the other articles I wrote during the project here.