@covalenthq/client-sdk 0.2.9 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -46
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.js +5226 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/services/BalanceService.d.ts +543 -0
- package/dist/cjs/services/BaseService.d.ts +357 -0
- package/dist/cjs/services/CovalentClient.d.ts +65 -0
- package/dist/cjs/services/NftService.d.ts +620 -0
- package/dist/cjs/services/PricingService.d.ts +88 -0
- package/dist/cjs/services/SecurityService.d.ts +158 -0
- package/dist/cjs/services/TransactionService.d.ts +457 -0
- package/dist/cjs/services/XykService.d.ts +686 -0
- package/dist/cjs/util/ApiHelpers.d.ts +5 -0
- package/dist/cjs/util/backoff.d.ts +11 -0
- package/dist/cjs/util/types/BalanceServiceTypes.d.ts +322 -0
- package/dist/cjs/util/types/BaseServiceTypes.d.ts +180 -0
- package/dist/cjs/util/types/GenericTypes.d.ts +96 -0
- package/dist/cjs/util/types/NftServiceTypes.d.ts +297 -0
- package/dist/cjs/util/types/PricingServiceTypes.d.ts +31 -0
- package/dist/cjs/util/types/SecurityServiceTypes.d.ts +121 -0
- package/dist/cjs/util/types/TransactionServiceTypes.d.ts +322 -0
- package/dist/cjs/util/types/XykServiceTypes.d.ts +479 -0
- package/dist/es/index.d.ts +9 -0
- package/dist/es/index.js +5223 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/services/BalanceService.d.ts +543 -0
- package/dist/es/services/BaseService.d.ts +357 -0
- package/dist/es/services/CovalentClient.d.ts +65 -0
- package/dist/es/services/NftService.d.ts +620 -0
- package/dist/es/services/PricingService.d.ts +88 -0
- package/dist/es/services/SecurityService.d.ts +158 -0
- package/dist/es/services/TransactionService.d.ts +457 -0
- package/dist/es/services/XykService.d.ts +686 -0
- package/dist/es/util/ApiHelpers.d.ts +5 -0
- package/dist/es/util/backoff.d.ts +11 -0
- package/dist/es/util/types/BalanceServiceTypes.d.ts +322 -0
- package/dist/es/util/types/BaseServiceTypes.d.ts +180 -0
- package/dist/es/util/types/GenericTypes.d.ts +96 -0
- package/dist/es/util/types/NftServiceTypes.d.ts +297 -0
- package/dist/es/util/types/PricingServiceTypes.d.ts +31 -0
- package/dist/es/util/types/SecurityServiceTypes.d.ts +121 -0
- package/dist/es/util/types/TransactionServiceTypes.d.ts +322 -0
- package/dist/es/util/types/XykServiceTypes.d.ts +479 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +5223 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/services/BalanceService.d.ts +543 -0
- package/dist/esm/services/BaseService.d.ts +357 -0
- package/dist/esm/services/CovalentClient.d.ts +65 -0
- package/dist/esm/services/NftService.d.ts +620 -0
- package/dist/esm/services/PricingService.d.ts +88 -0
- package/dist/esm/services/SecurityService.d.ts +158 -0
- package/dist/esm/services/TransactionService.d.ts +457 -0
- package/dist/esm/services/XykService.d.ts +686 -0
- package/dist/esm/util/ApiHelpers.d.ts +5 -0
- package/dist/esm/util/backoff.d.ts +11 -0
- package/dist/esm/util/types/BalanceServiceTypes.d.ts +322 -0
- package/dist/esm/util/types/BaseServiceTypes.d.ts +180 -0
- package/dist/esm/util/types/GenericTypes.d.ts +96 -0
- package/dist/esm/util/types/NftServiceTypes.d.ts +297 -0
- package/dist/esm/util/types/PricingServiceTypes.d.ts +31 -0
- package/dist/esm/util/types/SecurityServiceTypes.d.ts +121 -0
- package/dist/esm/util/types/TransactionServiceTypes.d.ts +322 -0
- package/dist/esm/util/types/XykServiceTypes.d.ts +479 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -27
- package/dist/index.js.map +1 -1
- package/dist/services/BalanceService.d.ts +149 -11
- package/dist/services/BalanceService.js +300 -84
- package/dist/services/BalanceService.js.map +1 -1
- package/dist/services/BaseService.d.ts +46 -10
- package/dist/services/BaseService.js +199 -151
- package/dist/services/BaseService.js.map +1 -1
- package/dist/services/CovalentClient.d.ts +65 -0
- package/dist/services/CovalentClient.js +44 -0
- package/dist/services/CovalentClient.js.map +1 -0
- package/dist/services/NftService.d.ts +182 -16
- package/dist/services/NftService.js +490 -211
- package/dist/services/NftService.js.map +1 -1
- package/dist/services/PricingService.d.ts +8 -3
- package/dist/services/PricingService.js +44 -38
- package/dist/services/PricingService.js.map +1 -1
- package/dist/services/SecurityService.d.ts +71 -3
- package/dist/services/SecurityService.js +140 -32
- package/dist/services/SecurityService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +58 -9
- package/dist/services/TransactionService.js +152 -103
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/XykService.d.ts +85 -19
- package/dist/services/XykService.js +470 -291
- package/dist/services/XykService.js.map +1 -1
- package/dist/util/ApiHelpers.d.ts +2 -1
- package/dist/util/ApiHelpers.js +57 -36
- package/dist/util/ApiHelpers.js.map +1 -1
- package/dist/util/backoff.d.ts +5 -3
- package/dist/util/backoff.js +35 -13
- package/dist/util/backoff.js.map +1 -1
- package/dist/util/types/BalanceServiceTypes.d.ts +63 -0
- package/dist/util/types/BalanceServiceTypes.js +1 -2
- package/dist/util/types/BaseServiceTypes.d.ts +8 -0
- package/dist/util/types/BaseServiceTypes.js +1 -2
- package/dist/util/types/GenericTypes.d.ts +7 -0
- package/dist/util/types/GenericTypes.js +1 -2
- package/dist/util/types/NftServiceTypes.d.ts +86 -2
- package/dist/util/types/NftServiceTypes.js +1 -2
- package/dist/util/types/PricingServiceTypes.js +1 -2
- package/dist/util/types/SecurityServiceTypes.d.ts +51 -0
- package/dist/util/types/SecurityServiceTypes.js +1 -2
- package/dist/util/types/TransactionServiceTypes.d.ts +24 -2
- package/dist/util/types/TransactionServiceTypes.js +1 -2
- package/dist/util/types/XykServiceTypes.d.ts +20 -6
- package/dist/util/types/XykServiceTypes.js +1 -2
- package/package.json +19 -4
- package/dist/services/Client.d.ts +0 -29
- package/dist/services/Client.js +0 -30
- package/dist/services/Client.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Covalent SDK for TypeScript
|
|
2
2
|
|
|
3
|
-
The Covalent API SDK supported
|
|
3
|
+
The Covalent SDK is the fastest way to integrate the Covalent Unified API for working with blockchain data. The SDK works with all [supported chains](https://www.covalenthq.com/docs/networks/) including Mainnets and Testnets.
|
|
4
|
+
|
|
5
|
+
Note - use `Node v18` and above for best results.
|
|
4
6
|
|
|
5
|
-
The Covalent SDK supports all chains across Mainnets and Testnets. List of supported Networks can be found on our [Supported Networks page](https://www.covalenthq.com/docs/networks/)
|
|
6
7
|
|
|
7
8
|
> **Name Resolution**
|
|
8
9
|
>
|
|
9
|
-
> The Covalent SDK supports
|
|
10
|
+
> The Covalent SDK natively supports ENS domains (e.g. `demo.eth`), Lens Handles (e.g. `@demo.lens`) and Unstoppable Domains (e.g. `demo.x`) which automatically resolve to the underlying user address (e.g. `0xfC43f5F9dd45258b3AFf31Bdbe6561D97e8B71de`)
|
|
10
11
|
|
|
11
12
|
## Getting started
|
|
12
13
|
|
|
@@ -18,14 +19,14 @@ or
|
|
|
18
19
|
yarn add @covalenthq/client-sdk
|
|
19
20
|
```
|
|
20
21
|
|
|
21
|
-
After installing
|
|
22
|
+
After installing, you can import and use the SDK with:
|
|
22
23
|
|
|
23
24
|
```ts
|
|
24
|
-
import {
|
|
25
|
+
import { CovalentClient } from "@covalenthq/client-sdk";
|
|
25
26
|
|
|
26
27
|
const ApiServices = async () => {
|
|
27
|
-
const client = new
|
|
28
|
-
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS"); // Example call
|
|
28
|
+
const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
|
|
29
|
+
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS"); // Example call
|
|
29
30
|
if (!resp.error) {
|
|
30
31
|
console.log(resp.data);
|
|
31
32
|
} else {
|
|
@@ -33,55 +34,71 @@ const ApiServices = async () => {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
```
|
|
36
|
-
|
|
37
|
+
|
|
38
|
+
> **Getting an API Key**
|
|
39
|
+
>
|
|
40
|
+
> To get your own Covalent API key, **[sign up here](https://www.covalenthq.com/platform/auth/register/)** and create your key from the *API Keys* tab.
|
|
41
|
+
|
|
42
|
+
Note about a **ℹ️ BREAKING CHANGE**:
|
|
43
|
+
|
|
44
|
+
> If you have been using:
|
|
45
|
+
>
|
|
46
|
+
> `import { Client } from "@covalenthq/client-sdk";`
|
|
47
|
+
>
|
|
48
|
+
> Please change to:
|
|
49
|
+
>
|
|
50
|
+
> `import { CovalentClient } from "@covalenthq/client-sdk";`
|
|
51
|
+
|
|
52
|
+
### Typed Objects
|
|
53
|
+
Query parameters are handled using `typed objects`. To pass in query parameters, developers can define an object that follows the type listed in the provided `tsdocs` under `src/util/types/`. Additionally, developers can reference the `tsdocs` for autocomplete suggestions for the supported parameters. These supported parameters can be passed in any order.
|
|
54
|
+
|
|
55
|
+
For example, the following sets the `quoteCurrency` query parameter to `CAD` and the parameter `nft` to `true` for fetching all the token balances, including NFTs, for a wallet address:
|
|
37
56
|
```ts
|
|
38
57
|
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS", {quoteCurrency: "CAD", nft: true});
|
|
39
58
|
```
|
|
40
59
|
|
|
41
|
-
|
|
60
|
+
You can import all the listed types. For example:
|
|
42
61
|
```ts
|
|
43
|
-
import {
|
|
62
|
+
import { CovalentClient, BalancesResponse, BalanceItem } from "@covalenthq/client-sdk";
|
|
44
63
|
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS", {quoteCurrency: "CAD", nft: true});
|
|
45
64
|
const data: BalancesResponse = resp.data; // `resp.data` in this case is of type `BalancesResponse`
|
|
46
65
|
const items: BalanceItem[] = resp.data.items; // `resp.data.items` is of type `BalanceItem[]`
|
|
47
66
|
```
|
|
48
67
|
|
|
49
|
-
> **Creating a unique Covalent API Key**
|
|
50
|
-
>
|
|
51
|
-
> To create your own API key, **[sign up for an Covalent account here](https://www.covalenthq.com/platform/auth/register/)** and use the key created under the [API Keys](https://www.covalenthq.com/platform/apikey/) tab.
|
|
52
|
-
|
|
53
|
-
|
|
54
68
|
## How to use the Covalent SDK
|
|
55
69
|
|
|
56
|
-
The Covalent SDK provides comprehensive support for all Class A, Class B, and Pricing endpoints grouped under
|
|
70
|
+
The Covalent SDK provides comprehensive support for all Class A, Class B, and Pricing endpoints that are grouped under the following *Service* namespaces:
|
|
57
71
|
|
|
58
|
-
- `SecurityService
|
|
59
|
-
- `BalanceService
|
|
60
|
-
- `
|
|
61
|
-
- `NftService
|
|
62
|
-
- `PricingService
|
|
63
|
-
- `TransactionService
|
|
64
|
-
- `XykService
|
|
72
|
+
- [`SecurityService`](#securityservice): Access to the token approvals endpoints
|
|
73
|
+
- [`BalanceService`](#balanceservice): Access to the balances endpoints
|
|
74
|
+
- [`BaseService`](#baseservice): Access to the address activity, log events, chain status, and block retrieval endpoints
|
|
75
|
+
- [`NftService`](#nftservice): Access to the NFT endpoints
|
|
76
|
+
- [`PricingService`](#pricingservice): Access to the historical token prices endpoint
|
|
77
|
+
- [`TransactionService`](#transactionservice): Access to the transactions endpoints
|
|
78
|
+
- [`XykService`](#xykservice): Access to the XY=K suite of endpoints
|
|
65
79
|
|
|
66
80
|
### SecurityService
|
|
67
81
|
|
|
68
|
-
The `SecurityService` class
|
|
82
|
+
The `SecurityService` class refers to the [token approvals API endpoints](https://www.covalenthq.com/docs/api/security/get-token-approvals-for-address/):
|
|
69
83
|
|
|
70
|
-
- `getApprovals()`: Get a list of approvals across all token contracts categorized by spenders for a wallet’s assets.
|
|
84
|
+
- `getApprovals()`: Get a list of approvals across all ERC20 token contracts categorized by spenders for a wallet’s assets.
|
|
85
|
+
- `getNftApprovals()`: Get a list of approvals across all NFT contracts categorized by spenders for a wallet’s assets.
|
|
71
86
|
|
|
72
87
|
### BalanceService
|
|
73
88
|
|
|
74
|
-
The `BalanceService` class
|
|
89
|
+
The `BalanceService` class refers to the [balances API endpoints](https://www.covalenthq.com/docs/api/balances/get-token-balances-for-address/):
|
|
75
90
|
|
|
76
91
|
- `getTokenBalancesForWalletAddress()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
|
|
77
92
|
- `getHistoricalTokenBalancesForWalletAddress()`: Fetch the historical native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address at a given block height or date. Response includes daily prices and other metadata.
|
|
78
93
|
- `getHistoricalPortfolioForWalletAddress()`: Render a daily portfolio balance for an address broken down by the token. The timeframe is user-configurable, defaults to 30 days.
|
|
79
|
-
- `getErc20TransfersForWalletAddress()`: Render the transfer-in and transfer-out of a token along with historical prices from an address.
|
|
94
|
+
- `getErc20TransfersForWalletAddress()`: Render the transfer-in and transfer-out of a token along with historical prices from an address. (Paginated)
|
|
95
|
+
- `getErc20TransfersForWalletAddressByPage()`: Render the transfer-in and transfer-out of a token along with historical prices from an address. (By page)
|
|
80
96
|
- `getTokenHoldersV2ForTokenAddress()`: Get a list of all the token holders for a specified ERC20 or ERC721 token. Returns historic token holders when block-height is set (defaults to latest). Useful for building pie charts of token holders.
|
|
97
|
+
- `getNativeTokenBalance()`: Get the native token balance for an address. This endpoint is required because native tokens are usually not ERC20 tokens and sometimes you want something lightweight.
|
|
81
98
|
|
|
82
|
-
###
|
|
99
|
+
### BaseService
|
|
83
100
|
|
|
84
|
-
The `
|
|
101
|
+
The `BaseService` class refers to the [address activity, log events, chain status and block retrieval API endpoints](https://www.covalenthq.com/docs/api/base/get-address-activity/):
|
|
85
102
|
|
|
86
103
|
- `getBlock()`: Fetch and render a single block for a block explorer.
|
|
87
104
|
- `getLogs()`: Get all the event logs of the latest block, or for a range of blocks. Includes sender contract metadata as well as decoded logs.
|
|
@@ -95,7 +112,7 @@ The `BaseServices` class contains the log events, chain, and block endpoints. Li
|
|
|
95
112
|
|
|
96
113
|
### NftService
|
|
97
114
|
|
|
98
|
-
The `NftService` class
|
|
115
|
+
The `NftService` class refers to the [NFT API endpoints](https://www.covalenthq.com/docs/api/nft/get-nfts-for-address/):
|
|
99
116
|
|
|
100
117
|
- `getChainCollections()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files.
|
|
101
118
|
- `getNftsForAddress()`: Used to render the NFTs (including ERC721 and ERC1155) held by an address.
|
|
@@ -107,17 +124,19 @@ The `NftService` class contains the NFT endpoints. Listed below are the supporte
|
|
|
107
124
|
- `getCollectionTraitsSummary()`: Used to calculate rarity scores for a collection based on its traits.
|
|
108
125
|
- `checkOwnershipInNft()`: Used to verify ownership of NFTs (including ERC-721 and ERC-1155) within a collection.
|
|
109
126
|
- `checkOwnershipInNftForSpecificTokenId()`: Used to verify ownership of a specific token (ERC-721 or ERC-1155) within a collection.
|
|
110
|
-
- `
|
|
127
|
+
- `getNftMarketSaleCount()`: Used to build a time-series chart of the sales count of an NFT collection.
|
|
128
|
+
- `getNftMarketVolume()`: Used to build a time-series chart of the transaction volume of an NFT collection.
|
|
129
|
+
- `getNftMarketFloorPrice()`: Used to render a price floor chart for an NFT collection.
|
|
111
130
|
|
|
112
131
|
### PricingService
|
|
113
132
|
|
|
114
|
-
The `PricingService` class
|
|
133
|
+
The `PricingService` class refers to the [historical token prices API endpoint](https://www.covalenthq.com/docs/api/pricing/get-historical-token-prices/):
|
|
115
134
|
|
|
116
135
|
- `getTokenPrices()`: Get historic prices of a token between date ranges. Supports native tokens.
|
|
117
136
|
|
|
118
137
|
### TransactionService
|
|
119
138
|
|
|
120
|
-
The `TransactionService` class
|
|
139
|
+
The `TransactionService` class refers to the [transactions API endpoints](https://www.covalenthq.com/docs/api/transactions/get-a-transaction/):
|
|
121
140
|
|
|
122
141
|
- `getAllTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
|
|
123
142
|
- `getTransaction()`: Fetch and render a single transaction including its decoded log events. Additionally return semantically decoded information for DEX trades, lending and NFT sales.
|
|
@@ -126,13 +145,14 @@ The `TransactionService` class contains the transactions endpoint. Listed below
|
|
|
126
145
|
|
|
127
146
|
### XykService
|
|
128
147
|
|
|
129
|
-
The `XykService`
|
|
148
|
+
The `XykService` refers to the [Xy=k API endpoints](https://www.covalenthq.com/docs/api/xyk/get-xyk-pools/):
|
|
130
149
|
|
|
131
150
|
- `getPools()`: Get all the pools of a particular DEX. Supports most common DEXs (Uniswap, SushiSwap, etc), and returns detailed trading data (volume, liquidity, swap counts, fees, LP token prices).
|
|
132
151
|
- `getPoolByAddress()`: Get the 7 day and 30 day time-series data (volume, liquidity, price) of a particular liquidity pool in a DEX. Useful for building time-series charts on DEX trading activity.
|
|
133
152
|
- `getPoolsForTokenAddress()`: Get all pools and the supported DEX for a token. Useful for building a table of top pairs across all supported DEXes that the token is trading on.
|
|
153
|
+
- `getPoolsForWalletAddress()`: Get all pools and supported DEX for a wallet. Useful for building a personal DEX UI showcasing pairs and supported DEXes associated to the wallet.
|
|
134
154
|
- `getAddressExchangeBalances()`: Return balance of a wallet/contract address on a specific DEX.
|
|
135
|
-
- `getNetworkExchangeTokens()`:
|
|
155
|
+
- `getNetworkExchangeTokens()`: Retrieve all network exchange tokens for a specific DEX. Useful for building a top tokens table by total liquidity within a particular DEX.
|
|
136
156
|
- `getSupportedDEXes()`: Get all the supported DEXs available for the xy=k endpoints, along with the swap fees and factory addresses.
|
|
137
157
|
- `getDexForPoolAddress()`: Get the supported DEX given a pool address, along with the swap fees, DEX's logo url, and factory addresses. Useful to identifying the specific DEX to which a pair address is associated.
|
|
138
158
|
- `getSingleNetworkExchangeToken()`: Get historical daily swap count for a single network exchange token.
|
|
@@ -142,9 +162,9 @@ The `XykService` class contains the Xy=k endpoints. Listed below are the support
|
|
|
142
162
|
- `getEcosystemChartData()`: Get a 7d and 30d time-series chart of DEX activity. Includes volume and swap count.
|
|
143
163
|
- `getHealthData()`: Ping the health of xy=k endpoints to get the synced block height per chain.
|
|
144
164
|
|
|
145
|
-
|
|
165
|
+
## How pagination works
|
|
146
166
|
|
|
147
|
-
|
|
167
|
+
The following endpoints support pagination:
|
|
148
168
|
|
|
149
169
|
- `getErc20TransfersForWalletAddress()`
|
|
150
170
|
- `getTokenHoldersV2ForTokenAddress()`
|
|
@@ -155,25 +175,76 @@ The `XykService` class contains the Xy=k endpoints. Listed below are the support
|
|
|
155
175
|
- `getTokenIdsForContractWithMetadata()`
|
|
156
176
|
- `getAllTransactionsForAddress()`
|
|
157
177
|
|
|
158
|
-
|
|
178
|
+
Using the Covalent API, paginated supported endpoints return only 100 items, such as transactions or log events, per page. However, the Covalent SDK leverages generators to *seamlessly fetch all items without the user having to deal with pagination*.
|
|
179
|
+
|
|
180
|
+
For example, the following fetches ALL transactions for `demo.eth` on Ethereum:
|
|
159
181
|
```ts
|
|
160
|
-
import {
|
|
182
|
+
import { CovalentClient } from "@covalenthq/client-sdk";
|
|
161
183
|
|
|
162
184
|
const ApiServices = async () => {
|
|
163
|
-
const client = new
|
|
164
|
-
|
|
165
|
-
|
|
185
|
+
const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
|
|
186
|
+
try {
|
|
187
|
+
for await (const tx of client.TransactionService.getAllTransactionsForAddress("eth-mainnet", "demo.eth")) {
|
|
188
|
+
console.log("tx", tx);
|
|
189
|
+
}
|
|
190
|
+
} catch (error) {
|
|
191
|
+
console.log(error.message);
|
|
166
192
|
}
|
|
167
193
|
}
|
|
168
194
|
```
|
|
169
|
-
|
|
195
|
+
|
|
196
|
+
### Concurrency Mechanism
|
|
197
|
+
|
|
198
|
+
Developers have the flexibility to specify the desired number of concurrent API calls they wish to execute using the `threadCount` settings parameter, with a default value of `3`. For example:
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
import { CovalentClient, CovalentClientSettings } from "@covalenthq/client-sdk";
|
|
202
|
+
|
|
203
|
+
const settings: CovalentClientSettings = {
|
|
204
|
+
threadCount: 5
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const ApiServices = async () => {
|
|
208
|
+
const client = new CovalentClient("YOUR_API_KEY", settings); // Replace with your Covalent API key and add set debugger
|
|
209
|
+
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
|
|
210
|
+
if (!resp.error) {
|
|
211
|
+
console.log(resp.data);
|
|
212
|
+
} else {
|
|
213
|
+
console.log(resp.error_message);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Debugger Mode
|
|
219
|
+
|
|
220
|
+
Developers have the option to enable a debugger mode that provides response times, the URLs of called endpoints, and the HTTP statuses of those endpoints. This feature helps users identify which endpoints may have encountered failures. The default is `debug = false` if no input is provided.
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
import { CovalentClient, CovalentClientSettings } from "@covalenthq/client-sdk";
|
|
224
|
+
|
|
225
|
+
const settings: CovalentClientSettings = {
|
|
226
|
+
debug: true
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const ApiServices = async () => {
|
|
230
|
+
const client = new CovalentClient("YOUR_API_KEY", settings); // Replace with your Covalent API key and add set debugger
|
|
231
|
+
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
|
|
232
|
+
if (!resp.error) {
|
|
233
|
+
console.log(resp.data);
|
|
234
|
+
} else {
|
|
235
|
+
console.log(resp.error_message);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+

|
|
170
241
|
|
|
171
242
|
### Retry Mechanism
|
|
172
243
|
|
|
173
|
-
Each endpoint is equipped with an exponential backoff algorithm that exponentially extends the wait time between retries,
|
|
244
|
+
Each endpoint is equipped with an exponential backoff algorithm that exponentially extends the wait time between retries, up to a `maximum of 5` retry attempts.
|
|
174
245
|
|
|
175
246
|
### Error Handling
|
|
176
|
-
The paginated endpoints
|
|
247
|
+
The paginated endpoints throw an error message in this format: `An error occurred {error_code}: {error_message}`. The developer will need to `catch` these errors. Note - these endpoints do not follow the default response format which is:
|
|
177
248
|
```ts
|
|
178
249
|
❴
|
|
179
250
|
"data": ...,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { CovalentClient, Client, Chain, Quote, Chains, Quotes, CovalentClientSettings } from "./services/CovalentClient";
|
|
2
|
+
export * from "./util/types/BalanceServiceTypes";
|
|
3
|
+
export * from "./util/types/BaseServiceTypes";
|
|
4
|
+
export * from "./util/types/NftServiceTypes";
|
|
5
|
+
export * from "./util/types/PricingServiceTypes";
|
|
6
|
+
export * from "./util/types/SecurityServiceTypes";
|
|
7
|
+
export * from "./util/types/XykServiceTypes";
|
|
8
|
+
export * from "./util/types/GenericTypes";
|
|
9
|
+
export * from "./util/types/TransactionServiceTypes";
|