Polygon's getting started flows outline how to create a Polygon contract that allows for bridging tokens (ERC-20/721/1155) FROM Ethereum TO Polygon. Typically, what we really want is to create a token that's mintable on Polygon first, then allows the owner to bridge the token to Ethereum. This is called the Mintable Assets flow, and is what we will outline below. Read more about the high level documentation here: https://docs.polygon.technology/docs/develop/ethereum-polygon/mintable-assets
With the Polygon Mintable (or "Mintable Assets") flow, tokens are minted the Polygon contract first.
A separate token contract is deployed to both Polygon and Ethereum, and is mostly the same, except for a couple modified functions that allow withdraw/deposit/burn/mint to bridge tokens between the two networks.
When a token wants to be transfered from Polygon to Ethereum, it is burned with the withdraw
method on the Polygon contract. The bridge flow detects the burn event, and once sync'd, will allow the bridge to mint the token on Ethereum within the Ethereum contract.
When a token wants to be trasfered from Ethereum to Polygon, it is approved/locked in the bridge flow (Predicate), and once sync'd, the Child Manager will call the deposit
method on the Polygon contract, minting the token on Polygon.
- Create a Polygon token contract with
mint
deposit
andwithdraw
functions (these allow bridging tokens to Ethereum) - Assign a depositor role to the Child Manager contract on the Polygon side (this allows the bridge/sync flow to burn and mint tokens on Polygon when they are transfered to/from Ethereum)
- Create an Ethereum token contract with a
mint
function with a mint role for Predicate (this allows the bridge/sync flow to mint tokens on Ethereum when they are transfered from Polygon) - Verify both contracts on Etherscan and Polygonscan accordingly
- Map contracts using the token mapper: https://mapper.polygon.technology/
Polygon (child) contract must implement IChildToken interface:
interface IChildToken {
function deposit(address user, bytes calldata depositData) external;
}
Ethereum (root) contract must implement IMintableERC721 interface:
interface IMintableERC721 is IERC721 {
function mint(address user, uint256 tokenId) external;
function mint(address user, uint256 tokenId, bytes calldata metaData) external;
function exists(uint256 tokenId) external view returns (bool);
}
To test, use Mumbai <> Görli.