Abstract
This SNIP proposes a standardized collection of types and events for describing onchain data, as well as a compact serialization scheme for wire transmission, enabling the development of generic indexers for efficiently parsing data from arbitrary contracts.
Motivation
One of the challenges of blockchain application development is making chain data accessible to clients. Many applications adopt the pattern of creating offchain replicas (“indexes”) of onchain state, but without a shared standard most applications end up “rolling their own” non-interoperable tools for representing, fetching, storing, and serving onchain data. This leads to duplicated efforts and creates a high barrier to entry for new developers.
Standards such as ERC20 and ERC721 establish common interfaces for certain onchain data structures, but we have yet to see a general standard for describing arbitrary onchain data structures; a gap this SNIP is trying to fill.
A common source of type data for contracts is the ABI (application binary interface), which describes function inputs, outputs, and events declared by the contract. However, ABIs are not secure – only the hash is verified, and when deployed could be set to anything. We would prefer a self-documenting specification derived from events emitted by deployed contracts – a type of “write-ahead logging” converting onchain state into offchain representations.
In 2023, the Dojo framework implemented a gaming-specific introspect scheme tightly coupled to its own indexer; this worked well for the use-case but struggled to generalize as the user base expanded. This SNIP proposes a general standard for describing onchain state, splitting the solution into three parts: types, events, and data serialization rules.
The end goal is for Cairo developers to be able to integrate this functionality trivially, by way of an external framework, as in this example:
#[derive(Introspect, ISerde)]
struct Player {
health: u32,
strength: u32,
}
By adopting this SNIP, Cairo developers will be able to more easily make their onchain data available for offchain indexing, simplifying application development on Starknet.