89DEVs

Deploy smart contract to Polygon Network

The Solidity programming language is mostly associated with the Ethereum blockchain. The smart contracts written in Solidity, however, can be deployed to any blockchain using the Ethereum Virtual Machine (EVM). Next to the Binance Smart Chain (BSC) and the Avalanche network is the Polygon Network one of the most used blockchains for smart contract developers. 

polygon network logo

Why deploy to Polygon Network?

One of the main advantages of the Polygon Network is its multi-chain ecosystem that offers a bridge between previous and current infrastructure. It is also highly efficient and offers a high transaction throughput of currently 65,000 transactions per second. Another important advantage of the Polygon Network is the cheaper cost of deploying a smart contract.
Just deployed new ERC720 smart-contract on ethereum. Cost $436.
While the gas price on the Ethereum blockchain has been very high, it is much cheaper to deploy to Polygon Network where the costs are usually just cents instead of tens or even hundreds of dollars.

How to deploy to Polygon Network?

The deployment of a smart contract written in Solidity is done in three easy steps:
  1. Configure MetaMask for Polygon Network
  2. Get MATIC funds - Free funds on testnet available!
  3. Deploy smart contract to Polygon Network
If your MetaMask is already set up for the Polygon Network and you have sufficient MATIC funds for deployment you go directly to Step 3:Deploy smart contract to Polygon Network. Please note, that there are the Polygon Mainnet and the Mumbai-Testnet. The first is used to deploy real-world contracts, while the latter is used to test smart contracts with test funds.

Configure MetaMask for Polygon Network

MetaMask is by default only prepared for the Ethereum Network. If we want to use it on other blockchains like BSC or Polygon we have to configure it. This can be done quite easily and Polygon has even a shortcut for it: add polygon to metamask On polygonscan, you can find a small link at the right bottom of the page to add Polygon to MetaMask. Please note, that the main net and the Mumbai testnet have to be added separately. Add Mainnet to MetaMask Add Mumbai Testnet to MetaMask Of course, it is also possible to add both Polygon networks manually. Therefore, go to your MetaMask account, click on the image icon on the right top corner and then click on Settings. add polygon to metamask In the Settings menu, click on Networks to select the network settings. add polygon to metamask Then check if you can see the Polygon networks in the overview and if not click the blue Add Network button. add polygon to metamask

Network Settings for Polygon

To add the Polygon Mainnet and the Polygon Mumbai testnet enter the following details manually. It is recommended to set up both networks, because the Mumbai testnet allows you to test the smart contract before it is deployed to the Mainnet.

Network Settings for Polygon Mainnet

The network settings for the Polygon Mainnet
parameter Mainnet
Network Name Polygon Mainnet
New RPC URL https://polygon-rpc.com
Chain Id 137
Symbol MATIC
Block Explorer URL https://polygonscan.com

Network Settings Polygon Mumbai Testnet

The network settings for the Mumbai testnet
parameter Mumbai Testnet
Network Name Polygon Mumbai Testnet
New RPC URL https://rpc-mumbai.maticvigil.com/
Chain Id 80001
Symbol MATIC
Block Explorer URL https://mumbai.polygonscan.com

Get funds: Free MATIC on Mumbai testnet

Now it's time to get some funds to pay later for the deployment fees. We can acquire free MATIC on the Mumbai testnet by using the Mumbai Faucet - it gives us 1 MATIC every 24 hours. To the faucet, copy the address from MetaMask and paste it to the faucet website. Make sure to select the correct network before copying the address. If everything went well, 1 MATIC will appear in your MetaMask within a few seconds. use matic mumbai faucet To deploy to the Mainnet, it is necessary to buy some MATIC at an exchange.

Deploy contract to Polygon

Finally, we can deploy our smart contract to the Polygon Network. In this tutorial, we will use the Mumbai testnet to demonstrate how an example contract is deployed. It works similarly for the Mainnet. We are also using Remix as a beginner-friendly IDE. In Remix under the Deploy & Run tab, select Injected Web3 as Environment. If MetaMask is already connected with remix nothing will happen, otherwise, you have to confirm the connection as shown in the below screenshot. connect metamask and remix Next, click the Deploy button in Remix. It will take a short moment until the confirmation in MetaMask appears. You will see an estimate of the deployment fee. Now it's time to confirm the deployment and usually, it doesn't take longer than a few seconds until the Solidity smart contract is deployed to the Polygon Network. It is recommended to deploy first to the Mumbai testnet to make sure the contract works as expected. deploy solidity contract to polygon In this tutorial we have deployed the HelloWorld.sol smart contract to Polygon. After the deployment, we can use and test the contract as we would do it in our local environment. To learn more about the Solidity programming language check our Solidity tutorial and our guide on how to Deploy to the Binance Smart Chain. If you are an blockchain developer you might be also interested in our salary guide for solidity developers.

        

Summary

Click to jump to section