Bridging ETH

Bridge ETH 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-eth
cd giwa-bridging-eth
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 ETH.

1

Get Sepolia ETH

For a deposit (Ethereum -> GIWA), you need ETH on the Ethereum Sepolia network. Use this faucet to get Sepolia ETH.

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 ETH bridging.

Deposit ETH (Ethereum -> GIWA)

Let’s bridge ETH from Ethereum to GIWA.

When you run the code below, your ETH on Ethereum is actually sent to the OptimismPortal contract. The same amount is then minted and credited to your GIWA wallet. This process is known as Lock-and-Mint.

1

Flow

  1. Send a deposit transaction on Layer 1

  2. The corresponding Layer 2 deposit transaction is created by the sequencer

  3. Deposit complete

2

Writing the code

3

Running

Why does it take a few minutes for an L1 deposit to appear in my L2 wallet balance?

When you send an L1 deposit transaction, the L2 sequencer picks it up and creates a corresponding L2 deposit transaction. Because the L1 chain can experience reorgs, the L2 sequencer waits for the L1 deposit transaction to be finalized by a certain number of blocks (N blocks) before processing it. This ensures system stability and prevents inconsistencies.

Withdraw ETH (GIWA -> Ethereum)

Have you successfully sent ETH 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 ETH on GIWA is actually sent to the L2ToL1MessagePasser contract. The same amount is then released to your Ethereum wallet. In this case, the ETH that was originally locked in the OptimismPortal contract during the deposit gets unlocked. This process is called Burn-and-Unlock.

The ETH sent to the L2ToL1MessagePasser contract is effectively considered burned. While the balance still appears when queried, the contract includes a burn() function that can be called at any time to destroy the entire balance.

1

Flow

  1. Send a withdrawal initiation transaction on Layer 2

  2. Send a withdrawal prove transaction on Layer 1

  3. Send a withdrawal finalize transaction on Layer 1

  4. Withdrawal complete

2

Writing the code

3

Running

Learn more

Check out the viem docs for additional resources.

Last updated