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.

1

Create a project folder

mkdir giwa-bridging-erc20
cd giwa-bridging-erc20
2

Initialize the project

pnpm init
3

Install dependencies

pnpm add -D tsx @types/node
pnpm add viem@^2.38.0

Prepare a wallet

You’ll need a wallet to bridge an ERC-20 token.

1

Get Sepolia ETH

You’ll need ETH on both Ethereum Sepolia and GIWA Sepolia to bridge tokens.

Don’t have a wallet yet? Use cast command to create one.

2

Set the Private Key environment variable

This tutorial requires multiple transaction signatures. To handle this, you’ll need to set your wallet private key as an environment variable.

export TEST_PRIVATE_KEY=0x...

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.

What is an ABI?

An ABI (Application Binary Interface) is the interface required to interact with a smart contract. It defines the contract’s function names, parameters, and return values. Clients, SDKs, and other tools use the ABI to make calls to the contract.

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.

1

Writing the code

2

Running

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 .

1

Flow

  1. Grant approval to L1StandardBridge contract so that it can transfer your ERC-20 tokens

  2. Send the deposit transaction on L1

  3. The corresponding L2 deposit transaction is created by the sequencer

  4. Deposit complete

2

Writing the code

3

Running

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.

1

Flow

  1. Send the withdrawal initiation transaction on L2

  2. Send the withdrawal prove transaction on L1

  3. Send the withdrawal finalize transaction on L1

  4. Withdrawal complete

2

Writing the code

3

Running

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