INTERACTING WITH COVALENT API — For Beginners

Joseph Appolos
7 min readMay 30, 2021

--

The popularity of the Covalent API in the DeFi market has been growing on a daily basis and even as simple and easy it is to use, a lot of people have had more questions than there’s time to answer regarding the use of different aspect of the the the API.

This article will help to guide you in exploring the amazing features and enormous data contained in then COVENT API especially if you’re a newbie to crypto.

Overview

To access the API docs, simply click on “Developer” at the top of the page when you open the COVALENT official page and then click on ‘API reference’ from the drop down menu.

How to acces Covalent API docs

The COVALENT API has two endpoints; namely

  • Class A — endpoints that return enriched blockchain data to all blockchain networks eg: balances, transaction, log events, etc.
  • Class B — endpoints for a specific protocol on a blockchain, eg: AAVE is Ethereum-only and is not applicable to other blockchain networks.

Apart form these major ones, Covalent also have pricing endpoints which returns historical prices for contract address in a particular Chain_ID and quote currency.

Different endpoints of the COVALENT API

Class A Endpoints

With the class A endpoints you can get:

  • Token balances
  • Historical portfolio value overtime
  • Transaction details ERC20 token transfers
  • A block
  • Block heights
  • Log events (by contract address and by topic hash(es)
  • NFT token balances
  • External NFT metadata
  • NFT token IDs, transactions
  • Changes in token holders between two block heights
  • Token holders as of a block height
  • All contract metadata
  • A transaction
  • All chains and all chain statuses.
Data retrievable from the Class A endpoints.

Let’s see how to interact with the class A endpoints. All the data of items on the list above can be obtained within seconds.

The steps

  1. The first thing to do to have full access of the data in the API is to create an “API KEY”. How do you do this? Click on ‘developer’ on the top center corner of the official website ,then click on ‘Free API key’ to create your account.
creating An API key 1

Fill in the details that appears on the next page and hit and hit the ‘create account’ button, or click on ‘login’ if you have an account before. Once your API key is created, you’ll see it on the next page.

Filling your details for your API Keys.

You have to test your key to make sure everything works fine before proceeding to use it. If there’s any issue (most times there are none) please contact COVALENT support (contact@covalenthq.com or head over to discord). The API key can be used to authenticate against the COVALENT API. When authenticating, use the API key as the username and a blank password. Once this step is complete, then you can go ahead to set your API key.

What your API key looks like.

Make sure to set your API on the docs page before making any query, this helps to authenticate it. Even though the API can still be used even without your API key as there is a default API key, it is advisable to create yours for a smoother experience.

How to set up your key after creating.

2) Select the data you want to view from the list on the left hand side under class A. Lets select ‘Get token balances for address’ for the sake of this tutorial. This return a list of all the tokens and NFT token balances along with their current spot prices.

Selecting an option from the list A class a endpoints.

3) Enter the Chain_ID (this is a setting that helps you to switch from one blockchain to another) of the blockchain you want to interact with. The chain_ID of the different blockchaind that are supported by COVALENT are listed below

Ethereum Mainnet…… 1,

Polygon/Matic Mainnet..... 137,

Polygon/Matic Testnet….. 80001,

Binance Smart Chain..... 56,

Avalanche C-Chain Mainnet…. 43114,

Fuji C-Chain Testnet.... 43113,

Fantom Opera Mainnet….. 250.

The Chain_ID entered will query that blockchain alone and return balances of the tokens on the address entered for that blockchain.

Different Chain_ID for Different blockchains supported by COVALENT.

4) Enter the wallet address that you want to check (this option comes immediately after the CHain_ID option).

5) Don’t enter any other data in any of the options available at this stage of learning. These options are for more advanced users.

These options should be left blank(except for advanced users).

6) Scroll down and hit TRY. The result of your search will be displayed instantly for your view on the web page.

7) The ‘balance’ (which is the actual amount of the token in the address) displayed should be divided by 10¹⁸ to get the actual balance.

Results returned by the API

The ‘quote rate’ represents the price of the token, the ‘quote’ represents the amount in USD of the token present in the wallet.

The results explained.

If you desire to check NFT data on the same wallet address, then this is what you should do:

8) After completing steps 3 and 4 above, type the word “true" on the ‘nft boolean’ option. This returns both token balances and NFT balances of the address in question.

setting to return NFT balances

9) On the view page, scroll down to where the said data is displayed to view. All the NFT data that the address contains will be displayed along with the token balances of the wallet.

Result returned for NFT balance

This procedure is similar to the procedures undergone when other class A endpoints are considered. These data can be used in several ways depending on your degree of expertise, ranging from data visualization, development of apps, building a DeFi protocol and so on.

Now try retrieving data from other class A endpoint, you’ll see how easy it becomes.

Class B Endpoints

As mentioned earlier, this endpoints return data on a specific protocol on a specific blockchain. For example, I want to want get the number of and details(including time stamps) of liquidity transactions of an address on Sushiswap, I will select “Get Sushiswap address exchange liquidity transactions” from Class B endpoints. It’s very explanatory and easy to understand. Some f the data that can be retieved using Class B endpoints are:

  • Exchange liquidity transactions of an address for a specific protocol.
  • Exchange balances of an address for a specific protocol.
  • Address balances for a particular protocol.
  • Address activities for a particular protocol, etc.
Some data of Class B endpoint

Here are the steps

  1. After selecting the endpoint of interest (that is the protocol and the type of data), enter the chain_ID of the respective protocol (some protocols are launched on multiple blockchains, just input the chain_ID of the one of interest. For this tuttorial, lets ‘get the network assets of uniswap’.
  2. What is required for you to input depends on the data that wants to be viewed. For this case, here’s what needs to be inputed:
input options to get network assets of uniswap

3. Input the the ticker (this is like the initials of the token).

4. Hit the TRY button and get your results in few seconds

Ethereum network assets of Uniswap displayed.

A lot more can be done with the Class B endpoints, try out some few runs on your own.

Note: The steps listed in this tutorial is for beginners and hence the need to keep it simple and straight forward . The COVALENT API can be applied in more advance, enhanced and streamlined search. For example; the highest swap that was made in an aggregator — say 1inch, the total number of users of a DeFi protocol (such as AAVE), Creator and all holders(including recent and past) of an NFT token since birth and so much more. This will be discussed in subsequent articles, stay glued.

--

--

No responses yet