Mints, burns and transfers
Last updated
Was this helpful?
Last updated
Was this helpful?
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 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 CURL
at the bottom:
What you'll notice is that decoded.params
contains data that allows us to filter all the mints and burns and also it give use the value
for the transaction. So let's start filtering our transactions!
Primer
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"}
You'll make the API call and once you've received the response, iterate over the array with the map
function to extract only the values and then use the reduce
function 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!
[{$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:
- filter
transactions that have the name "Transfer";
- iterate over the array with the map
function to extract the values;
- use the reduce
function 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
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
A good start would be curl -X GET "
" -H "Accept: application/json" \
and then analyze the first transaction in the items array:
Primer
is 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 .
In order to define our primer
query string parameter, you'll have to take a look again at the 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 from
or to
the contract address 0x0000000000000000000000000000000000000000
and this is how our query string looks like: