Crates.io | chaindexing |
lib.rs | chaindexing |
version | 0.1.80 |
created_at | 2023-08-03 18:21:54.634571+00 |
updated_at | 2025-07-25 12:29:58.105063+00 |
description | Index any EVM chain and query in SQL |
homepage | |
repository | https://github.com/chaindexing/chaindexing-rs |
max_upload_size | |
id | 933920 |
size | 306,725 |
Index any EVM chain and query in SQL
Getting Started | Examples | Design Goals & Features | RoadMap | Contributing
📊 Here is what indexing and tracking owers of your favorite NFTs looks like:
use chaindexing::states::{ContractState, Filters, Updates};
use chaindexing::{EventContext, EventHandler};
use crate::states::Nft;
pub struct TransferHandler;
#[chaindexing::augmenting_std::async_trait]
impl EventHandler for TransferHandler {
fn abi(&self) -> &'static str {
"event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)"
}
async fn handle_event<'a, 'b>(&self, context: EventContext<'a, 'b>) {
let event_params = context.get_event_params();
let _from = event_params.get_address_string("from");
let to = event_params.get_address_string("to");
let token_id = event_params.get_u32("tokenId");
if let Some(existing_nft) =
Nft::read_one(&Filters::new("token_id", token_id), &context).await
{
let updates = Updates::new("owner_address", &to);
existing_nft.update(&updates, &context).await;
} else {
let new_nft = Nft {
token_id,
owner_address: to,
};
new_nft.create(&context).await;
}
}
}
A quick and effective way to get started is by exploring the comprehensive examples provided here: https://github.com/chaindexing/chaindexing-examples/tree/main/rust.
is_at_block_tail
flag to improve op heuristics for applicationsChaindexing is still young and optimized for ergonomics rather than raw throughput. The default configuration works well for real-time indexing of a few contracts, but historical backfills or very high-volume workloads may expose the following constraints:
blocks_per_batch
blocks every ingestion_rate_ms
milliseconds. With the defaults (450 blocks / 20 000 ms) this translates to roughly 22 blocks / s per chain. Tune these knobs to trade throughput for RPC cost.chain_concurrency
chains are ingested in parallel (default 4). Additional chains are processed sequentially.handler_rate_ms
(default 4 000 ms). If a contract emits thousands of events per block this cycle can lag behind ingestion.These limitations are passively being addressed; community benchmarks and pull requests are highly appreciated!
All contributions are welcome. Before working on a PR, please consider opening an issue detailing the feature/bug. Equally, when submitting a PR, please ensure that all checks pass to facilitate a smooth review process.