As Goerli & Mumbai testnets have been deprecated, this guide is for historical reference.
The Polygon mainnet is an L2 commit chain to the Ethereum mainnet.Bridging your existing Ethereum smart contract to the Polygon commit chain allows network users to move their assets based on your contract between an Ethereum network and a Polygon commit chain.In this tutorial, you will:
Deploy an ERC-20 smart contract on the Ethereum Goerli testnet.
Deploy a compatible smart contract on the Polygon Mumbai testnet.
Map the Ethereum smart contract to the Polygon smart contract.
Verify your root Ethereum ERC-20 contract on Etherscan
Once your contract is deployed, you can view it online at Etherscan.Before you submit a mapping request to bridge your root Ethereum ERC-20 contract to the Polygon commit chain, you must verify the contract on Etherscan.
Flatten your contract codeSince your ERC-20 contract uses imported OpenZeppelin libraries, you must put all the imports into one .sol file to make Etherscan be able to verify it.Install Truffle Flattener.In the contracts directory, run:
Clean up the licensing information.The flattened contract will have the same licensing note imported from each of the files. Multiple licensing notes in one file break the Etherscan verification, so you have to leave one licensing note for the entirety of the flattened contract.The easiest way to clean up is to search for the SPDX mentions in the file and remove all of them except for the very first one.
Verify the deployed contract on Etherscan.At this point, you have your flattened and cleaned-up contract ready for the Etherscan verification.
Find your deployed contract. The address of your contract should have been printed by Truffle at the end of the deployment in the contract address field.
On the contract page on Etherscan, click Contract > Verify and Publish.
In Compiler Type, select Solidity (Single file).
In Compiler Version, select v0.8.1. This is the version this tutorial used to compile the contract.
In Open Source License Type, select MIT License (MIT).
Click Continue.
Keep the Optimization option set to No as Truffle does not use optimization by default.
Paste the entirety of your flattened .sol contract in the Enter the Solidity Contract Code below field.
Click Verify and Publish.Etherscan will take a few seconds to compile your contract, verify, and publish it.
0x2e5e27d50EFa501D90Ad3638ff8441a0C0C0d75e — the ChildChainmanager address on the Polygon Mumbai testnet. For the ChildChainManager contract addresses, look online for the addresses provided by Polygon:
network_id — the network ID of the Polygon network: testnet is 80001, mainnet is 137.
solc — the Solidity compiler version that Truffle must use. OpenZeppelin contracts have a higher version Solidity compiler requirement than the default Truffle installation, hence you must provide a specific compiler version.
Find your deployed contract. The address of your contract should have been printed by Truffle at the end of the deployment in the contract address field.
On the contract page on the explorer, click Contract > Verify and Publish.
In Compiler Type, select Solidity (Single file).
In Compiler Version, select v0.6.6. This is the compiler version the default child contract uses as provided by Polygon.
In Open Source License Type, select MIT License (MIT).
Click Continue.
Keep the Optimization option set to No as Truffle does not use optimization by default.
Paste the entirety of your ChildERC20.sol contract in the Enter the Solidity Contract Code below field.
This tutorial guided you through the basics of bridging an ERC-20 contract from the Ethereum Goerli testnet to the Polygon Mumbai testnet.The same instructions will work for the Ethereum mainnet and the Polygon mainnet.Polygon has public L2 contract templates and a network of deployed contracts monitored by Heimdall nodes, all of which make it easy to bridge assets from the Ethereum mainnet to the Polygon commit chain.