DEV Community

Cover image for Deploy a Smart Contract on Polygon (MATIC)
Avneesh Agarwal for thirdweb

Posted on • Originally published at blog.thirdweb.com

Deploy a Smart Contract on Polygon (MATIC)

This guide will show you how to deploy any smart contract to the Polygon network.

By the end, you'll learn how to create a simple NFT Drop smart contract, deploy it to the Polygon Mumbai testnet, and mint an NFT on the smart contract.

Let's get started!

What is Polygon?

Polygon has exponentially lower (approximately ~10,000x lower) gas fees than Ethereum does, and utilises Proof-of-Stake (POS) consensus, which has a less negative impact on the environment than Proof-of-Work (POW).

Using Polygon is a great choice for all kinds of blockchain projects,especially those that require a lot of interaction with the blockchain; because of its low gas fees.

Brands such as Instagram and Adidas have recently started using Polygon for their projects, adding credibility and a growing audience for the Polygon network.

Create a smart contract on Polygon

To begin, head to the Contracts page in your thirdweb Dashboard and hit "Deploy new contract":

deploy new contract

You will be taken to our Explore page — where you can browse smart contracts built by the top protocols in web3 and deploy them in just a few clicks!

Note: You can also use the thirdweb CLI to set up a smart contract environment by running the below command from your terminal:

This will take you through an easy-to-follow flow of steps for you to create your contract. Learn more about this in our CLI guide.

Otherwise, let's get back to Explore:

thirdweb explore page

Here, select your smart contract of choice. For this guide, we're going to use the NFT Drop (ERC721) contract to create our NFT collection:

thirdweb's NFT Drop Contract

Set up your smart contract with an image, name, description, etc., and configure which wallet address will receive the funds from primary and secondary sales:

Populate metadata of your contract

In the network/chain section select Polygon Mainnet or Polygon Mumbai (testnet) as you wish. For the sake of this guide, I am going to use Polygon Mumbai

Select Polygon Mumbai network

Once you have selected the network, click on deploy now. It will prompt you to switch your network to Mumbai

Switch Wallet to Polygon Mumbai Testnet

Click on the switch Wallet button and if you don't already have the network in your wallet it will prompt you to add the network and then switch to the network:

Switch network to Polygon Mumbai

Now let's deploy the smart contract on the Polygon Mumbai testnet! But before that, we need testnet funds.

Get Mumbai matic in your wallet

Once you have added the Mumbai network to your wallet. You can either navigate there directly or open the Wallet button and hit "Request Testnet Funds" in the thirdweb dashboard:

Click on Request Testnet Funds from the dropdown

This will take you to the Polygon Mumbai faucet. Here, paste your wallet address and hit submit

You will be prompted to review the details and confirm:

Confirm the details of your request

Once you confirm the details, funds will arrive in your wallet:

Request for funds submitted

Once you have completed this process, you will have testnet funds in your wallet on Mumbai testnet, meaning you're now ready to deploy your smart contract!

Deploying the contract

Now that you have your testnet ETH, let's go back to the thirdweb Dashboard where we were building our NFT Drop contract.

We have already filled out the metadata so click on "Deploy Now" after selecting the chain. It will prompt a transaction, you have to approve that.

Confirm the transaction to deploy the contract

And you're done! You have just deployed to the Polygon Mumbai testnet.

Calling Smart Contract Functions

Let's see how we can use the smart contract by calling some functions on it, such as minting an NFT into our collection!

From the Explorer tab, you can view all of the available functions on your smart contract and execute them directly from your connected wallet:

Calling the Read name function from Explorer

Setting Up Our NFT Collection

In our example, we created an NFT drop smart contract, so we'll quickly set it up and mint our first NFT by performing the following steps:

  1. Lazy mint a batch of NFTs.
  2. Configuring our claim conditions.
  3. Mint an NFT from the drop!

Once we've set up our NFTs, we can click the Claim button in the NFTs tab to mint our first NFT, and voilà! We just minted an NFT on the Polygon testnet!

Claimed NFT

What's Next?

Now that you've deployed your smart contract, you can use our SDK to build a web3 application! Where users can connect their wallets and interact with the functions of your smart contracts. Learn more from our guide below:

Wrapping up

In this guide, you've learned how to create a simple NFT Drop smart contract, deploy it to the Polygon Mumbai testnet, and mint an NFT on the smart contract. We hope it was helpful!

If you have any questions jump into the thirdweb Discord and join 32,000+ other builders! And if you're looking to build on Polygon and want to learn more about how to do that with thirdweb's tools, reach out to the team directly. Please let us know if you have any feature requests or guide requests here.

Top comments (0)