📕
A closer look at Chi GasToken
  • What is Chi?
  • Prerequisites
  • First Covalent API call
  • Spot a mint/burn/transfer
  • Mints, burns and transfers
  • Closing thoughts
Powered by GitBook
On this page
  • Step 5: Get data for mints, burns and transfers
  • Step 6: Filter transactions with Primer

Was this helpful?

Mints, burns and transfers

PreviousSpot a mint/burn/transferNextClosing thoughts

Last updated 4 years ago

Was this helpful?

Step 5: Get data for mints, burns and transfers

The way to approach this is by using another Covalent endpoint, respectively GET /v1/{chain_id}/events/address/{address}/ .

As I mentioned before, it is better to first try it out directly in the browser on Covalent's page to see the response first and also have an overview of the parameters you can play with.

So let's do just that in order to analyze the first transaction so you can adjust the parameters accordingly and see how the final curl will look like. You'll be able to check the details for RESPONSE, RESPONSE HEADERS and CURLat the bottom:

A good start would be curl -X GET "https://api.covalenthq.com/v1/1/events/address/0x0000000000004946c0e9F43F4Dee607b0eF1fA1c/?starting-block=12344945&ending-block=12351433&key=ckey_a0b7bb48fadf475c8f1258a5c35" -H "Accept: application/json" \ and then analyze the first transaction in the items array:

5       {
6         "block_signed_at": "2021-05-01T00:01:31Z",
7         "block_height": 12344946,
8         "tx_offset": 1,
9         "log_offset": 18,
10         "tx_hash": "0xe417bff17f92fea22b873e1d7235934660486edbbfd4d977fa69a0de71f69925",
11         "_raw_log_topics_bytes": null,
12         "raw_log_topics": [
13           "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
14           "0x00000000000000000000000073fe72f0646795fed399754c6967fbfc510cf804",
15           "0x0000000000000000000000000000000000000000000000000000000000000000"
16         ],
17         "sender_contract_decimals": null,
18         "sender_name": null,
19         "sender_contract_ticker_symbol": null,
20         "sender_address": "0x0000000000004946c0e9f43f4dee607b0ef1fa1c",
21         "sender_address_label": "1inch Network: CHI Token",
22         "sender_logo_url": null,
23         "raw_log_data": "0x0000000000000000000000000000000000000000000000000000000000000005",
24         "decoded": {
25           "name": "Transfer",
26           "signature": "Transfer(indexed address from, indexed address to, uint256 value)",
27           "params": [
28             {
29               "name": "from",
30               "type": "address",
31               "indexed": true,
32               "decoded": true,
33               "value": "0x73fe72f0646795fed399754c6967fbfc510cf804"
34             },
35             {
36               "name": "to",
37               "type": "address",
38               "indexed": true,
39               "decoded": true,
40               "value": "0x0000000000000000000000000000000000000000"
41             },
42             {
43               "name": "value",
44               "type": "uint256",
45               "indexed": false,
46               "decoded": true,
47               "value": "5"
48             }
49           ]
50         }
51       },

What you'll notice is that decoded.paramscontains data that allows us to filter all the mints and burns and also it give use the valuefor the transaction. So let's start filtering our transactions!

Step 6: Filter transactions with Primer

Primeris a query language offered by Covalent that allows us to process and transform records retrieved with the Covalent API. You can read more about it here.

You will make use of Primer by using one of it's basic functionality by performing a simple match in order to filter our transactions:

So how do should this parameter be written, especially for deeply nested documents? The answer is simple, by inputting a <field>:<value> expression combined with the dot notation.

Let's try it out for filtering mints!

Since you need to access from apply an equality condition to retrieve all the transactions <from>:<0x0000000000000000000000000000000000000000>and access the decoded.params.0, our parameter for match will look like this: {"decoded.params.0.value":"0x0000000000000000000000000000000000000000"}

Tip! Increase the page-size when using Primer to make sure you are including a higher number of transactions (default is 100).

You'll make the API call and once you've received the response, iterate over the array with the mapfunction to extract only the values and then use the reducefunction to sum everything up:

Awesome! You now have to total value of Chi GasTokens that have been minted on the 1st of May, 2021: totalChiMintedValue = 67263

Now let's rinse and repeat the process for burns!

This means that the match parameter must be updated and filter by the transactions <to>:<0x0000000000000000000000000000000000000000>: {"decoded.params.1.value":"0x0000000000000000000000000000000000000000"} :

You did it again! The total value of Chi GasTokens that have been burned on the 1st of May, 2021 is totalChiBurnedValue = 10092

Saving the best for last, the Chi transfers! Since you've gained some experience working with Primer let's take your skills to the next level in order to extract the Chi transfers!

In order to define our primerquery string parameter, you'll have to take a look again at the Covalent docs about Primer and combine the $not (!== not equal to) comparison operator with the $and logical operator. This will retrieve all the transactions that aren't fromor tothe contract address 0x0000000000000000000000000000000000000000and this is how our query string looks like:

[{$match:{$and:[{$not:{decoded.params.0.value:0x0000000000000000000000000000000000000000}},{$not:{decoded.params.1.value:0x0000000000000000000000000000000000000000}}]}}]

Run the code with it once you've received the response, take the following steps: - filtertransactions that have the name "Transfer"; - iterate over the array with the mapfunction to extract the values; - use the reducefunction to sum everything up:

Congrats! You also have now the total value of Chi GasTokens that have been burned on the 1st of May, 2021:totalChiTransferredValue = 120182

If you are curious about finding out the answer to the same question but for a different network (e.g. Binance Smart Chain) all you need to do is change the chain_idparameter.

Amazing work! You've officially found the answer for our original question How many Chi tokens have been minted, burned and transferred on 1st of May, 2021 on the Ethereum network?, and that is: - total Chi minted: 67,263 - total Chi burned: 10,092 - total Chi transferred: 120,182