For AI agents: the documentation index is at /llms.txt. Markdown versions of pages are available by appending .md to the URL.
Skip to main content

Indexing Optimism Bridge Deposits

Introduction​

This tutorial will guide you through indexing Optimism Standard Bridge deposits in under 5 minutes using Envio HyperIndex's no-code contract import feature.

The Optimism Standard Bridge enables the movement of ETH and ERC-20 tokens between Ethereum and Optimism. We'll index bridge deposit events by extracting DepositFinalized logs on Optimism and ETHDepositInitiated logs on Ethereum Mainnet.

Building this with an AI agent?

The steps below use the interactive prompts, which can add contracts on two chains in one go. Under an agent, envio init imports a single contract, so give your agent this prompt instead:

Build the indexer in https://docs.envio.dev/docs/HyperIndex/tutorial-op-bridge-deposits.md.
If you can't open that URL, read the page with `pnpx envio tools fetch-docs https://docs.envio.dev/docs/HyperIndex/tutorial-op-bridge-deposits`.
Import the Optimism contract with `pnpx envio init contract-import explorer -n optimism-bridge-indexer -c 0x4200000000000000000000000000000000000010 -b optimism --single-contract --all-events -d optimism-bridge-indexer`.
Then make config.yaml, schema.graphql and src/handlers match Step 5 of that page, add a handler for L1ChugSplashProxy ETHDepositInitiated, update the tests to cover chains 1 and 10, and run `pnpm codegen`, `pnpm tsc --noEmit` and `pnpm test`.
If a command fails, check "If Your Agent Gets Stuck" in https://docs.envio.dev/docs/HyperIndex/quickstart.md before trying anything else.

Prerequisites​

Before starting, ensure you have the following installed:

Note

Docker is specifically required to run your blockchain indexer locally. You can skip Docker installation if you plan only to use Envio Cloud.

Step 1: Initialize Your Indexer​

  1. Open your terminal in an empty directory and run:
pnpx envio init

