ERC721 NFT Bridging
BOBA NFT bridges consists of two bridge contracts. The L1NFTBridge contract is deployed on L1 and the L2NFTBridge contract is deployed on L2. It supports native L1 NFTs and native L2 NFTs to be moved back and forth.
Native L1 NFT: the original NFT contract was deployed on L1
Native L2 NFT: the original NFT contract was deployed on L2
Bridging an NFT to Boba takes several minutes, and bridging an NFT from Boba to Ethereum takes 7 days. Not all NFTs are bridgeable - developers must use specialized NFT contracts (e.g. L2StandardERC721.sol) to enable this functionality.
When deploying your L2StandardERC721, please take caution if you extend the contract with more features, as an incorrect implementation may result in loss of tokens. For instance, do not add a method that would allow updating the corresponding 'l1Contract' address for an L2StandardERC721. An update in between operation would deem the previous tokens to be locked on the bridge. Furthermore, The NFTBridge contracts use the information at the time of registration to obtain the l1Token information and send messages between the bridges.
Assuming you have already deployed an NFT contract on L1, and you wish to transfer those NFTs to L2, please make sure that your L1 NFT contract is ERC721 compatible. Your contract must implement ERC165
and ERC721
interfaces. We will check the interface before registering your NFT contracts to our bridges.
After verifying the interface, please deploy L2StandardERC721 on Boba. The L1_NFT_CONTRACT_ADDRESS
is the address of your NFT on Ethereum.
If you want to deploy your own L2 NFT contract, please follow requirements:
Your L2 NFT contract must be ERC721 compatible and implemented
ERC165
andERC721
interfaces.The
mint
function in your L2 NFT contract should be overriden by.The input must be
address _to, uint256 _tokenId, bytes memory _data
, even though you might need them all.In your L2 NFT contract, you must add the following code to bypass our interface check in our NFT bridge
NOTE: Once you have your L2 NFT contract address, please contact us so we can register that address in the L1 and L2 NFT bridges.
Deploy your NFT on Boba and then deploy L1StandardERC721 on Ethereum. The L2_NFT_CONTRACT_ADDRESS
is the address of your NFT on Boba.
If you want to deploy your own L1 NFT contract, please follow requirements:
Your L1 NFT contract must be ERC721 compatible and implemented
ERC165
andERC721
interfaces.The
mint
function in your L1 NFT contract should be overriden by.The input must be
address _to, uint256 _tokenId, bytes memory _data
, even though you might need them all.In your L1 NFT contract, you must add the following code to bypass our interface check in our NFT bridge
NOTE: Once you have your L1 NFT contract address, please contact us so we can register that address in the L1 and L2 NFT bridges.
CASE 1 - Native L1 NFT - Bridge NFTs from Ethereum to Boba
First, users transfer their NFT to the L1 NFT Bridge, starting with an approval.
Users then call the depositNFT
or depositNFTTo
function to deposit NFT to L2. The NFT arrives on L2 after L1 conf blocks.
CASE 2 - Native L1 NFT - Bridge NFTs from Boba to Ethereum
Prior to the exit, the L2 NFT Bridge burns the L2 NFT, so the first step is for the user to approve the transaction.
Users have to approve the Boba for the exit fee next. They then call the withdraw
or withdrawTo
function to exit the NFT from Boba to Ethereum. The NFT will arrive on L1 after the seven days.
CASE 3 - Native L2 NFT - Bridge NFTs from Boba to Ethereum
Users have to transfer their NFTs to the L2 NFT Bridge, so they start by approving the transaction.
Users have to approve the Boba for the exit fee next. They then call the withdraw
or withdrawTo
function to exit NFT from L2. The NFT will arrive on L1 after the seven days.
CASE 4 - Native L2 NFT - Bridge NFTs from Ethereum to Boba
The L1 NFT Bridge has to burn the L1 NFT, so the user needs to approve the transaction first.
Users then call the depositNFT
or depositNFTTo
function to deposit NFT to L2. The NFT arrives on L2 after L1 conf blocks.
Attempting to categorize ERC721s on the basis of metadata, we have:
ERC721 with derivable metaData (more common)
The general ERC721(like the one in the example) has the tokenURI in the form = 'baseURI' + 'tokenId' or is completely derivable on-chain from the tokenId
In this case, you don't really need to worry about transporting metadata between layers and hence you are already at best.
ERC721 with no metadata (non- ERC721Metadata)
Some ERC721 do not have metadata associated, in which case you surely do not need to worry about transporting metadata
ERC721 with non-derivable metaData (unrecoverable context)
These are the "special NFTs" that require some form of transportation of metadata between layers
The NFT Bridge provides with a special method 'withdrawWithExtraData' in comparision to 'withdraw' for the usual bridging to allow transporting the metadata when bridging the NFT to the other layer
What metadata are actually bridged?
When you chose to withdraw through the aforementioned method - the tokenURI()
data will be encoded and passed on to the L1StandardERC721 for it to receive and handle it
Optimisations
Bridging the tokenURI data as a whole might not be ecnomical always and depends on the size of the tokenURI. For example, bridging the tokenURI data for on-chain NFTs could be very costly. The NFTBridge, asks for a special method for this - bridgeExtraData
, if this method is implemented on your native ERC721 contracts and returns some data that you would need to bridge to the other layer, the bridge will prioritize this over tokenURI
potentially allowing to bridge seed data for generation on the L1 side.
Making your ERC721 bridge extra data
To enable the bridge to pick up the exposed extra data that you would want to bridge
expose the method
bridgeExtraData()
on your contract. This can encode one/many unique seed data to be transported over to the other layer while bridging. For example, an on-chain contract that requires three unique integers to be transported for each tokenId can expose the data in a way similar to:
Modify ERC165 supportsInterface to return the bridgeExtraData(uint256) selector
For example,
On the other side, our NFT bridge mints the NFT using the function
so your NFT contract should decode _data
and write into the smart contract.
To bridge the NFT with the extra data, you need to call these functions of NFT bridges:
Mainnet
Ethereum
BNB Mainnet
Testnet
BNB Testnet
Last updated