Event Decoding Functions
Mirror provides 3 custom functions which can be in used within transforms to decode raw contract events during processing: _gs_log_decode
, _gs_tx_decode
and _gs_fetch_abi
.
_gs_log_decode
This function decodes Raw Logs data given a json string representing the ABI string. Since it is stateless it will scale very well across different pipeline sizes.
It will automatically use the matching event in the ABI, but partial ABIs that only contain the target event will also work.
Params
A string representing a json array of events and functions
Name of the column the dataset which contains a string containing the topics, comma separated.
Name of the column the dataset which contains a string containing the payload of the event.
Return
The function will output a nested ROW type with event_param::TEXT[]
and event_signature::TEXT
. If you’re planning on using a sink that doesn’t support nested ROWs, you may want to do a further transformation to unnest the result.
Examples
If you were using the Raw Logs source dataset, you would call this function passing your ABI and using the ‘topics’ and ‘data’ columns. For example:
You would then able to access both topics and data from the decoded column as decoded.event_params
and decoded.event_signature
in a second transform. See below for a complete example pipeline.
_gs_tx_decode
This function decodes Raw Traces data given a json string representing the ABI string. Since it is stateless it will scale very well across different pipeline sizes.
It will automatically use the matching function in the ABI, but partial ABIs that only contain the target function will also work.
Params
A string representing a json array of events and functions
Name of the column the dataset which contains a string containing the data sent along with the message call.
Name of the column the dataset which contains a string containing the data returned by the message call.
Return
The function will output a nested ROW type with the name of the function along with its inputs and outputs as arrays of strings. If you’re planning on using a sink that doesn’t support nested ROWs, you may want to do a further transformation to unnest the result.
Examples
If you were using the Raw Traces source dataset, you would call this function passing your ABI and using the ‘input’ and ‘output’ columns. For example:
You would then able to access both function and its inputs and outputs from the decoded columns as decoded.function
, decoded.decoded_inputs
and decoded.decoded_outputs
in a second transform. You can see an example in this guide.
_gs_fetch_abi
We provide a convenient function for fetching ABIs, as often they are too big to copy and paste into the yaml definition.
Params
The URL from where the ABI will be fetched
The type of url. Two types of value are accepted:
etherscan
for etherscan or etherscan-compatible APIsraw
for json array ABIs.
If you use etherscan-compatible APIs it’s highly recommended to include your own API key if you are using this function with a large pipeline. The amount of workers may result in the API limits being surpassed.
Examples
Following up on the previous example, we can replace the raw ABI definition by a call to basescan using the _gs_log_decode function:
In some cases, you may prefer to host the ABI yourself and retrieve it from your a separate server such as Github Gist:
Pipeline Example
Below is an example pipeline definition for decoding events for Friendtech contract in Base, make sure to visit this guide for a more in-depth explanation of this pipeline:
Was this page helpful?