Consuming a Foundational Store

This guide explains how to consume data from a Foundational Store in your Substreams modules. Foundational Stores provide efficient access to pre-processed blockchain data for building complex data processing pipelines.

What is a Foundational Store?

A Foundational Store is a high-performance, multi-backend key-value storage system designed for Substreams ingestion and serving. It provides:

  • Fork-aware storage: Handles blockchain reorganizations automatically

  • Multiple backends: Supports Badger (embedded) and PostgreSQL

  • Block-level versioning: Every entry tagged with block number for historical queries

  • High-performance serving: gRPC API for data retrieval

  • Streaming ingestion: Continuous processing via Substreams sink

Foundational Stores are typically populated by Substreams modules that extract and transform blockchain data, then serve that data to other Substreams modules for efficient lookups.

Consuming a Foundational Store

To consume data from a Foundational Store in your Substreams module:

Step 1: Import the Foundational Store

Add the import to your substreams.yaml:

imports:
  your_store: [email protected]

modules:
  - name: your_module
    kind: map
    inputs:
      - foundational-store: your_store
    output:
      type: proto:your.OutputType

Step 2: Query the Store in Code

Use the FoundationalStore input in your Rust handler:

Understanding QueriedEntries Responses

When querying a Foundational Store, responses are returned as QueriedEntries containing multiple QueriedEntry results.

QueriedEntries Structure

Each QueriedEntry corresponds to one requested key, in the same order as the request.

Response Codes

  • RESPONSE_CODE_FOUND: Key exists and value was retrieved successfully

  • RESPONSE_CODE_NOT_FOUND: Key does not exist at the requested block

  • RESPONSE_CODE_NOT_FOUND_FINALIZE: Key was deleted after finality (LIB) - historical reference only

  • RESPONSE_CODE_UNSPECIFIED: Default value, should not occur in normal operation

Handling Responses in Code

Example: SPL Token Transfers with Ownership Resolution

The substreams-spl-token module demonstrates consuming a Foundational Store.

It imports the SPL Initialized Account store to resolve token account ownership:

Then queries the store to get owner addresses for transfer resolution:

Last updated

Was this helpful?