Filter Instructions
The map_filter_instructions
module of the Solana Substreams Explorer extracts instruction of a given Program ID. For example, consider that you want to extract all the Stake11111111111111111111111111111111111111
instructions.
Run the Substreams
Run From Source Code
In the substreams-explorer
project, move to the solana-explorer
folder, which contains the source of the Solana Substreams. Then, build the Rust code:
Now, you can run the Substreams by using the substreams gui
command. To avoid iterating over the whole blockchain, the following command extracts instructions from the Stake Program only at block 243830383
:
In the Output
screen of the GUI, you can see two Stake11111111111111111111111111111111111111
instructions were retrieved at block 243830383
:
The map_filter_instructions
allows you to filter any Program ID, and this is configurable as a parameter in the Substreams Manifest (substreams.yaml
):
You can replace Stake11111111111111111111111111111111111111
by any instruction of your choice.
Run the Package From the Substreams Registry
The Solana Explorer package is also available on the Substreams Registry. You can run it by using the following command, achieving the same result:
Inspect the Code
The map_filter_instructions.rs
file contains the source of the module. The output of the Substreams module is the Instructions
object, which is defined in the /proto/transactions.proto
file of the project. This is a custom object defined by the user, and you can modify at your will.
Let's inspect the module function:
The
parse_filters_from_params
function parses the parameters passed to the module. In this example, the parameter passed is defined in thesubstreams.yaml
file asprogram_id=Stake11111111111111111111111111111111111111
.Iterate over the transactions of the blocks.
Extract the Message object, which contains relevant information, such as the instructions of the trasaction.
Get accounts of the transaction (the
resolved_accounts()
method contains also accounts stored in the Address Lookup Tables).Iterave over the instructions.
Use the
apply_filter
function to only keep instruction whereprogram_id=Stake11111111111111111111111111111111111111
.Create an
Instruction
object, which will be the output of the Substreams. This object is declared as a Protobuf in theproto
folder of the project.
Last updated