Search
Generic filters
Share on facebook
Share on twitter
Share on linkedin

How to Build with the Covalent API

Even though Ethereum remains the leading chain for deploying dApps, NFTs, and smart contracts, it is clear that cross-chain interoperability is inevitable, which Covalent has recognized. As such, Covalent’s API enables blockchain developers to use the indexed data from multiple blockchain networks that this large-scale aggregator Covalent has gathered. Moreover, Moralis now offers its users a Covalent Moralis plugin, enabling programmers to use the Covalent API when building Web3 applications. Therefore, many developers who want to learn how to build with the Covalent API should pay close attention as we’ll dive deep into the topic of Covalent, Moralis, the plugin, and how these elements combined can future-proof your work.

In addition, Moralis, which is known as “Firebase for crypto”, is another excellent tool that has cross-chain interoperability in its DNA. This ultimate Web3 development platform supports most of the major reputable chains. Moreover, Moralis’ SDK provides everything you need to fully cover blockchain-related backend needs with short snippets of code. As such, every JavaScript-proficient programmer can create incredible multi-chain Web3 applications in a matter of minutes.

Furthermore, thanks to the Covalent Moralis plugin, developers can now make the most out of both these cross-chain operable tools. Moreover, this article will show you how to build with the Covalent API quickly and easily. Moving forward, you’ll learn how to install the Covalent Moralis plugin to get going. Then, we’ll also take a look at some specific endpoints. However, since some of you might have heard of Covalent for the first time, we’ll start by answering the question of “what is Covalent?” before showing you how to build with the Covalent API.  

What is Covalent?

No, we are not talking about the covalent bond, so no need to worry; there will be no chemistry talk. Instead, Covalent is an excellent crypto project with a clear vision that the future of blockchain will be on multiple chains. Essentially, Covalent is a large-scale data aggregator, which helps developers access blockchain’s network data. It features support for many leading blockchain networks, including Ethereum, Avalanche, and Polygon (full list displayed in the image below).

Moreover, Covalent converts hundreds of billions of blockchain-based data points that are otherwise difficult to access into actionable insights. By “scanning” various sources, including chains, smart contracts, nodes, and multiple data feeds, Covalent gathers huge amounts of valuable data and serves it to developers on a silver platter. Through a single accessible API (the Covalent API), developers get to access all this indexed data. As such, it empowers developers to get better oversight of the blockchain ecosystem and more efficiently allocate resources in their development process. Moreover, thanks to the Covalent Moralis plugin, it is now easier than ever to build with the Covalent API.

Nonetheless, Covalent is already the “behind-the-scenes” data infrastructure of many popular DeFi and NFT projects. Fortunately, by using Moralis and its Covalent plugin, you can create your own crypto project without breaking a sweat or draining your pockets, and you also get to bypass all of the limitations of RPC nodes. With that said, you are ready to learn how to build with the Covalent API.

How to Build with the Covalent API using Moralis

In case you are new to Moralis, let us remind you that it is the ultimate Web3 development platform delivered by developers for developers with a goal to contribute to the adoption of blockchain technology, which (if used properly) can make the world a much better place. With that said, there are some setups that you need to complete before you can start to build with the Covalent API. We cover the exact steps in the subsections below.

Create a Moralis Server

In order to build with the Covalent API using Moralis, you need to install the Covalent Moralis plugin; however, to do that, you must first create your Moralis server. Here’s how to go about it:

  1. Create Your Moralis Account – If you haven’t created your free Moralis account yet, make sure to do so now. Just click the link above. Then, enter your email address, and create your password (remember to confirm your email address by clicking the confirmation link that will be sent to your email address). In case you already have an active Moralis account, log in.
      
  2. Create a Moralis Server – Once logged in, you’ll access your Moralis admin area. Click on the “Servers” tab and then the “+ Create a new Server” button in the top-right corner (see the image below). Next, you’ll get to select the network type (mainnet or testnet). When dealing with example projects, we recommend selecting the “Testnet Server” option (see our Ethereum testnet guide). However, once you’re ready to make fully functional dApps live, you’ll want to select the “Mainnet Server” option.


A pop-up window that will appear will prompt you to enter the server name (this can be anything you want), select region, network type, and chain(s). To spin up your server, click on “Add Instance”:

Note: With your server created, you are all set to install the Covalent Moralis plugin. However, since you most likely want to build with the Covalent API, we recommend completing the following two steps to gain full Moralis functionality.

Access Moralis’ SDK Functionality 

With your Moralis server created, you are ready to access the full power of Moralis by connecting it with your code. Fortunately, only two simple steps are required to do this:

  1. Access Server Details – To access your server’s details, click on “View Details” next to your server name. 


Next, a pop-up window that contains all the information you need will appear:

  1. Initialize Moralis – Now, populate your “.js”, “.html” (if you are starting from scratch), or the “.env” file (if you are using the ultimate Web3 boilerplate) with the Moralis server details (application ID and server URL) to obtain the required backend functionality covered by Moralis. Moreover, do so inside your code editor (we normally use Visual Studio Code):

