ERC1155 Token Bridge
Bridging ERC1155 Tokens from Layer 1 to Layer 2 in Wischain
Deposit ERC1155 Tokens from Layer 1
Bridging ERC1155 tokens from Layer 1 (L1) to Layer 2 (L2) in Wischain is accomplished through the L1ERC1155Gateway. Unlike the ERC721 bridging process, this does not utilize a router; instead, the depositERC1155 function on the Gateway is called directly.
The depositERC1155 function is a payable function, which means the amount of ETH sent alongside the transaction will be allocated for L2 transaction fees. If the ETH provided is insufficient, the transaction will fail, and any excess funds will be refunded to the sender. A minimum of 0.00001 ETH is generally adequate to process a token deposit.
Creating an ERC1155 Token on Layer 2
To bridge ERC1155 tokens effectively, a contract compliant with the IScrollERC1155 standard must be deployed. This contract needs to be registered on both the L1ERC1155Gateway and L2ERC1155Gateway. The contract must grant permission to the L2 Gateway to mint tokens upon deposit and burn tokens when they are withdrawn.
The interface for the IScrollERC1155 standard is as follows:
Adding an ERC1155 Token to the Wischain Bridge
All assets can be securely and permissionlessly bridged through Gateway contracts that any developer can deploy. Additionally, Wischain maintains an ERC1155 Gateway contract that welcomes all NFTs created by the community. Being part of the Wischain-managed Gateway allows developers to forgo deploying their own Gateway contracts, ensuring their tokens are listed in the Wischain frontend. To have a token added to the Wischain Gateway, developers must reach out to the Wischain team and follow the guidelines outlined in the token lists repository.
Withdrawing ERC1155 Tokens from Layer 2
The L2ERC1155Gateway contract facilitates the transfer of tokens from L2 back to L1. Before initiating a withdrawal, the L2ERC1155Gateway contract must be authorized by the corresponding token contract. Once approved, the withdrawERC1155 function can be called to execute the asset bridge.
The withdrawERC1155 function is also a payable function, and the amount of ETH sent will cover the Layer 1 transaction fees. If the ETH provided is insufficient, the transaction will not proceed, and any surplus will be refunded. Given that L1 fees can fluctuate based on network activity, an estimated 0.005 ETH should generally suffice for processing a token withdrawal.
It is crucial to ensure that the transaction does not revert on L1 when sending from L2. If a transaction fails on L1, the bridged tokens will be burnt on L2, and there is no mechanism to recover them.
L1ERC1155Gateway API
Developers can access the complete API documentation for the Wischain contracts through the provided npm library.
depositERC1155 Function
Parameters:
_token: The address of the ERC1155 token contract on L1.
_to: The recipient's account address on L2.
_tokenId: The ID of the NFT to deposit.
_amount: The quantity of tokens to deposit.
_gasLimit: The gas limit required for the deposit on L2. Any unused portion of the fee will be refunded.
updateTokenMapping Function
Parameters:
_l1Token: The address of the ERC1155 token in L1.
_l2Token: The address of the corresponding ERC1155 token in L2.
L2ERC1155Gateway API
withdrawERC1155 Function
Parameters:
token: The address of the ERC1155 token contract on L2.
to: The recipient's account address on L1.
tokenId: The ID of the NFT to withdraw.
amount: The quantity of tokens to withdraw.
gasLimit: This parameter is included for potential future compatibility.
updateTokenMapping Function
Parameters:
_l1Token: The address of the ERC1155 token in L1.
_l2Token: The address of the corresponding ERC1155 token in L2.
This comprehensive structure allows for efficient and secure bridging of ERC1155 tokens between Layer 1 and Layer 2 within the Wischain ecosystem, facilitating greater interoperability and functionality for developers and users alike.
Last updated