Purpose
The indexer keeps the backend in sync with onchain state so the relayer can resolve accounts quickly.
Why it exists
Without the indexer, every authenticated request would require the relayer to scan the onchain AccountRegistry to find which MemWalAccount holds a given delegate key. This involves fetching the registry object, iterating through its dynamic fields, and checking each account, an expensive chain of RPC calls.
The indexer eliminates this by listening to Sui events and syncing account data into PostgreSQL. The relayer can then resolve delegate key ownership with a single database lookup.
How it works
The indexer is a standalone Rust service (services/indexer) that:
- Connects to the same PostgreSQL database as the relayer
- Polls Sui blockchain events using
suix_queryEvents - Filters for
AccountCreatedevents from the Walrus Memory package - Inserts
account_id → ownermappings into theaccountstable - Stores its event cursor in
indexer_stateso it can resume after restarts
Auth resolution flow
When the relayer receives a request, it resolves the delegate key's account using this priority:
- PostgreSQL cache (
delegate_key_cache), fastest, populated lazily by the relayer itself - Indexed accounts (
accounts), populated by the indexer, enables account discovery without chain scans - Onchain registry scan, fallback, scans
AccountRegistrydynamic fields through RPC - Header hint (
x-account-id), client-provided hint, useful during first-time setup - Config fallback (
MEMWAL_ACCOUNT_ID), server-level default
After successful resolution through any strategy, the mapping is cached in delegate_key_cache for future requests.
Configuration
The indexer reads these environment variables:
| Variable | Required | Default | Description |
|---|---|---|---|
DATABASE_URL | Yes | PostgreSQL connection string | |
MEMWAL_PACKAGE_ID | Yes | Walrus Memory contract package ID to filter events | |
SUI_RPC_URL | No | Mainnet fullnode | Sui RPC endpoint |
POLL_INTERVAL_SECS | No | 5 | Seconds between event poll cycles |
Running
$ cd services/indexer
$ cargo run
The indexer is recommended for production but optional for development, the relayer can fall back to onchain resolution without it.