Deploy a Smart Contract to Polygon zkEVM Testnet
This guide will show you how to deploy any smart contract to Polygon's zkEVM testnet, a zero-knowledge-rollup built on top of the Ethereum Mainnet.
By the end, you'll learn how to create a simple NFT collection smart contract using Solidity, deploy it to the Polygon zkEVM network, and mint an NFT on the smart contract!
Let's get started!
What is Polygon zkEVM?
Polygon zkEVM is a layer two network built to address the scalability issues of the Ethereum main net, such as the transactions per second and gas fees.
The "EVM" is the Ethereum Virtual Machine; responsible for storing the state, transactions, and smart contracts of the Ethereum network. "ZK" refers to the fact that it is a zero-knowledge roll-up, meaning it creates bundles or "rolls up" batches of transactions together and executes them off-chain (i.e., not on the EVM).
Zero-knowledge proofs can cryptographically prove the result of these transactions occurring with a validity proof sent to finalize transactions on the blockchain.
Configuring Polygon zkEVM
To deploy to Polygon zkEVM, we first need to add it as a network to the dashboard from our wallet. To do this, connect your wallet and click the ˅
icon. From the menu that opens up, select Configure Networks
.
Search for Polygon zkEVM Testnet and select it:
It will now auto-fill all the details required. You can upload an icon for the Testnet if you like and use a custom RPC you can use that as well.
Click on add network and it will ask you to reload the page when you try to close the modal so that the network can be set up.
Now, click on the network dropdown and select Polygon zkEVM testnet:
It will prompt you to add the network to your wallet, click on approve and switch network:
Now that the network is configured, head to the Polygon zkEVM Bridge.
Next, we need to set our wallet up with some test funds on the zkEVM test network. To do this, we can bridge funds from the Ethereum Goerli test network to zkEVM.
Connect your wallet to the zkEVM Bridge application:
And bridge funds from Goerli to the zkEVM test network like so:
After a few minutes, you'll be able to hit Finalise
to complete the bridge!
Once you have completed this process, you will have the funds that you bridged in your wallet on the zkEVM network, meaning we're ready to deploy our smart contracts!
Creating A Smart contract
In this guide, we will write a simple NFT collection smart contract in Solidity with the help of ContractKit and Deploy.
If you prefer, you can head to our Explore page and browse smart contracts built by the top protocols in web3 and deploy them to the zkEVM testnet in just a few clicks!
Creating An NFT Collection Smart Contract
To get started, we'll use the CLI to set up a smart contract environment by running the below command from your terminal:
npx thirdweb create contract
This command will kick off a series of interactive questions about how you want to set up your smart contract. I am going to create an NFTDrop
smart contract in this example:
Deploying Your Smart Contract to Polygon zkEVM Testnet
Once your project is created, change directories into the new project and use Deploy to begin the deployment process.
npx thirdweb deploy
Running this command performs the following steps:
- Compile all the contracts in the current directory.
- Allow you to select which contract(s) you want to deploy.
- Uploads your contract source code (ABI) to IPFS.
Finally, it provides a URL to open the deployment flow in the dashboard.
Opening this URL will take you to a page where you can populate the parameters of your smart contracts constructor and deploy it to any EVM-compatible network.
You need to provide values for each of the required fields of your smart contract constructor:
Finally, click the Deploy Now
button and approve the transaction! Once the transaction goes through, you can use it just like any other smart contract!
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 fr0m your connected wallet:
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:
- Lazy mint a batch of NFTs.
- Configuring our claim conditions.
- 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 Polygon zkEVM!
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
The Polygon zkEVM is a powerful and exciting technology that improves Ethereum's scalability with a combination of zero-knowledge cryptography and off-chain batching of transaction execution.
With thirdweb, you can seamlessly deploy smart contracts to any EVM-compatible chain, including layer two rollups such as zkEVM. In this guide, we've shown you a simple example of how you can deploy an NFT collection smart contract!
Need help?
For support, join the official thirdweb Discord server or share your thoughts on our feedback board.