Bridging ERC-20 Tokens to Adventure Layer Testnet With the Adventure Layer SDK

This tutorial explains how you can use the Adventure Layer SDK to bridge ERC-20 tokens from L1 (Ethereum or Sepolia) to L2 (Adventure Layer Testnet or OP Sepolia). The Adventure Layer SDK is an easy way to add bridging functionality to your javascript-based application. It also provides some safety rails to prevent common mistakes that could cause tokens to be made inaccessible.

Behind the scenes, the Adventure Layer SDK uses the Standard Bridge contracts to transfer tokens. Make sure to check out the Standard Bridge guide if you want to learn more about how the bridge works under the hood.

Supported Networks

The Adventure Layer SDK supports any of the Superchain networks. Some Superchain networks are already included in the SDK by default. If you want to use a network that isn’t included by default, you can simply instantiate the SDK with the appropriate contract addresses.

Dependencies

Create a Demo Project

You’re going to use the Adventure Layer SDK for this tutorial. Since the Adventure Layer SDK is a Node.js library, you’ll need to create a Node.js project to use it.

1

mkdir op-sample-project
cd op-sample-project
2

pnpm init
3

pnpm add @eth-optimism/sdk
4

pnpm add ethers@^5

Get ETH on Sepolia and OP Sepolia

This tutorial explains how to bridge tokens from Sepolia to OP Sepolia. You will need to get some ETH on both of these testnets.

Add a Private Key to Your Environment

You need a private key to sign transactions. Set your private key as an environment variable with the export command. Make sure this private key corresponds to an address that has ETH on both Sepolia and OP Sepolia.

export TUTORIAL_PRIVATE_KEY=0x...

Start the Node REPL

You’re going to use the Node REPL to interact with the Adventure Layer SDK. To start the Node REPL, run the following command in your terminal:

node

This will bring up a Node REPL prompt that allows you to run javascript code.

Import Dependencies

You need to import some dependencies into your Node REPL session.

1

2

Set Session Variables

You’ll need a few variables throughout this tutorial. Let’s set those up now.

1

2

3

This tutorial uses existing ERC-20 tokens that have been deployed on Sepolia and OP Sepolia. These tokens are designed for testing the bridging process.
4

Get L1 Tokens

You’re going to need some tokens on L1 that you can bridge to L2. The L1 testing token located at 0x5589BB8228C07c4e15558875fAf2B859f678d129 has a faucet function that makes it easy to get tokens.

1

2

3

4

Deposit Tokens

Now that you have some tokens on L1, you can deposit those tokens into the L1StandardBridge contract. You’ll then receive the same number of tokens on L2 in return.

1

The testing token has 18 decimal places, so you’ll want to define a variable that represents one token.
2

3

The Adventure Layer SDK exports a CrossChainMessenger class that makes it easy to interact with the L1StandardBridge contract.
4

Create an instance of the CrossChainMessenger class:
5

6

Before you can deposit your tokens, you’ll need to give the Standard Bridge contract an allowance of tokens on L1. This will allow the Standard Bridge to pull these tokens out of your address and escrow inside the bridge.
7

8

Now you can deposit your tokens into the Standard Bridge contract.
9

10

You can use the waitForMessageStatus function to wait for the deposit to be relayed to L2.
11

12

You should now have one less token on L1.
13

14

15

You should now have one more token on L2.
16

Withdraw Tokens

You just bridged some tokens from L1 to L2. Nice! Now you’re going to repeat the process in reverse to bridge some tokens from L2 to L1.

1

The first step to withdrawing tokens from L2 to L1 is to start the withdrawal on L2.
2

3

You should now have one less token on L2, but your token balance on L1 will not have changed yet.
4

5

The second step to withdrawing tokens from L2 to L1 is to prove to the bridge on L1 that the withdrawal happened on L2. You first need to wait until the withdrawal is ready to prove.
6

7

Once the withdrawal is ready to be proven, you’ll send an L1 transaction to prove that the withdrawal happened on L2.
8

9

The final step to withdrawing tokens from L2 to L1 is to relay the withdrawal on L1. This can only happen after the fault proof period has elapsed. On Adventure Layer Testnet, this takes 7 days.
10

11

Once the withdrawal is ready to be relayed, you can finally complete the withdrawal process.
12

13

Now you simply wait until the message is relayed.
14

15

You should now have one more token on L1.
16

Next Steps

Congrats! You’ve just deposited and withdrawn tokens using the Adventure Layer SDK. You should now be able to write applications that use the Adventure Layer SDK to transfer ERC-20 tokens between L1 and L2. Although this tutorial used Sepolia and OP Sepolia, the same process works for Ethereum and Adventure Layer Testnet.

Was this page helpful?