DEV Community

Prabhat1308
Prabhat1308

Posted on

Deploying a smart contract on POLYGON using Thirdweb's any EVM , any Contract feature

Deploying a contract to any EVM compatible blockchain has been tough for the newcomers all along . With this blog I will share with you how to easily deploy a contract on any EVM compatible chain using ThirdWeb's new feature.

Creating a contract

First I created a minimal and simple solidity contract on Remix and then deployed it on Ethereum Goerli Testnet.Below is the code for the contract

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

import "hardhat/console.sol";

contract Owner {

    address private owner;

    event OwnerSet(address indexed oldOwner, address indexed newOwner);
    modifier isOwner() {
        require(msg.sender == owner, "Caller is not owner");
        _;
    }
    constructor() {
        console.log("Owner contract deployed by:", msg.sender);
        owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor
        emit OwnerSet(address(0), owner);
    }

    function changeOwner(address newOwner) public isOwner {
        emit OwnerSet(owner, newOwner);
        owner = newOwner;
    }

    function getOwner() external view returns (address) {
        return owner;
    }
} 
Enter fullscreen mode Exit fullscreen mode

Accessing The Dashboard

Then I get the address of my deployed contract from Remix and put it in the dashboard of ThirdWeb for the search contract on top left side of the dashboard.
Here is how the dashboard looks.
ThirdWeb Dashboard
When you enter the address of the deployed contract it shows you in which chain it is deployed. Select it and after sometime you will be redirected to your deployed contracts Overview page.
The deployed address and its chain being shown
This is how the Overview page of your contract will look like.
Overview page
You can see my contract at this link Deployed contract on goerli testnet
You can see that it shows my contract address , recent events and extensions if any. But the real deal are the options which you can see on your left.
For the scope of this article , I will only focus on the build option provided.

Deploying on Polygon mumbai testnet

On clicking the build option you will be shown with the following interface. You can select which SDK you would want based on which language or framework you are working on be it REACT, JAVASCRIPT,PYTHON or GO. It also has unity SDK for game development. For more info you can see ThirdWeb Docs

Build option
Now to enable the ThirdWeb framework to do its magic you need to download the ThirdWeb dependencies.For that you need to go to your project directory and write the following command on your command prompt/shell/terminal.

npm install @thirdweb-dev/sdk ethers@5

Note:ignore any warnings that pops up on your screen . Those will hardly affect your project.

If you are using hardhat for your project ,you need to change your deploy.js file . This is how my deploy.js looked like

const hre = require("hardhat");

import { ThirdwebSDK } from "@thirdweb-dev/sdk/evm";

const sdk = new ThirdwebSDK("goerli");
const contract = await sdk.getContract(
  "0xEBd012bF2F29ea06fc816759E9c4df2A64993f96"
);

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Enter fullscreen mode Exit fullscreen mode

If you have reached this step , then you are almost ready to see the magic of ThirdWeb unveil in front of You.
To deploy the contract you need to use the following command

Note that we have not specified to which network we are deploying the contract to yet.

npx thirdweb deploy

After you write this , you will see this screen on your terminal.

VS code terminal

ThirdWeb not displaying properly! Scope for improvement ;)

You can now witness the true magic of ThirdWeb three framework! It automatically detects the project type , automatically detects the deployed contract, compiles it and gives us a link to deploy the contract.
But the catch is We dont have to do any changes to deploy to any EVM compatible chain.ThirdWeb takes that burden on itself and leaves us devs only to select where we have to deploy it to. On clicking the link provided we get to the following page.
mumbai deployment
We can select from as many as 700 chains to deploy to. Here I have selected to deploy it to mumbai testnet . You can find the other chains supported from this announcement article by ThirdWeb.
Announcement blog
Now you are left with only to sign the transaction to deploy and adding the contract to dashboard.

Here you can see now that my Owner contract is successfully deployed on polygon and goerli!

successful deployment
Mission Complete !
Keep Buidling frens!

Experience with ThirdWeb

Building with ThirdWeb was a very smooth and the docs are really well maintained. However the build instruction page can be made more beginner friendly as after the framework grows popularity , the new web3 builders will prefer to build with ThirdWeb framework , however as they are not yet experienced , they might find it difficult to determine where in their project do they have to make the specified changes. Maybe specific instructions for hardhat and foundry can be put on the the build page.

Also I am not sure as to how ThirdWeb will handle the deployment where a project might contain multiple contracts . Maybe a tutorial on how to do that would be great to make advanced projects using ThirdWeb framework for the people. The CLI interface is really good and i could not find any scope for improvement in it as it is really well made.I look forward to this as i start building great dapps using this framework.

Top comments (0)