Given a smart contract address passed as a parameter, this module returns the logs attached to the contract.
Tip: This tutorial teaches you how to build a Substreams from scratch.
Remember that you can auto-generate your Substreams module by usig the code-generation tools.
Running the Substreams
First, generate the Protobuf modules and build the Rust code:
makeprotogen
makebuild
Now, you can run the Substreams. The logs retrieved correspond to the 0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d (BoredApeYachtClub smart contract). To avoid iterating over the full blockchain, the following command starts at block 17717995 and finished at block 17718004. Therefore, only the BoredApeYachtClub smart contract logs that happened within this block range are printed.
substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_contract_events --start-block 17717995 --stop-block +10
In this example, you do not need to parse the parameters, as contract_address is the only string passed and you can use it directly. However, it is necessary to verify that the parameter is a valid Ethereum; this verification is performed by the verify_parameter function.
Then, you iterate over the events of the contract:
The .logs() function iterates over the logs of successful transactions within the block.
For every log of a successful transaction, you verify if its address matches the smart contract address (i.e. you verify if the log was actually emitted by the smart contract). For the comparison, both log.address() and contract_address are converted to Vec<u8>.
Every filtered log (i.e. every log that belongs to the smart contract) is mapped to a pb::eth::event::v1::Event struct, which was specified in the Protobuf definition.