Dealing with "logs" field in "Transaction"

When working with the Transaction data source, "logs" field is the most frequently used field. Since each transaction contains multiple event logs and it could be challenging to transform an array type data field to your desired format. But after this article, you will be an expert.

For example, we want to extract certain values through the logs "LogTrade" from Dydx protocol. (When a trade is made through Dydx, a log called "LogTrade" will be left on the blockchain)

Step 1: We get all the transactions which contain the "LogTrade" event logs.

Step 2: Since each transaction could contain multiple other logs, let's only keep "LogTrade" logs and remove the rest. You can use Project with a filter operator.

Step 3: Since some transactions might contain more than one "LogTrade" logs, we can make it even easier to work with by using Unwind to flatten the remaining array.

Finally, from this point on, you can use any field in the data easily.

Last updated