First, we need a token to bridge. There is no need for a particular ERC20 implementation in order for a token to be compatible with L2. If you already have a token, feel free to skip this step. If you want to deploy a new token, use the following contract of a simple ERC20 token that mints 1 million tokens to the deployer when launched.
Next, you’ll launch a counterpart to this token on Scroll, which will represent the original token on Sepolia. This token can implement custom logic to match that of the L1 token or even add additional features beyond those of the L1 token.
For this to work:
The token must implement the IScrollStandardERC20 interface in order to be compatible with the bridge.
The contract should provide the gateway address and the counterpart token addresses (the L1 token we just launched) under the gateway() and counterpart() functions. It should also allow the L2 gateway to call the token mint() and burn() functions, which are called when a token is deposited and withdrawn.
The following is a complete example of a token compatible with the bridge. To the constructor, you will pass the official Scroll Custom Gateway address (0x058dec71E53079F9ED053F3a0bBca877F6f3eAcf) and the address of the token launched on Sepolia.
You need to contact the Scroll team to add the token to L2CustomERC20Gateway contract in Scroll and L1CustomERC20Gateway contract in L1. In addition, follow the instructions on the token lists repository to add your token to the Scroll official bridge frontend.
Once your token has been approved by the Scroll team, you should be able to deposit tokens from L1. To do so, you must first approve the L1CustomGateway contract address on Sepolia (0x31C994F2017E71b82fd4D8118F140c81215bbb37). Then, deposit tokens by calling the depositERC20 function from the L1CustomGateway contract. This can be done using our bridge UI, Etherscan Sepolia, or a smart contract.
You will follow similar steps to send tokens back from L2 to L1. First, approve the L2CustomGateway address (0x058dec71E53079F9ED053F3a0bBca877F6f3eAcf) and then withdraw the tokens calling the withdrawERC20 from the L2CustomGateway contract.
Adding your token to the Scroll official bridge (as described above) is the recommended method of bridging tokens to and from Scroll. This approach will make them easier to discover and safer for holders. However, it will require approval from the Scroll team. If you want to launch a custom token without the official approval process, you can launch a custom gateway yourself. To do so, you will need to deploy an L1CustomERC20Gateway contract on L1 and an L2CustomERC20Gateway on L2.
Once the contracts are deployed, call the following functions to initialize the contracts and bind them to the corresponding tokens and the gateway on the other side of the bridge.
First, call the initialize function on the MyL1Gateway contract with the following parameters:
_counterpart: The address of MyL2Gateway we just launched on Scroll.
_router: Set it to 0x13FBE0D0e5552b8c9c4AE9e2435F38f37355998a, the L1GatewayRouter contract on Sepolia.
_messenger: Set it to 0x50c7d3e7f7c656493D1D76aaa1a836CedfCBB16A, the L1ScrollMessenger contract on Sepolia.
A custom gateway can host multiple token bridges. In this case, we will only be allowing bridging between L1Token and L2Token by calling the updateTokenMapping function on the MyL1Gateway contract with the following parameters:
_l1Token: The address of the L1Token contract we previously launched on Sepolia.
_l2Token: The address of the L2Token contract we previously launched on Scroll.