Note: Make sure that you use the details of your particular server and NOT the ones from the image above.

How to Build with the Covalent API Using the Covalent Moralis Plugin

By now, you know that the key to being able to build with Covalent’s API in the simplest way possible is by using Moralis. However, to give your particular server “Covalent API access”, you need to install the Covalent Moralis plugin. Moreover, since you already have your server created (this is a prerequisite to installing plugins), it will be easy to add the plugin. Just follow the steps below to complete this part of the setup process.

  1. For starters, click on the “Plugins” button on your Moralis server. On the following step, click on the “Go to Plugin Store!” button: 
  1. To install the Covalent Moralis plugin, select that plugin by clicking its “Read More” button:
  1. Now, you’ll finally have an option to install the selected plugin. Just click on the “Install the plugin” button in the top-right corner:
  1. After clicking on the “Install the plugin” button, you will be redirected to your Moralis admin area to complete the plugin’s installation process. This is the window you’ll see:
  1. From the drop-down menu, select the server you’ve created in the previous subsection. Then, click on ”Confirm”. As such, this is what you should see:
  1. As you can see, you need to obtain a Covalent API key. Fortunately, this is available on Covalent’s official website. Once on the website, click on “Get an API key”:
  1. Enter your information and click on the “Create account” button:
  1. Click on the link in the confirmation email and name your organization. Then you’ll be able to obtain a Covalent API. Copy and paste it in the designated area (step five). Then click on the “Install” button.

After successfully completing the installation, you should be able to see the Covalent plugin listed among your server’s plugins (as shown below): 

Build with the Covalent API – Exploring Endpoints

At this point, you should have everything set up correctly, which means that you are ready to build with the Covalent API. We made the detailed instructions for working with this feature, including the endpoints, available at GitHub as well as on the Covalent Moralis plugin’s page. Thus, make sure to explore the details there. However, to make things even simpler for you, here are the endpoints:

  • Get Block – Using chain ID and block height returns the block.
interface GetBlockDto {
  chainId: number;
  blockHeight: string;
}

await Moralis.Plugins.covalent.getBlock(GetBlockDto);
  • All Contract Metadata – Using chain ID, returns a list of all contracts on a blockchain along with their metadata.
interface GetAllContractMetaDto {
  chainId: number;
  pageNumber?: number;
  pageSize?: number;
}

await Moralis.Plugins.covalent.getAllContractMetadata(GetAllContractMetaDto);
  • Get Block Heights – Using chain ID, start date, and end date, returns all the block height(s) of a particular chain within a date range.
interface GetBlockHeightsDto {
  chainId: number;
  blockHeight: string;
  startDate: string;
  endDate: string;
  pageNumber?: number;
  pageSize?: number;
}

await Moralis.Plugins.covalent.getBlockHeights(GetBlockHeightsDto);
  • Return Chains – Returns a list of all chains.
interface GetChainsDto {}

await Moralis.Plugins.covalent.getChains(GetChainsDto);
  • Chain Statuses – Returns a list of all chain statuses.
interface GetChainStatusesDto {}

await Moralis.Plugins.covalent.getChainsStatuses(GetChainStatusesDto);

Token Transaction Endpoints

  • Get Changes in Token Holders – Using chain ID and wallet address returns a paginated list of token holders and their current/historical balances.
interface GetChangesInTokenHoldersDto {
  chainId: number;
  address: Address;
  startingBlock: string;
  endingBlock: string;
  pageNumber?: number;
  pageSize?: number;
  quoteCurrency?: string;
}

await Moralis.Plugins.covalent.getChangesInTokenHolerBetweenBlockHeights(GetChangesinTokenHoldersDto);
  • ERC-20 Token Transactions for Address – Using chain ID, user address, and transaction hash returns all ERC-20 token contract transfers.
interface GetErc20TokenTransactionsForAddressDto {
  chainId: number;
  address: Address;
  tokenAddress: Address;
  quoteCurrency?: string;
  pageNumber?: number;
  pageSize?: number;
}

await Moralis.Plugins.covalent.getErc20TokenTransfersForAddress(GetErc20TokenTransactionsForAddressDto);
  • Historical Portfolio Value Over Time – Using chain ID and wallet address returns wallet value for the last 30 days at 24-hour interval timestamps.
interface GetHistoricalPortfolioValueOverTimeDto {
  chainId: number;
  address: Address;
  quoteCurrency?: string;
}

await Moralis.Plugins.covalent.getHistoricalPortfolioValueOverTime(GetHistoricalPortfolioValueOverTimeDto);
  • Get Log Events by Contract Address – Using chain ID and contract address, returns a paginated list of decoded log events emitted by a particular smart contract.
interface GetLogEventsByContractAddressDto {
  chainId: number;
  contractAddress: Address;
  startingBlock: string;
  endingBlock: string;
  pageNumber?: number;
  pageSize?: number;
}

