class: center, middle, inverse, title-slide # Covalent API ## via httr
### Omni Analytics Group --- ## Covalent API Covalent provides a unified API bringing visibility to billions of blockchain data points and it's free for everyone. To get started, you can simply sign up with an email address and get an API key. To learn more about Covalent, please visit https://www.covalenthq.com/. <p align="center"> <img src="images/covalent.png" width="300px"> </p> --- ## Covalent Documentation After you have created an account and obtained an API key, you should carefully read all the information provided in the [Covalent Documentation](https://www.covalenthq.com/docs/api/#overview). We will be following these two endpoints: ![](images/endpoint1.png) ![](images/endpoint2.png) Each parameter is bracketed with {}. Thus, we will need to fill in `chain_id` and `address`. --- ## httr In this case study, we will show you how to use `httr` package to obtain data through Covalent API. `httr` provide a wrapper for the curl package, customized to the demands of modern web APIs. First, we can use the `GET()` function to retrieve information from a url, which returns `response()` object. To get the content of this object, we will use the `content()` function along with the `parsed` parameter to convert it into an R object as follows. ```r library(httr) assets <- GET("https://api.covalenthq.com/v1/1/networks/aave/assets/") assets_parsed <- content(assets, "parsed") assets ``` ``` ## Response [https://api.covalenthq.com/v1/1/networks/aave/assets/] ## Date: 2021-04-30 13:43 ## Status: 503 ## Content-Type: text/html ## Size: 197 B ## <html> ## <head><title>503 Service Temporarily Unavailable</title></head> ## <body> ## <center><h1>503 Service Temporarily Unavailable</h1></center> ## <hr><center>nginx/1.19.6</center> ## </body> ## </html> ``` --- ## httr (continued...) Let's take a look at the structure of `assets_parsed`. Note that it gives information on each asset. ```r str(assets_parsed) ``` <p align="center"> <img src="images/example1.png"> </p> --- ## AAVE network assets Now that we have the data, we can use the following to obtain information on the first asset ```r assets_parsed$data$items[[1]] ``` .pull-left[ ![](images/example2.png) ] .pull-right[ ![](images/example3.png) ] --- ## GET transactions Recall `GET /v1/{chain_id}/address/{address}/transactions_v2/` from Covalent Documenation. To demonstrate, we fill `chain_id` with 1 as it represents Ethereum Network and `address` with `$atoken$contract_address` from previous slide. ```r transaction <- GET("https://api.covalenthq.com/v1/1/address/0xfc1e690f61efd961294b3e1ce3313fbd8aa4f85d/transactions_v2/?format=csv") transaction_parsed <- content(transaction, "parsed") dim(transaction_parsed) ``` ``` ## NULL ``` --- ## Transactions Data Let's take a look a the first few rows of the data. ```r head(transaction_parsed) ``` ![](images/example4.png) --- ## Conclusion You have just used Covalent API for the first time! Now you can explore more and obtain other data. <br> <br> <br> <p align="right"> <img src="images/Cut_outs/Cut_out_07.png" width="200px" height="200px"> </p>