Foundational Modules
The Injective Foundational Substreams contains Substreams modules, which retrieve fundammental data on the Injective blockchain.
You can use the Injective Foundational Modules as the input for your Substreams or subgraph.
The Foundational Modules are the base of the code generation tools provided by the Substreams CLI.
Before You Begin
Clone the Foundational Substreams GitHub repository, move to the injective-common
folder, and open it in an IDE of your choice (for example, VSCode).
The Foundational Modules
First, take a look at the Substreams manifest (substreams.yaml
), which contains the declaration of all the Injective Foundational Modules.
The
all_transactions
module provides access to all the transactions of the Injective blockchain. It receives a raw Injective block object as input (sf.cosmos.type.v2.Block
), and outputs a list of transactions object (sf.substreams.cosmos.v1.TransactionList
).The
all_events
module provides access to all the events in the Injective blockchain. It receives a raw Injective block as input (sf.cosmos.type.v2.Block
), and outputs a list of events object (sf.substreams.cosmos.v1.EventList
).The
index_events
module uses theall_events
module to create a cache where events are sorted based on theirtype
field. This cache helps in the performance of the module. You can read more about index modules in the correspoding documentation.The
filtered_events
allows you to use theindex_events
module (i.e. using the cache of events), to filter only the event types you are interested in. The string parameter passed as input is used to specify which events you want to consume.
Use The Foundational Modules
All this module are pre-programmed and ready to use in your Substreams or your subgraphs.
Use in a Substreams
Using another module as input for your Substreams is very easy: you just have to declare it in the manifest.
For example, the following declaration of the my_test_module
module receives the all_transactions
module as input:
Then, in the Rust handler declaration, you can simply receive the output object of the all_transactions
module:
Use in a Subgraph
You can easily import a Substreams module into a subgraph by defining it in the subgraph manifest (subgraph.yaml
):
Define the Substreams package (
.spkg
) containing the module of your choice.Define the module that you want to use (which must be contained in the package).
Define the file where you will create the handler.
Define the handler name.
Then, in the mappings.ts
file you can create the handleEvents
function.
Definition of the function, which receives the raw bytes of the Substreams.
Decode the bytes into the
EventList
Protobuf object, which is the output of the Substreams.
You can check out a full example in the USDT Exchange Volume tutorial
Last updated