await Moralis.Plugins.covalent.getLogEventsByContractAddress(GetLogEventsByContractAddressDto);
  • Receive Log Events by Topic – Using chain ID and topic, returns a paginated list of decoded log events.
interface GetLogEventsByTopicDto {
  chainId: number;
  topic: Topic;
  endBlock: string;
  secondaryTopic?: Topic;
  startBlock?: string;
  address?: Address;
  pageNumber?: number;
  pageSize?: number;
}

await Moralis.Plugins.covalent.getTokenHoldersByTopic(GetLogEventsByTopicDto);

Fungible and Non-Fungible Tokens Endpoints

  • NFT Token IDs for Contract – Using chain ID and contract address returns a list of all token IDs for the NFT contract on the blockchain.
interface GetNFTTokenIDsForContractDto {
  chainId: number;
  contractAddress: Address;
  pageNumber?: number;
  pageSize?: number;
}

await Moralis.Plugins.covalent.getNftTokenIdForContract(GetNFTTokenIDsForContractDto);
  • Get NFT Transactions for Contract – Using chain ID, contract address, and token ID, returns a list of transactions.
interface GetNFTTransactionsForContractDto {
  chainId: number;
  contractAddress: Address;
  tokenId: string;
  pageNumber?: number;
  pageSize?: number;
}

await Moralis.Plugins.covalent.getNftTransactionsForContract(GetNFTTransactionsForContractDto);
  • NFT External Metadata for Contract – Using chain ID, contract address, and token ID fetches and returns the external metadata. It supports both ERC-721 and ERC-1155 standards.
interface GetNFTExternalMetaForContractDto {
  chainId: number;
  contractAddress: Address;
  tokenId: string;
}

await Moralis.Plugins.covalent.getNftExternalMetadataForContract(GetNFTExternalMetaForContractDto);
  • Get Token Balances for Address – Using chain ID and wallet address returns current token balances along with their spot prices.
interface GetTokenBalancesForAddressDto {
  chainId: number;
  address: Address;
  quoteCurrency?: string;
}

await Moralis.Plugins.covalent.getTokenBalancesForAddress(GetTokenBalancesForAddressDto);
  • Get Token Holders as of any Block Height – Using chain ID and wallet address returns a paginated list of token holders. If block height is omitted, the latest block is used.
interface GetBlockTokenHoldersDto {
  chainId: number;
  contractAddress: Address;
  blockHeight: string;
  pageNumber?: number;
  pageSize?: number;
  quoteCurrency?: string;
}

await Moralis.Plugins.covalent.getBlockTokenHolders(GetBlockTokenHoldersDto);

More Transaction Endpoints

  • Get Transactions – Using chain ID and transaction hash returns the transaction data with their decoded event logs.
interface GetTransactionDto {
  chainId: number;
  transactionHash: TransactionHash;
}

await Moralis.Plugins.covalent.getTransaction(GetTransactionDto);
  • Get Transactions for Address – Using chain ID and wallet address returns all transactions along with their decoded log events.
interface GetTransactionsForAddressDto {
  chainId: number;
  address: Address;
  quoteCurrency?: string;
  pageNumber?: number;
  pageSize?: number;
}

await Moralis.Plugins.covalent.getTransactionsForAddress(GetTransactionsForAddressDto);

Time to Build with the Covalent API

To build with the Covalent API, you simply copy and paste any of the above endpoints into your code. Of course, you need to complete all of the setup steps given in this article first. Moreover, you also need to use “Moralis.initPlugins()” in your code to ensure that the above-installed plugin is initiated. 

For an even better understanding of the topic at hand, we recommend watching the video below starting at 3:48, where a Moralis expert will guide you through the setup. Moreover, he will also show you several of the above endpoints in action. 

How to Build with the Covalent API – Summary

At this point, you should know that Covalent is a large-scale data aggregator and that by using the Covalent API, you get to access on-chain data across a wide range of chains. Moreover, you should also know how to build with the Covalent API. Furthermore, you’ve learned that by using Moralis’ SDK in combination with the Covalent Moralis plugin, you get to build all sorts of dApps and also access all of the data provided by Covalent. Now, that’s extremely powerful as it enables you to develop cross-chain dApps by simply copying and pasting short snippets of code.

In case you need some additional free crypto education, make sure to visit the Moralis YouTube channel and the Moralis blog. On both of these outlets, you can also find countless example projects, which are a great way to get some ideas and master the simplicity that Moralis offers. Some of the latest topics show you how to build cross-chain dApps, how to host a dApp, how to build a decentralized messaging app, how to create an OpenSea clone, how to mint NFTs without gas fees, and much more. Furthermore, in case you are serious about going full-time crypto, we encourage you to explore courses at Moralis Academy

December 8, 2021
Moralis Blog
Moralis Blog
Become a Moralis Mage
Get the latest information about Moralis Web3 in your email
Search
Generic filters
Related Articles
Become a Web3 Expert
Subscribe to our newsletter and get our E-book Web3 Speed run for FREE