@covalenthq/client-sdk 0.2.9 → 0.4.2
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 +64 -14
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.js +4619 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/services/BalanceService.d.ts +443 -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 +484 -0
- package/dist/cjs/services/PricingService.d.ts +88 -0
- package/dist/cjs/services/SecurityService.d.ts +96 -0
- package/dist/cjs/services/TransactionService.d.ts +440 -0
- package/dist/cjs/services/XykService.d.ts +682 -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 +284 -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 +221 -0
- package/dist/cjs/util/types/PricingServiceTypes.d.ts +31 -0
- package/dist/cjs/util/types/SecurityServiceTypes.d.ts +71 -0
- package/dist/cjs/util/types/TransactionServiceTypes.d.ts +312 -0
- package/dist/cjs/util/types/XykServiceTypes.d.ts +479 -0
- package/dist/es/index.d.ts +9 -0
- package/dist/es/index.js +4616 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/services/BalanceService.d.ts +443 -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 +484 -0
- package/dist/es/services/PricingService.d.ts +88 -0
- package/dist/es/services/SecurityService.d.ts +96 -0
- package/dist/es/services/TransactionService.d.ts +440 -0
- package/dist/es/services/XykService.d.ts +682 -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 +284 -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 +221 -0
- package/dist/es/util/types/PricingServiceTypes.d.ts +31 -0
- package/dist/es/util/types/SecurityServiceTypes.d.ts +71 -0
- package/dist/es/util/types/TransactionServiceTypes.d.ts +312 -0
- package/dist/es/util/types/XykServiceTypes.d.ts +479 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +4616 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/services/BalanceService.d.ts +443 -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 +484 -0
- package/dist/esm/services/PricingService.d.ts +88 -0
- package/dist/esm/services/SecurityService.d.ts +96 -0
- package/dist/esm/services/TransactionService.d.ts +440 -0
- package/dist/esm/services/XykService.d.ts +682 -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 +284 -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 +221 -0
- package/dist/esm/util/types/PricingServiceTypes.d.ts +31 -0
- package/dist/esm/util/types/SecurityServiceTypes.d.ts +71 -0
- package/dist/esm/util/types/TransactionServiceTypes.d.ts +312 -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 +49 -11
- package/dist/services/BalanceService.js +110 -81
- package/dist/services/BalanceService.js.map +1 -1
- package/dist/services/BaseService.d.ts +46 -10
- package/dist/services/BaseService.js +193 -145
- 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 +52 -22
- package/dist/services/NftService.js +236 -235
- package/dist/services/NftService.js.map +1 -1
- package/dist/services/PricingService.d.ts +8 -3
- package/dist/services/PricingService.js +43 -37
- package/dist/services/PricingService.js.map +1 -1
- package/dist/services/SecurityService.d.ts +9 -3
- package/dist/services/SecurityService.js +38 -31
- package/dist/services/SecurityService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +41 -9
- package/dist/services/TransactionService.js +133 -100
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/XykService.d.ts +81 -19
- package/dist/services/XykService.js +451 -278
- 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 +25 -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 +10 -2
- package/dist/util/types/NftServiceTypes.js +1 -2
- package/dist/util/types/PricingServiceTypes.js +1 -2
- package/dist/util/types/SecurityServiceTypes.d.ts +1 -0
- package/dist/util/types/SecurityServiceTypes.js +1 -2
- package/dist/util/types/TransactionServiceTypes.d.ts +14 -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,6 +1,6 @@
|
|
|
1
1
|
# covalent-api-sdk-ts
|
|
2
2
|
|
|
3
|
-
The Covalent API SDK supported for TypeScript.
|
|
3
|
+
The Covalent API SDK supported for TypeScript. Use `Node v18` and above for best results.
|
|
4
4
|
|
|
5
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
6
|
|
|
@@ -21,10 +21,10 @@ yarn add @covalenthq/client-sdk
|
|
|
21
21
|
After installing the app, you can then import and use the SDK:
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
|
-
import {
|
|
24
|
+
import { CovalentClient } from "@covalenthq/client-sdk";
|
|
25
25
|
|
|
26
26
|
const ApiServices = async () => {
|
|
27
|
-
const client = new
|
|
27
|
+
const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
|
|
28
28
|
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS"); // Example call, refer to API Docs for required paramaters or click into the method `getTokenBalancesForWalletAddress` to see the accepted parameter arguments
|
|
29
29
|
if (!resp.error) {
|
|
30
30
|
console.log(resp.data);
|
|
@@ -40,7 +40,7 @@ const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-m
|
|
|
40
40
|
|
|
41
41
|
All of our types are also available for import! For example:
|
|
42
42
|
```ts
|
|
43
|
-
import {
|
|
43
|
+
import { CovalentClient, BalancesResponse, BalanceItem } from "@covalenthq/client-sdk";
|
|
44
44
|
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS", {quoteCurrency: "CAD", nft: true});
|
|
45
45
|
const data: BalancesResponse = resp.data; // `resp.data` in this case is of type `BalancesResponse`
|
|
46
46
|
const items: BalanceItem[] = resp.data.items; // `resp.data.items` is of type `BalanceItem[]`
|
|
@@ -57,7 +57,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
|
|
|
57
57
|
|
|
58
58
|
- `SecurityService`: Access to the Covalent's getApprovals endpoint
|
|
59
59
|
- `BalanceService`: Access to the Covalent's balances endpoints
|
|
60
|
-
- `
|
|
60
|
+
- `BaseService`: Access to the Covalent's log events, chain, and block endpoints
|
|
61
61
|
- `NftService`: Access to the Covalent's NFT endpoints
|
|
62
62
|
- `PricingService`: Access to the Covalent's get historical token prices endpoint
|
|
63
63
|
- `TransactionService`: Access to the Covalent's transactions endpoints
|
|
@@ -79,9 +79,9 @@ The `BalanceService` class contains the balances endpoints. Listed below are the
|
|
|
79
79
|
- `getErc20TransfersForWalletAddress()`: Render the transfer-in and transfer-out of a token along with historical prices from an address.
|
|
80
80
|
- `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.
|
|
81
81
|
|
|
82
|
-
###
|
|
82
|
+
### BaseService
|
|
83
83
|
|
|
84
|
-
The `
|
|
84
|
+
The `BaseService` class contains the log events, chain, and block endpoints. Listed below are the supported endpoints, also refer to our api docs under the Base section in our class A endpoints.
|
|
85
85
|
|
|
86
86
|
- `getBlock()`: Fetch and render a single block for a block explorer.
|
|
87
87
|
- `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.
|
|
@@ -107,7 +107,6 @@ The `NftService` class contains the NFT endpoints. Listed below are the supporte
|
|
|
107
107
|
- `getCollectionTraitsSummary()`: Used to calculate rarity scores for a collection based on its traits.
|
|
108
108
|
- `checkOwnershipInNft()`: Used to verify ownership of NFTs (including ERC-721 and ERC-1155) within a collection.
|
|
109
109
|
- `checkOwnershipInNftForSpecificTokenId()`: Used to verify ownership of a specific token (ERC-721 or ERC-1155) within a collection.
|
|
110
|
-
- `getNftExternalMetadataForContract()`: Get a single NFT with metadata by token ID from a collection. Useful for building NFT card displays.
|
|
111
110
|
|
|
112
111
|
### PricingService
|
|
113
112
|
|
|
@@ -131,8 +130,9 @@ The `XykService` class contains the Xy=k endpoints. Listed below are the support
|
|
|
131
130
|
- `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
131
|
- `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
132
|
- `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.
|
|
133
|
+
- `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
134
|
- `getAddressExchangeBalances()`: Return balance of a wallet/contract address on a specific DEX.
|
|
135
|
-
- `getNetworkExchangeTokens()`:
|
|
135
|
+
- `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
136
|
- `getSupportedDEXes()`: Get all the supported DEXs available for the xy=k endpoints, along with the swap fees and factory addresses.
|
|
137
137
|
- `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
138
|
- `getSingleNetworkExchangeToken()`: Get historical daily swap count for a single network exchange token.
|
|
@@ -157,23 +157,73 @@ The `XykService` class contains the Xy=k endpoints. Listed below are the support
|
|
|
157
157
|
|
|
158
158
|
The listed endpoints above are currently the only endpoints that support pagination which return 100 results per page. To get the next page, it uses a `link url` or the `page-number` provided in the endpoint response. Here's an example of how to paginate through all recent transactions on the ethereum blockchain for the demo's ENS address:
|
|
159
159
|
```ts
|
|
160
|
-
import {
|
|
160
|
+
import { CovalentClient } from "@covalenthq/client-sdk";
|
|
161
161
|
|
|
162
162
|
const ApiServices = async () => {
|
|
163
|
-
const client = new
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
|
|
164
|
+
try {
|
|
165
|
+
for await (const tx of client.TransactionService.getAllTransactionsForAddress("eth-mainnet", "demo.eth")) {
|
|
166
|
+
console.log("tx", tx);
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.log(error.message);
|
|
166
170
|
}
|
|
167
171
|
}
|
|
168
172
|
```
|
|
169
173
|
The paginated endpoints exclusively returns their response items without the response wrapper, enabling developers to access the list seamlessly, ensuring efficient and straightforward item retrieval.
|
|
170
174
|
|
|
175
|
+
### Concurrency Mechanism
|
|
176
|
+
|
|
177
|
+
Developers have the flexibility to specify the desired number of concurrent API calls they wish to execute, with a default value of `3` applied if no input is provided.
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
import { CovalentClient, CovalentClientSettings } from "@covalenthq/client-sdk";
|
|
181
|
+
|
|
182
|
+
const settings: CovalentClientSettings = {
|
|
183
|
+
threadCount: 5
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const ApiServices = async () => {
|
|
187
|
+
const client = new CovalentClient("YOUR_API_KEY", settings); // Replace with your Covalent API key and add set debugger
|
|
188
|
+
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
|
|
189
|
+
if (!resp.error) {
|
|
190
|
+
console.log(resp.data);
|
|
191
|
+
} else {
|
|
192
|
+
console.log(resp.error_message);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Debugger Mode
|
|
198
|
+
|
|
199
|
+
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 will be `debug = false` if no input is provided.
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
import { CovalentClient, CovalentClientSettings } from "@covalenthq/client-sdk";
|
|
203
|
+
|
|
204
|
+
const settings: CovalentClientSettings = {
|
|
205
|
+
debug: true
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const ApiServices = async () => {
|
|
209
|
+
const client = new CovalentClient("YOUR_API_KEY", settings); // Replace with your Covalent API key and add set debugger
|
|
210
|
+
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
|
|
211
|
+
if (!resp.error) {
|
|
212
|
+
console.log(resp.data);
|
|
213
|
+
} else {
|
|
214
|
+
console.log(resp.error_message);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+

|
|
220
|
+
|
|
171
221
|
### Retry Mechanism
|
|
172
222
|
|
|
173
223
|
Each endpoint is equipped with an exponential backoff algorithm that exponentially extends the wait time between retries, making up to a `maximum of 5` retry attempts only.
|
|
174
224
|
|
|
175
225
|
### Error Handling
|
|
176
|
-
The paginated endpoints will throw an error message in this format: `An error occurred {error_code}: {error_message}`, when an error occurs. The developer would need to make sure to catch those errors if any. This endpoint does not follow our default response format unlike our other endpoints, shown below.
|
|
226
|
+
The paginated endpoints will throw an error message in this format: `An error occurred {error_code}: {error_message}`, when an error occurs. The developer would need to make sure to `catch` those errors if any. This endpoint does not follow our default response format unlike our other endpoints, shown below.
|
|
177
227
|
```ts
|
|
178
228
|
❴
|
|
179
229
|
"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";
|