Running this from an AI agent or a script? envio init switches to agent mode when stdout is not a terminal, when CLAUDECODE or CI is set, or when TERM=dumb. Agent mode prints a plan and exits instead of showing the prompts below, and it can only import one contract with all its events. To follow this tutorial, run envio init in a real terminal, with ENVIO_TUI=true if your shell is detected as an agent. Otherwise use Non-interactive envio init for one contract, then edit config.yaml to match the one in Step 5. That doesn't create the second contract's entity or handler, so its events aren't stored: add its type to schema.graphql and a handler file shaped like src/handlers/Proxy.ts (both in Step 5), then run pnpm codegen.

  1. Enter a folder name for your indexer (we'll use "optimism-bridge-indexer" in this example). The indexer takes its name from the folder.
? Specify a folder name (ENTER to skip):  (.) optimism-bridge-indexer

The indexer is generated in TypeScript by default.

Step 2: Import the Optimism Bridge Contract​

  1. Select Evm → From Address - Lookup ABI from block explorer → optimism (type to filter the chain list)

  2. Enter the Optimism bridge contract address:

    0x4200000000000000000000000000000000000010

    View on Optimistic Etherscan

  3. Select only the DepositFinalized event. All events start selected, so:

    • Press ← to clear all
    • Move to DepositFinalized with the arrow keys (↑↓)
    • Press spacebar to select it, then Enter
Tip

You can select multiple events to index simultaneously.

Step 3: Add the Ethereum Mainnet Bridge Contract​

  1. When prompted, select Add a new contract (with a different ABI)

  2. Choose Block Explorer → ethereum-mainnet

  3. Enter the Ethereum Mainnet gateway contract address:

    0x99C9fc46f92E8a1c0deC1b1747d010903E884bE1

    View on Etherscan

  4. Select only the ETHDepositInitiated event (press ← to clear all, then space on ETHDepositInitiated, then Enter)

  5. When finished adding contracts, select I'm finished

  6. Add your Envio API token. Pick Create a new API token to open the token page, or Add an existing API token, then paste it at the ? Add your API token: prompt. If ENVIO_API_TOKEN is set in your shell, or you passed --api-token, this prompt is skipped and that token is written to .env:

? Add an Envio API token to your .env file?
> Create a new API token (Opens https://envio.dev/app/api-tokens)
Add an existing API token

Envio runs codegen, installs dependencies and finishes with:

Your indexer is ready! Pick how you'd like to run it:

1. cd optimism-bridge-indexer && pnpm test # run the tests (recommended for AI)
2. cd optimism-bridge-indexer && pnpm dev # run locally
3. cd optimism-bridge-indexer && pnpm start # run in production

pnpm test runs the generated src/indexer.test.ts without Docker. Its smoke test only processes chain 1; to check the Optimism contract too, pass an explicit block range for chain 10 (see Testing).

Step 4: Start Your Indexer​

  1. If you have any running indexers, stop them first:
pnpm envio stop
  1. Start your new indexer:
pnpm dev

This command:

  • Starts the required Docker containers
  • Sets up your database
  • Launches the indexing process
  • Opens the Hasura GraphQL interface

Step 5: Understanding the Generated Code​

Let's examine the key files that Envio generated:

1. config.yaml​

This configuration file defines:

  • Chains to index (Optimism and Ethereum Mainnet)
  • Starting blocks for each chain
  • Contract addresses and ABIs
  • Events to track
  • strict_hex_type: true, which types bytes params such as extraData as `0x${string}` instead of string
config.yaml
# yaml-language-server: $schema=./node_modules/envio/evm.schema.json
name: optimism-bridge-indexer
disable_default_cross_chain: true
chains:
- id: 1
start_block: 0
contracts:
- name: L1ChugSplashProxy
address:
- "0x99C9fc46f92E8a1c0deC1b1747d010903E884bE1"
events:
- event: ETHDepositInitiated(address indexed from, address indexed to, uint256 amount, bytes extraData)
- id: 10
start_block: 0
contracts:
- name: Proxy
address:
- "0x4200000000000000000000000000000000000010"
events:
- event: DepositFinalized(address indexed l1Token, address indexed l2Token, address indexed from, address to, uint256 amount, bytes extraData)
strict_hex_type: true

2. schema.graphql​

This schema defines the data structures for our selected events:

  • Entity types based on event data
  • Field types matching the event parameters
  • Relationships between entities (if applicable)
schema.graphql
type L1ChugSplashProxy_ETHDepositInitiated {
id: ID!
from: String!
to: String!
amount: BigInt!
extraData: String!
}

type Proxy_DepositFinalized {
id: ID!
l1Token: String!
l2Token: String!
from: String!
to: String!
amount: BigInt!
extraData: String!
}

3. src/handlers​

This folder has one file per contract (Proxy.ts and L1ChugSplashProxy.ts) containing the business logic for processing events:

  • Functions that execute when events are detected
  • Data transformation and storage logic
  • Entity creation and relationship management
src/handlers/Proxy.ts
/*
* Please refer to https://docs.envio.dev for a thorough guide on all Envio indexer features
*/
import { indexer } from "envio";
import type {
Proxy_DepositFinalized,
} from "envio";

indexer.onEvent({ contract: "Proxy", event: "DepositFinalized" }, async ({ event, context }) => {
const entity: Proxy_DepositFinalized = {
id: `${event.chainId}_${event.block.number}_${event.logIndex}`,
l1Token: event.params.l1Token,
l2Token: event.params.l2Token,
from: event.params.from,
to: event.params.to,
amount: event.params.amount,
extraData: event.params.extraData,
};

context.Proxy_DepositFinalized.set(entity);
});

Step 6: Exploring Your Indexed Data​

Now you can interact with your indexed data:

Accessing Hasura​

  1. Open Hasura at http://localhost:8080
  2. When prompted, enter the admin password: testing

Monitoring Indexing Progress​

In the API tab, run this query to see which blocks each chain has processed:

query IndexingProgress {
_meta {
chainId
progressBlock
sourceBlock
eventsProcessed
isReady
}
}
Note

Thanks to Envio's HyperSync, indexing happens significantly faster than with standard RPC methods.

Querying Indexed Events​

  1. Click the API tab
  2. Construct a GraphQL query to explore your data

Entity names follow the <ContractName>_<EventName> pattern. The block explorer names the Optimism contract Proxy and the Ethereum Mainnet contract L1ChugSplashProxy, so the tables are Proxy_DepositFinalized and L1ChugSplashProxy_ETHDepositInitiated.

Here's an example query to fetch the 10 largest bridge deposits:

query LargestDeposits {
Proxy_DepositFinalized(limit: 10, order_by: { amount: desc }) {
l1Token
l2Token
from
to
amount
}
}
  1. Click the Play button to execute your query

Conclusion​

Congratulations! You've successfully created an indexer for Optimism Bridge deposits across both Ethereum and Optimism.

What You've Learned​

  • How to initialize a multi-network indexer using Envio
  • How to import contracts from different blockchains
  • How to query and explore indexed blockchain data

Next Steps​

  • Try customizing the event handlers to add additional logic
  • Create relationships between events on different networks
  • Deploy your indexer to Envio Cloud

For more, see the other HyperIndex tutorials, or connect your AI assistant to the Envio docs MCP server so it can search these docs while it works.