Skip to main content
In this tutorial, you’ll learn how to use the viem library to trace a Standard Bridge deposit or withdrawal between L1 and L2. You’ll specifically learn how to determine the status of a deposit or withdrawal and how to retrieve the transaction receipt for the executed transaction on L1 (for withdrawals) or L2 (for deposits).

Dependencies

Create a demo project

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

Make a Project Folder

2

Initialize the project

3

Install viem

Add RPC URLs to your environment

You’ll be using the getTransactionReceipt function from the viem library during this tutorial. This function uses event queries to retrieve the receipt for a deposit or withdrawal. Since this function uses large event queries, you’ll need to use an RPC provider like Alchemy that supports indexed event queries. Grab an L1 and L2 RPC URL for Sepolia and OP Sepolia, respectively.

Start the Node REPL

You’re going to use the Node REPL to interact with viem. To start the Node REPL, run the following command in your terminal:
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.

Import viem

Set session variables

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

Import RPC URLs

2

Set the deposit to trace

You’ll be tracing a specific deposit in this tutorial. Deposit tracing is generally based on the transaction hash of the transaction that triggered the deposit. You can replace this transaction hash with your own if you’d like.
3

Set the withdrawal to trace

You’ll also be tracing a specific withdrawal in this tutorial. Like with deposits, withdrawal tracing is generally based on the transaction hash of the transaction that triggered the withdrawal. You can replace this transaction hash with your own if you’d like.
4

Create the RPC providers

Trace a Deposit

You can use viem to trace a deposit.
1

Get the deposit status

You can query for the deposit status using the transaction hash of the deposit.
2

Get the deposit transaction receipt

Retrieve the transaction receipt for the deposit using the viem client.
3

Get the deposit transaction

You can directly query for the L2 transaction that executed the deposit.

Trace a withdrawal

You can use viem’s functions to trace a withdrawal.
1

Get the withdrawal status

Like deposits, withdrawals can have multiple statuses depending on where they are in the process.
2

Get the withdrawal transaction receipt

Retrieve the L1 transaction receipt for the withdrawal.
3

Get the withdrawal transaction

Directly query for the L1 transaction that executed the withdrawal.

Next steps