Ethereum - ERC20 Token Metadata
ERC20 Token Metadata Foundational Store
A specialized foundational store for tracking ERC20 token metadata on Ethereum and EVM-compatible chains. This store focuses specifically on metadata extraction and serving, working in conjunction with separate modules for transfer tracking.
Overview
The ERC20 Token Metadata foundational store provides efficient storage and retrieval of:
Token Metadata: Name, symbol, and decimals for ERC20 tokens
Metadata Events: Initialization and change events for token metadata
RPC-Enhanced Data: Complete metadata fetched via batch RPC calls for accuracy
Note: This foundational store is currently deployed on Ethereum Mainnet only for testing purposes. For deployments on other networks, please reach out on Discord.
Consuming Foundational Store Data
use substreams::store::FoundationalStore;
use substreams_ethereum::pb::eth::v2::Block;
#[substreams::handlers::map]
fn map_tokens_transfers(
block: Block,
foundational_store: FoundationalStore,
) -> Result<TokenTransfers, Error> {
// ... extract transfers from block
// Collect token addresses that need metadata lookup
let keys_to_query: Vec<Vec<u8>> = token_addresses_to_resolve.into_iter().collect();
let resp = foundational_store.get_all(&keys_to_query);
// Process responses and decode metadata
let mut metadata_map = std::collections::HashMap::new();
for entry in resp.entries {
let code = ResponseCode::try_from(entry.response.as_ref().unwrap().response)?;
if code != ResponseCode::Found {
continue;
}
if let Ok(token_metadata) = TokenMetadata::decode(entry.response.unwrap().value.unwrap().value.as_slice()) {
metadata_map.insert(entry.key, token_metadata);
}
}
// Use metadata_map to enrich transfers with name, symbol, decimals
Ok(TokenTransfers { transfers })
}Consumer Module (uses foundational store as input):
Complete Example: See the map_tokens_transfers implementation.
Data Model
Key Structure
The store uses token contract addresses as keys:
Value Schema
TokenMetadata (type.googleapis.com/sf.substreams.ethereum.erc20.v1.TokenMetadata)
Implementation details
The foundational store processes ERC20 metadata through two mechanisms:
MetadataInitialize Events: Direct extraction from event data
MetadataChanges Events: Batch RPC calls to ensure accuracy
Each token address becomes a key, with the corresponding TokenMetadata protobuf message as the value.
Implementation
Creating Foundational Store Entries
Substreams Manifest Configuration
Producer Module (creates foundational store entries):
Complete Example: See the metadata_to_foundational_store implementation.
Related Resources
Foundational Stores Architecture
Last updated
Was this helpful?

