An ERC721 token bridge contract built on top of Teleporter to support bridging any ERC721 tokens between any subnet-evm
instance.
The generic ERC721 bridge is implemented using two primary contracts.
BridgeNFT
- A simple extension of OpenZeppelin's
ERC721
contract. - Representation of an ERC721 token from another chain.
- Identifies the specific native ERC721 contract and bridge it represents.
- Automatically deployed by
ERC721Bridge
when new tokens are added to be supported by a bridge instance.
- A simple extension of OpenZeppelin's
ERC721Bridge
- Bridge contract that uses Teleporter to facilitate the bridging operations of adding new supported tokens and moving tokens between chains.
- Supports bridging of simple ERC721 tokens between any
subnet-evm
instance. Note: Some custom ERC721 implementations may include custom logic for minting, metadata(such as variants, rarity, etc.), and/or other features. This bridge implementation does not support bridging of these custom features. - Primary functions include:
submitCreateBridgeNFT
: Called on the origin chain to add support for an ERC721 on a different chain's bridge instance. Submits a Teleporter message that invokescreateBridgeNFT
on the destination chain._createBridgeNFTContract
: Called when a newBridgeAction.Create
Teleporter message is received on the destinations chain. Deploys a newBridgeNFT
contract to represent a native ERC721 token, if it already does not exist.bridgeToken
: Called to move supported ERC721 token from one chain to another. If a token is moved from native to bridged contract, the ERC721 token is locked on the native chain by being transferred to the ERC721Bridge (requires the ERC721Bridge to be approved as operator of the token) and then minted to the used on the destination chain. If a token is moved from a bridged contract to a native contract, the bridged ERC721 token is burned (also requires approve) on the bridge chain and then "unlocked" by being transferred back to the recipient on the native chain._mintBridgeNFT
: Called when a newBridgeAction.Mint
Teleporter message is received on the destinations chain to mint the bridged ERC721 token to the receiver address._transferBridgeNFT
: Called when a newBridgeAction.Transfer
Teleporter message is received to transfer bridged tokens to the native chain.
Note: This implementation currently does not support chain-hopping for ERC721 tokens. This means if a user wants to re-bridge an ERC721 token from one chain to another, they must first bridge it back to the native chain and then bridge it to the new destination chain manually.
An end-to-end test demonstrating the use of the generic ERC721 token bridge contracts can be found in here. This test implements the following flow and checks that each step is successful:
- An example "native" ERC721 token is deployed on subnet A
- The ERC721Bridge contract is deployed on subnets A and B.
- Teleporter message is sent from subnet A to B to create a new BridgeNFT contract instance to represent the native ERC721 token on subnet B.
- An NFT is minted on subnet A to the user address.
- ERC721Bridge on subnet A is approved as operator of the NFT.
bridgeToken
is called on subnet A to lock the NFT and bridge it to subnet B.- The NFT is transferred to the ERC721Bridge contract on subnet A and then a Teleporter message is sent to subnet B to mint the NFT to the user on the BridgeNFT contract on subnet B.
- The user on subnet B approves the BridgeNFT contract on subnet B as operator of the NFT.
- The user on subnet B calls
bridgeToken
on the BridgeNFT contract on subnet B to burn the NFT and bridge it to subnet A.
- Run a local network following the instructions here.
- An example workflow is provided via the erc721_send_and_receive.sh script.