The indexer keeps the backend in sync with onchain state so the relayer can resolve accounts quickly.Documentation Index
Fetch the complete documentation index at: https://docs.memwal.ai/llms.txt
Use this file to discover all available pages before exploring further.
Why It Exists
Without the indexer, every authenticated request would require the relayer to scan the onchainAccountRegistry 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 MemWal 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 via RPC - Header hint (
x-account-id) — client-provided hint, useful during first-time setup - Config fallback (
MEMWAL_ACCOUNT_ID) — server-level default
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 | — | MemWal 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 |