Typescript SDK Quickstart
The Covalent SDK is the fastest way to integrate the Unified API for working with blockchain data. The SDK works with all supported chains including Mainnets and Testnets.
Install the SDK
You can use yarn
or npm
to install the @covalenthq/client-sdk
package.
Note: Use Node v18 and above for best results.
yarn add @covalenthq/client-sdk
Import the client
The CovalentClient
class provides a typesafe, easy to use helper functions and classes to use the Unified API.
Some examples of classes include:
SecurityService
: Access to the token approvals endpointsBalanceService
: Access to the balances endpointsBaseService
: Access to the address activity, log events, chain status, and block retrieval endpointsNftService
: Access to the NFT endpointsPricingService
: Access to the historical token prices endpointTransactionService
: Access to the transactions endpointsXykService
: Access to the XY=K suite of endpoints
import { CovalentClient } from "@covalenthq/client-sdk";
Make your first call
First initialize the client with your Covalent API key.
Next call the
getTokenBalancesForWalletAddress
function in theBalanceService
with the two required arguments for the chain name and the address (note that ENS resolution works, so you can trydemo.eth
).
const ApiServices = async () => { // Replace with your Covalent API key const client = new CovalentClient("YOUR_API_KEY"); const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS"); if (!resp.error) { console.log(resp.data); } else { console.log(resp.error_message); } }
Use the advanced features
The SDK comes with functionality that dramatically improves the developer experience. For example:
Auto pagination using async generators
Native use of BigInts
Concurrency limiting and exponential back-offs to retry rate-limited requests
Debugger mode for response times, URLs called and HTTP status codes
Happy coding!
Explore GoldRush
GoldRush is the modular block explorer kit. It comes with two components:
GoldRush Templates - out-of-the-box templates for wallet UIs, NFT Galleries, and more.
GoldRush Kit - beautifully designed open-source React components for your application.