Sync traces to a database with the contract ABI using Mirror.
This guide explains how to decode traces on-the-fly using Mirror Decoding Functions within transforms in Mirror pipelines.
Install Goldsky's CLI and log in
Install the Goldsky CLI:
For macOS/Linux:
For Windows:
Go to your Project Settings page and create an API key.
Back in your Goldsky CLI, log into your Project by running the command goldsky login
and paste your API key.
Now that you are logged in, run goldsky
to get started:
In this guide we are going to show how to decode traces of a contract with Goldsky Mirror. We will use as example the Friendtech contract deployed in Base but the same logic applies to any other contract and chain for which there’s an availabe Raw Traces Direct Indexing dataset as per this list.
There are two important transforms in this pipeline definition which are responsible for decoding the contract; we’ll explain how they work in detail. If you copy and use this configuration file, make sure to update:
secret_name
. If you already created a secret, you can find it via the CLI command goldsky secret list
.decoded_logs.friendtech
.Let’s start analyzing the first transform:
Looking at the Raw Traces schema we see there are standard traces columns such as id
, block_number
and transaction_hash
. Since the columns
input
and output
are encoded we need to make use of the _gs_tx_decode to decode the data. This function takes the following parameters:
The contract ABI: rather than specifying ABI directly into the SQL query, which would made the code considerably less legible, we have decided to make use of the _gs_fetch_abi function to fetch the ABI from the BaseScan API but you could also fetch it from an external public repository like Github Gist if you preferred.
input
: as a second argument which refer to the data sent along with the message call.
output
: as a third argument which refer to the data returned by the message call.
We are storing the decoding result in a new column called decoded
which is a nested ROW with the properties event_param::TEXT[]
and event_signature::TEXT
. We create a second transform that reads from the resulting dataset of this first SELECT query to access the decoded data:
Notice how we add a filter for decoded IS NOT NULL
as a safety measure to discard processing potential issues in the decoding phase.
As a last step, to deploy this pipeline and start sinking decoded data into your database simply execute:
goldsky pipeline apply <yaml file>
In this guide we have explored an example implementation of how we can use Mirror Decoding Functions to decode raw logs and stream them into our PostgreSQL database.
This same methodology can be applied to any contract of interest for any chain with raw_log
and raw_traces
Direct Indexing datasets available (see list).
Goldsky also provides alternative decoding methods:
decoded_logs
and decoded_traces
Decoding contracts on the flight is a very powerful way of understanding onchain data and making it usable for your users.
Can't find what you're looking for? Reach out to us at support@goldsky.com for help.
Sync traces to a database with the contract ABI using Mirror.
This guide explains how to decode traces on-the-fly using Mirror Decoding Functions within transforms in Mirror pipelines.
Install Goldsky's CLI and log in
Install the Goldsky CLI:
For macOS/Linux:
For Windows:
Go to your Project Settings page and create an API key.
Back in your Goldsky CLI, log into your Project by running the command goldsky login
and paste your API key.
Now that you are logged in, run goldsky
to get started:
In this guide we are going to show how to decode traces of a contract with Goldsky Mirror. We will use as example the Friendtech contract deployed in Base but the same logic applies to any other contract and chain for which there’s an availabe Raw Traces Direct Indexing dataset as per this list.
There are two important transforms in this pipeline definition which are responsible for decoding the contract; we’ll explain how they work in detail. If you copy and use this configuration file, make sure to update:
secret_name
. If you already created a secret, you can find it via the CLI command goldsky secret list
.decoded_logs.friendtech
.Let’s start analyzing the first transform:
Looking at the Raw Traces schema we see there are standard traces columns such as id
, block_number
and transaction_hash
. Since the columns
input
and output
are encoded we need to make use of the _gs_tx_decode to decode the data. This function takes the following parameters:
The contract ABI: rather than specifying ABI directly into the SQL query, which would made the code considerably less legible, we have decided to make use of the _gs_fetch_abi function to fetch the ABI from the BaseScan API but you could also fetch it from an external public repository like Github Gist if you preferred.
input
: as a second argument which refer to the data sent along with the message call.
output
: as a third argument which refer to the data returned by the message call.
We are storing the decoding result in a new column called decoded
which is a nested ROW with the properties event_param::TEXT[]
and event_signature::TEXT
. We create a second transform that reads from the resulting dataset of this first SELECT query to access the decoded data:
Notice how we add a filter for decoded IS NOT NULL
as a safety measure to discard processing potential issues in the decoding phase.
As a last step, to deploy this pipeline and start sinking decoded data into your database simply execute:
goldsky pipeline apply <yaml file>
In this guide we have explored an example implementation of how we can use Mirror Decoding Functions to decode raw logs and stream them into our PostgreSQL database.
This same methodology can be applied to any contract of interest for any chain with raw_log
and raw_traces
Direct Indexing datasets available (see list).
Goldsky also provides alternative decoding methods:
decoded_logs
and decoded_traces
Decoding contracts on the flight is a very powerful way of understanding onchain data and making it usable for your users.
Can't find what you're looking for? Reach out to us at support@goldsky.com for help.