Bridging ERC-20 Token
Bridge ERC-20 tokens from Ethereum to GIWA, and from GIWA to Ethereum.
Requirements
Make sure the following are installed.
Set up development environment
In this tutorial, we’ll use viem. Viem is a Node.js library, so we’ll start by creating a Node.js project.
Prepare a wallet
You’ll need a wallet to bridge an ERC-20 token.
Get Sepolia ETH
You’ll need ETH on both Ethereum Sepolia and GIWA Sepolia to bridge tokens.
Configure the Chain Client
Set up chain client for ERC-20 bridging.
Set contract addresses and ABIs
We’ve deployed a test ERC-20 on Ethereum and GIWA for bridging. The L2 token below is the bridged version of the L1 token.
Bridging ERC-20 token can be done using L1StandardBridge contract. Let's define ABIs for required functions.
Get L1 faucet tokens
To make a deposit (Ethereum -> GIWA), you’ll need faucet tokens on the Ethereum Sepolia network. The L1 token defined above includes a claimFaucet function. Run the code below to call claimFaucet and receive your L1 faucet tokens.
Deposit ERC-20 Token (Ethereum -> GIWA)
Now let’s bridge the faucet tokens from Ethereum to GIWA.
When you run the code below, your faucet tokens on Ethereum will actually be sent to the L1StandardBridge contract, and the same amount will be credited to your GIWA wallet. This process is called Lock-and-Mint .
Flow
Grant approval to L1StandardBridge contract so that it can transfer your ERC-20 tokens
Send the deposit transaction on L1
The corresponding L2 deposit transaction is created by the sequencer
Deposit complete
Withdraw ERC-20 Token (GIWA -> Ethereum)
Have you successfully sent ERC-20 from Ethereum to GIWA? Now let’s bridge it back in the opposite direction — from GIWA to Ethereum.
When you run the code below, your ERC-20 tokens on GIWA are burned, and the same amount is released to your Ethereum wallet. In this case, the tokens locked in the L1StandardBridge contract during the Deposit are now unlocked. This process is called Burn-and-Unlock.
Learn more
Interested in bridging data in addition to assets like ETH and ERC-20 tokens? Read the OP Stack docs and build your own implementation.
Last updated