Token Bridge

The ability to send cross layer messages trustlessly between L1 and L2 can be leveraged to build a token bridge to move assets from L1 to L2 and back. Goshen provide a standard bridge for Ether and ERC20 tokens.

Deposit Ether

To move Ether from L1 to L2, you can send a deposit transaction via depositETH or depositETHTo of L1StandardBridge contract. This will transfer the funds to the L1StandardBridge contract and will send a cross layer message to L2StandardBridge contract deployed on L2 to mint the same amount of funds to the specified address.

/**
 * @dev Deposit an amount of the ETH to the caller's balance on L2.
 * @param _data Optional data to forward to L2. This data is provided
 *        solely as a convenience for external contracts. Aside from enforcing a maximum
 *        length, these contracts provide no guarantees about its content.
 */
function depositETH(bytes calldata _data) external payable;

/**
 * @dev Deposit an amount of ETH to a recipient's balance on L2.
 * @param _to L2 address to credit the withdrawal to.
 * @param _data Optional data to forward to L2. This data is provided
 *        solely as a convenience for external contracts. Aside from enforcing a maximum
 *        length, these contracts provide no guarantees about its content.
 */
function depositETHTo(address _to, bytes calldata _data) external payable;

Withdraw Ether

To withdraw Ether from L2 to L1, you can send a withdraw transaction via withdrawETH or withdrawETHTo of L2StandardBridge contract. This will transfer the funds to the L2StandardBridge contract and will send a cross layer message to L1StandardBridge contract to transfer the same amount of funds to the specified address.

Deposit ERC20 tokens

To move a ERC20 token from L1 to L2, you can send a deposit transaction via depositERC20 or depositERC20To of L1StandardBridge contract. This will transfer the funds to the L1StandardBridge contract and will send a cross layer message to L2StandardBridge contract deployed on L2 to mint the same amount of funds to the specified address.

Withdraw ERC20 tokens

To withdraw a ERC20 token from L2 to L1, you can send a withdraw transaction via withdraw or withdrawTo of L2StandardBridge contract. This will transfer the funds to the L2StandardBridge contract and will send a cross layer message to L1StandardBridge contract to transfer the same amount of funds to the specified address.

Last updated