Deploy a Smart Contract to Polygon zkEVM Testnet

How to deploy a smart contract to the Polygon zkEVM network testnet - thirdweb Guides

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.

Select "Configure Networks" after connecting your wallet

Search for Polygon zkEVM Testnet and select it:

Search for Polygon zkEVM Testnet

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.

Metadata for the Polygon zkEVM Testnet network

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:

Switch network to Polygon zkEVM Testnet

It will prompt you to add the network to your wallet, click on approve and switch network:

Add the Polygon zkEVM network to your wallet

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.

💡
If you don't have Goerli ETH, you can get it free from a Goerli faucet.

Connect your wallet to the zkEVM Bridge application:

Connect your wallet to the zkEVM bridge

And bridge funds from Goerli to the zkEVM test network like so:

Bridge funds from Goerli testnet to zkEVM testnet.

After a few minutes, you'll be able to hit Finalise to complete the bridge!

Ensure you click 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!

thirdweb Explore: Smart Contracts & Protocols
Browse a large collection of ready-to-deploy contracts that have been built by thirdweb and other contract developers. Find a contract for your specific app’s or game’s needs.

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:

Using the CLI, we can set up a simple smart contract project

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:

  1. Compile all the contracts in the current directory.
  2. Allow you to select which contract(s) you want to deploy.
  3. 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:

Populate the parameters of your smart contract constructor
💡
Make sure to select Polygon zkEVM Testnet as the network!

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:

Use the explorer to execute functions on your smart contract.

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!
💡
We won't go into too much detail about this process in this guide, check out our other NFT Drop Guides for more information!

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!

Click the "Claim" button to mint your 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:

Learn how to build a web3 app to interact with your smart contract

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.