Introduction
In this tutorial, we'll walk through on how to decode a Compound V2 cETH Mint Transaction using the innovative GoldRush Decoder. This process is useful for anyone looking to understand complex transaction events, whether for blockchain analytics, creating GoldRush UI components, or any other use case. We'll start with outlining the essential tools and dependencies needed for this task, followed by a step-by-step guide through the decoding process, ensuring that you have a clear and concise understanding of each phase.
Prerequisites
Make sure you have yarn installed on your computer.
Recommended to use Postman or a similar API platform for testing the decoded response.
Clone the GoldRush Decoder GitHub repository.
Tutorial: Using GoldRush Decoder to Decode a Compound V2 cETH Mint Transaction
Protocol Configuration
Looking at the README from the
GoldRush Decoder repo, we know the first step in order to decode cETH events is to open a terminal in your IDE and run the following:
In the terminal, you should see a prompt asking for the protocol name which in this case will be compound-v2.
The program will recognize the protocol does not currently exist so it will create a new config template. It will ask for the contract address which in this case is 0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5.
It will then ask if this contract is a Factory Address, which is defined as a contract that is responsible for deploying other contracts for the protocol (e.g. Uniswap Factory Contract, Compound Deployer, etc.). In this case, we will be selecting no.
Lastly, it will ask for the chain name the contract is deployed on, which in this case will be
eth-mainnet
For a reference with all the supported chain names, please check out the
supported networks page on the GoldRush docs.Finally, the program will have created a new folder with a decoder, test and folder for contract abis.
Check the configs file to understand the structure of the information we just provided.
Acquire and Set Up ABI
Once we have the protocol folder set up we will need the ABI for the contract we want to decode events for (Note: Many contracts are implemented as proxies of other contracts so make sure the ABI you are using has the event of interest).
In order to find the ABI, you can go to the block explorer, input the contract address, and click the contract field (usually next to transactions, token transfers etc.)
Scroll down to the ABI section, copy the entirety of it, and paste it into the compound-v2.abi.json
file in JSON format.
Lastly, we are going to rename the ABI file be the same name as the contract which is CEther.
Modify the Decoder File
Now that we have the ABI in place, we can begin modifying the compound-v2.decoder.ts
file.
Open up the file and make sure the ABI is pointing to the right file at the top.
We can replace the <EVENT NAME>
portion of the code with the name of the event we are looking to decode. It should be spelt in the exact same format as it is in the ABI, except in the return function where it can be formatted in a more UI-friendly manner. In our case, we will be adding in the “Mint” value.
In the args parameter we want to list out the topic/data field names and types in the order the appear in the ABI, the finished code thus far will look like this:
Now we will construct the details
and Token
constant variables.
It is worth checking the README again to see the standardized variables format for ERC-20 token information along with the details constant variable format for any information that does not fit into tokens or nft.
We will only be using the details constant for this example, but within the repo there are many examples of other constants being used.
For the Event details constant we have to specify the heading of each data field, reference the appropriate field in the decoded object and the appropriate data type (will be either address or test).
Once the details constant is defined we want to pass it in the return object after protocol
and modify the action and category to the most relevant types (the different constants for actions and category can be found in decoder.constants.ts
).
Finally the finished code will look like this:
Prepare API Request in Postman
Once the decoding logic is inserted, we can check to see if the response is appropriate. Save the decoder file and open up Postman.
The body of the request should be:
In the decoder terminal, type in yarn dev
and the program will evaluate the decoder. If there are no errors we can make the API request, and the response for the log event in question should be the decoded response.
Looking through the entire decoded transaction, we can see the transfers of WETH and CEther already decoded as well due to the ERC-20 standard being decoded in the fallbacks
folder. That means we do not have to decode the transfers of assets in the Mint event decoder as they will already be decoded with the appropriate metadata and USD values.
Run the Decoder and Test
Finally, we will be adding a test for the event we just decoded in the compound-v2-tests.ts
.
We can replace <EVENT NAME>
with the name of the event we passed in the return function in the decoder file and we can replace <ENTER TX HASH FOR TESTING>
with the transaction hash we used in API request above.
We want to replace the last two lines of the test from this:
Note: We want to add individual tests for each constant that is returned by the decoding function. For example, if our response, in addition to the 3 values in details also returned 2 token values and 1 NFT value, our tests would look like this:
The finished code for the compound test will look like:
Once the test has been configured, we want to run the test locally and then make a PR to the main branch.
To run the tests locally run the following command in your terminal:
If the tests pass, we can make more decoding functions and tests and then push the changes to a PR!
Conclusion
This tutorial has provided a detailed guide on using the GoldRush Decoder to decode a Compound V2 cETH Mint Transaction. The process involves setting up the necessary environment, fetching and configuring the ABI, modifying the decoder file, and finally testing the decoding logic using Postman. By following these steps, you can successfully use GoldRush Decoder to decode blockchain events and gain deeper insights into transaction data!