Skip to content

Instantly share code, notes, and snippets.

@nicovalencia
Last active January 24, 2022 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicovalencia/3aa7a414d87efd6abdc955e55eb3e240 to your computer and use it in GitHub Desktop.
Save nicovalencia/3aa7a414d87efd6abdc955e55eb3e240 to your computer and use it in GitHub Desktop.

Polygon <> ETH NFT

Polygon Documentation

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

Simple Explanation

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.

Setup

  1. Create a Polygon token contract with mint deposit and withdraw functions (these allow bridging tokens to Ethereum)
  2. 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)
  3. 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)
  4. Verify both contracts on Etherscan and Polygonscan accordingly
  5. Map contracts using the token mapper: https://mapper.polygon.technology/

Required Interfaces

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);
}

Example Contracts (Full from Polygon)

To test, use Mumbai <> Görli.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment