@covalenthq/client-sdk 0.2.4 → 0.2.6
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 +20 -5
- package/dist/services/BalanceService.d.ts +90 -74
- package/dist/services/BalanceService.js +91 -151
- package/dist/services/BalanceService.js.map +1 -1
- package/dist/services/BaseService.d.ts +70 -76
- package/dist/services/BaseService.js +80 -162
- package/dist/services/BaseService.js.map +1 -1
- package/dist/services/Client.d.ts +8 -2
- package/dist/services/Client.js +5 -2
- package/dist/services/Client.js.map +1 -1
- package/dist/services/NftService.d.ts +66 -40
- package/dist/services/NftService.js +68 -135
- package/dist/services/NftService.js.map +1 -1
- package/dist/services/PricingService.d.ts +13 -4
- package/dist/services/PricingService.js +11 -10
- package/dist/services/PricingService.js.map +1 -1
- package/dist/services/SecurityService.d.ts +1 -7
- package/dist/services/SecurityService.js +1 -4
- package/dist/services/SecurityService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +39 -22
- package/dist/services/TransactionService.js +34 -34
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/XykService.d.ts +1 -7
- package/dist/services/XykService.js +1 -4
- package/dist/services/XykService.js.map +1 -1
- package/dist/util/ApiHelpers.d.ts +3 -0
- package/dist/util/ApiHelpers.js +59 -1
- package/dist/util/ApiHelpers.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# covalent-api-sdk-ts
|
|
2
2
|
|
|
3
|
-
The Covalent API SDK supported for
|
|
3
|
+
The Covalent API SDK supported for TypeScript.
|
|
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
|
|
|
@@ -33,6 +33,10 @@ const ApiServices = async () => {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
```
|
|
36
|
+
Query Parameters for any API endpoint is handled using `typed objects`. To pass in query parameters, developers can define an object that follows the type listed in the `tsdocs` and follow the `tsdocs` for autocomplete suggestions for the supported parameters. Supported parameters can be passed in as any order. For example: a developer wants to set the `quoteCurrency` parameter to `CAD` and `nft` to `true`.
|
|
37
|
+
```ts
|
|
38
|
+
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS", {quoteCurrency: "CAD", nft: true});
|
|
39
|
+
```
|
|
36
40
|
|
|
37
41
|
> **Creating a unique Covalent API Key**
|
|
38
42
|
>
|
|
@@ -48,7 +52,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
|
|
|
48
52
|
- `BaseServices`: Access to the Covalent's log events, chain, and block endpoints
|
|
49
53
|
- `NftService`: Access to the Covalent's NFT endpoints
|
|
50
54
|
- `PricingService`: Access to the Covalent's get historical token prices endpoint
|
|
51
|
-
- `TransactionService`: Access to the Covalent's transactions endpoints
|
|
55
|
+
- `TransactionService`: Access to the Covalent's transactions endpoints
|
|
52
56
|
- `XykService`: Access to the Covalent's Xy=k endpoints
|
|
53
57
|
|
|
54
58
|
### SecurityService
|
|
@@ -129,7 +133,18 @@ The `XykService` class contains the Xy=k endpoints. Listed below are the support
|
|
|
129
133
|
|
|
130
134
|
### How pagination works
|
|
131
135
|
|
|
132
|
-
|
|
136
|
+
#### Endpoints supporting pagination
|
|
137
|
+
|
|
138
|
+
- `getErc20TransfersForWalletAddress()`
|
|
139
|
+
- `getTokenHoldersV2ForTokenAddress()`
|
|
140
|
+
- `getBlockHeights()`
|
|
141
|
+
- `getLogEventsByAddress()`
|
|
142
|
+
- `getLogEventsByTopicHash()`
|
|
143
|
+
- `getChainCollections()`
|
|
144
|
+
- `getTokenIdsForContractWithMetadata()`
|
|
145
|
+
- `getAllTransactionsForAddress()`
|
|
146
|
+
|
|
147
|
+
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:
|
|
133
148
|
```ts
|
|
134
149
|
import { Client } from "@covalenthq/client-sdk";
|
|
135
150
|
|
|
@@ -140,14 +155,14 @@ const ApiServices = async () => {
|
|
|
140
155
|
}
|
|
141
156
|
}
|
|
142
157
|
```
|
|
143
|
-
|
|
158
|
+
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.
|
|
144
159
|
|
|
145
160
|
### Retry Mechanism
|
|
146
161
|
|
|
147
162
|
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.
|
|
148
163
|
|
|
149
164
|
### Error Handling
|
|
150
|
-
The
|
|
165
|
+
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.
|
|
151
166
|
```ts
|
|
152
167
|
❴
|
|
153
168
|
"data": ...,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Chains, Quotes } from "./Client";
|
|
1
|
+
import { Chains, Quotes, Response } from "./Client";
|
|
2
2
|
declare class BalancesResponse {
|
|
3
3
|
/** * The requested address. */
|
|
4
4
|
address: string;
|
|
@@ -128,23 +128,6 @@ declare class OhlcItem {
|
|
|
128
128
|
pretty_quote: string;
|
|
129
129
|
constructor(data: OhlcItem);
|
|
130
130
|
}
|
|
131
|
-
declare class Erc20TransfersResponse {
|
|
132
|
-
/** * The requested address. */
|
|
133
|
-
address: string;
|
|
134
|
-
/** * The timestamp when the response was generated. Useful to show data staleness to users. */
|
|
135
|
-
updated_at: Date;
|
|
136
|
-
/** * The requested quote currency eg: `USD`. */
|
|
137
|
-
quote_currency: string;
|
|
138
|
-
/** * The requested chain ID eg: `1`. */
|
|
139
|
-
chain_id: number;
|
|
140
|
-
/** * The requested chain name eg: `eth-mainnet`. */
|
|
141
|
-
chain_name: string;
|
|
142
|
-
/** * List of response items. */
|
|
143
|
-
items: BlockTransactionWithContractTransfers[];
|
|
144
|
-
/** * Pagination metadata. */
|
|
145
|
-
pagination: Pagination;
|
|
146
|
-
constructor(data: Erc20TransfersResponse);
|
|
147
|
-
}
|
|
148
131
|
declare class BlockTransactionWithContractTransfers {
|
|
149
132
|
/** * The block signed timestamp in UTC. */
|
|
150
133
|
block_signed_at: Date;
|
|
@@ -179,17 +162,6 @@ declare class BlockTransactionWithContractTransfers {
|
|
|
179
162
|
transfers: TokenTransferItem[];
|
|
180
163
|
constructor(data: BlockTransactionWithContractTransfers);
|
|
181
164
|
}
|
|
182
|
-
declare class Pagination {
|
|
183
|
-
/** * True is there is another page. */
|
|
184
|
-
has_more: boolean;
|
|
185
|
-
/** * The requested page number. */
|
|
186
|
-
page_number: number;
|
|
187
|
-
/** * The requested number of items on the current page. */
|
|
188
|
-
page_size: number;
|
|
189
|
-
/** * The total number of items across all pages for this request. */
|
|
190
|
-
total_count: number;
|
|
191
|
-
constructor(data: Pagination);
|
|
192
|
-
}
|
|
193
165
|
declare class TokenTransferItem {
|
|
194
166
|
/** * The block signed timestamp in UTC. */
|
|
195
167
|
block_signed_at: Date;
|
|
@@ -228,19 +200,6 @@ declare class MethodCallsForTransfers {
|
|
|
228
200
|
method: string;
|
|
229
201
|
constructor(data: MethodCallsForTransfers);
|
|
230
202
|
}
|
|
231
|
-
declare class TokenHoldersResponse {
|
|
232
|
-
/** * The timestamp when the response was generated. Useful to show data staleness to users. */
|
|
233
|
-
updated_at: Date;
|
|
234
|
-
/** * The requested chain ID eg: `1`. */
|
|
235
|
-
chain_id: number;
|
|
236
|
-
/** * The requested chain name eg: `eth-mainnet`. */
|
|
237
|
-
chain_name: string;
|
|
238
|
-
/** * List of response items. */
|
|
239
|
-
items: TokenHolder[];
|
|
240
|
-
/** * Pagination metadata. */
|
|
241
|
-
pagination: Pagination;
|
|
242
|
-
constructor(data: TokenHoldersResponse);
|
|
243
|
-
}
|
|
244
203
|
declare class TokenHolder {
|
|
245
204
|
/** * Use contract decimals to format the token balance for display purposes - divide the balance by `10^{contract_decimals}`. */
|
|
246
205
|
contract_decimals: number;
|
|
@@ -316,16 +275,66 @@ declare class HistoricalBalanceItem {
|
|
|
316
275
|
nft_data: NftData[];
|
|
317
276
|
constructor(data: HistoricalBalanceItem);
|
|
318
277
|
}
|
|
278
|
+
export interface GetTokenBalancesForWalletAddressQueryParamOpts {
|
|
279
|
+
/** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
|
|
280
|
+
quoteCurrency?: Quotes;
|
|
281
|
+
/** * If `true`, NFTs will be included in the response. */
|
|
282
|
+
nft?: boolean;
|
|
283
|
+
/** * If `true`, only NFTs that have been cached will be included in the response. Helpful for faster response times. */
|
|
284
|
+
noNftFetch?: boolean;
|
|
285
|
+
/** * If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`. */
|
|
286
|
+
noSpam?: boolean;
|
|
287
|
+
/** * If `true`, the response shape is limited to a list of collections and token ids, omitting metadata and asset information. Helpful for faster response times and wallets holding a large number of NFTs. */
|
|
288
|
+
noNftAssetMetadata?: boolean;
|
|
289
|
+
}
|
|
290
|
+
export interface GetHistoricalPortfolioForWalletAddressQueryParamOpts {
|
|
291
|
+
/** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
|
|
292
|
+
quoteCurrency?: Quotes;
|
|
293
|
+
/** * The number of days to return data for. Defaults to 30 days. */
|
|
294
|
+
days?: number;
|
|
295
|
+
}
|
|
296
|
+
export interface GetErc20TransfersForWalletAddressQueryParamOpts {
|
|
297
|
+
/** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
|
|
298
|
+
quoteCurrency?: Quotes;
|
|
299
|
+
/** * The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically. */
|
|
300
|
+
contractAddress?: string;
|
|
301
|
+
/** * The block height to start from, defaults to `0`. */
|
|
302
|
+
startingBlock?: number;
|
|
303
|
+
/** * The block height to end at, defaults to current block height. */
|
|
304
|
+
endingBlock?: number;
|
|
305
|
+
/** * Number of items per page. Omitting this parameter defaults to 100. */
|
|
306
|
+
pageSize?: number;
|
|
307
|
+
/** * 0-indexed page number to begin pagination. */
|
|
308
|
+
pageNumber?: number;
|
|
309
|
+
}
|
|
310
|
+
export interface GetTokenHoldersV2ForTokenAddressQueryParamOpts {
|
|
311
|
+
/** * Ending block to define a block range. Omitting this parameter defaults to the latest block height. */
|
|
312
|
+
blockHeight?: number;
|
|
313
|
+
/** * Number of items per page. Note: Currently, only values of `100` and `1000` are supported. Omitting this parameter defaults to 100. */
|
|
314
|
+
pageSize?: number;
|
|
315
|
+
/** * 0-indexed page number to begin pagination. */
|
|
316
|
+
pageNumber?: number;
|
|
317
|
+
}
|
|
318
|
+
export interface GetHistoricalTokenBalancesForWalletAddressQueryParamOpts {
|
|
319
|
+
/** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
|
|
320
|
+
quoteCurrency?: Quotes;
|
|
321
|
+
/** * If `true`, NFTs will be included in the response. */
|
|
322
|
+
nft?: boolean;
|
|
323
|
+
/** * If `true`, only NFTs that have been cached will be included in the response. Helpful for faster response times. */
|
|
324
|
+
noNftFetch?: boolean;
|
|
325
|
+
/** * If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`. */
|
|
326
|
+
noSpam?: boolean;
|
|
327
|
+
/** * If `true`, the response shape is limited to a list of collections and token ids, omitting metadata and asset information. Helpful for faster response times and wallets holding a large number of NFTs. */
|
|
328
|
+
noNftAssetMetadata?: boolean;
|
|
329
|
+
/** * Ending block to define a block range. Omitting this parameter defaults to the latest block height. */
|
|
330
|
+
blockHeight?: number;
|
|
331
|
+
/** * Ending date to define a block range (YYYY-MM-DD). Omitting this parameter defaults to the current date. */
|
|
332
|
+
date?: number;
|
|
333
|
+
}
|
|
319
334
|
/**
|
|
320
335
|
* Balances APIs
|
|
321
336
|
*
|
|
322
337
|
*/
|
|
323
|
-
export declare class Response<T> {
|
|
324
|
-
data: T;
|
|
325
|
-
error: boolean;
|
|
326
|
-
error_code: number;
|
|
327
|
-
error_message: string;
|
|
328
|
-
}
|
|
329
338
|
export declare class BalanceService {
|
|
330
339
|
private apiKey;
|
|
331
340
|
constructor(apiKey: string);
|
|
@@ -333,57 +342,64 @@ export declare class BalanceService {
|
|
|
333
342
|
*
|
|
334
343
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
335
344
|
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
336
|
-
* @param {
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
345
|
+
* @param {GetTokenBalancesForWalletAddressQueryParamOpts} queryParamOpts
|
|
346
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
347
|
+
* - `nft`: If `true`, NFTs will be included in the response.
|
|
348
|
+
* - `noNftFetch`: If `true`, only NFTs that have been cached will be included in the response. Helpful for faster response times.
|
|
349
|
+
* - `noSpam`: If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
|
|
350
|
+
* - `noNftAssetMetadata`: If `true`, the response shape is limited to a list of collections and token ids, omitting metadata and asset information. Helpful for faster response times and wallets holding a large number of NFTs.
|
|
341
351
|
*
|
|
342
352
|
*/
|
|
343
|
-
getTokenBalancesForWalletAddress(chainName: Chains, walletAddress: string,
|
|
353
|
+
getTokenBalancesForWalletAddress(chainName: Chains, walletAddress: string, queryParamOpts?: GetTokenBalancesForWalletAddressQueryParamOpts): Promise<Response<BalancesResponse>>;
|
|
344
354
|
/**
|
|
345
355
|
*
|
|
346
356
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
347
357
|
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
348
|
-
* @param {
|
|
349
|
-
*
|
|
358
|
+
* @param {GetHistoricalPortfolioForWalletAddressQueryParamOpts} queryParamOpts
|
|
359
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
360
|
+
* - `days`: The number of days to return data for. Defaults to 30 days.
|
|
350
361
|
*
|
|
351
362
|
*/
|
|
352
|
-
getHistoricalPortfolioForWalletAddress(chainName: Chains, walletAddress: string,
|
|
363
|
+
getHistoricalPortfolioForWalletAddress(chainName: Chains, walletAddress: string, queryParamOpts?: GetHistoricalPortfolioForWalletAddressQueryParamOpts): Promise<Response<PortfolioResponse>>;
|
|
353
364
|
/**
|
|
354
365
|
*
|
|
355
366
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
356
367
|
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
357
|
-
* @param {
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
368
|
+
* @param {GetErc20TransfersForWalletAddressQueryParamOpts} queryParamOpts
|
|
369
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
370
|
+
* - `contractAddress`: The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
371
|
+
* - `startingBlock`: The block height to start from, defaults to `0`.
|
|
372
|
+
* - `endingBlock`: The block height to end at, defaults to current block height.
|
|
373
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
374
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
361
375
|
*
|
|
362
376
|
*/
|
|
363
|
-
getErc20TransfersForWalletAddress(chainName: Chains, walletAddress: string,
|
|
377
|
+
getErc20TransfersForWalletAddress(chainName: Chains, walletAddress: string, queryParamOpts?: GetErc20TransfersForWalletAddressQueryParamOpts): AsyncIterable<BlockTransactionWithContractTransfers>;
|
|
364
378
|
/**
|
|
365
379
|
*
|
|
366
380
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
367
381
|
* @param {string} tokenAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
368
|
-
* @param {
|
|
369
|
-
*
|
|
370
|
-
*
|
|
382
|
+
* @param {GetTokenHoldersV2ForTokenAddressQueryParamOpts} queryParamOpts
|
|
383
|
+
* - `blockHeight`: Ending block to define a block range. Omitting this parameter defaults to the latest block height.
|
|
384
|
+
* - `pageSize`: Number of items per page. Note: Currently, only values of `100` and `1000` are supported. Omitting this parameter defaults to 100.
|
|
385
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
371
386
|
*
|
|
372
387
|
*/
|
|
373
|
-
getTokenHoldersV2ForTokenAddress(chainName: Chains, tokenAddress: string,
|
|
388
|
+
getTokenHoldersV2ForTokenAddress(chainName: Chains, tokenAddress: string, queryParamOpts?: GetTokenHoldersV2ForTokenAddressQueryParamOpts): AsyncIterable<TokenHolder>;
|
|
374
389
|
/**
|
|
375
390
|
*
|
|
376
391
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
377
392
|
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
378
|
-
* @param {
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
393
|
+
* @param {GetHistoricalTokenBalancesForWalletAddressQueryParamOpts} queryParamOpts
|
|
394
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
395
|
+
* - `nft`: If `true`, NFTs will be included in the response.
|
|
396
|
+
* - `noNftFetch`: If `true`, only NFTs that have been cached will be included in the response. Helpful for faster response times.
|
|
397
|
+
* - `noSpam`: If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
|
|
398
|
+
* - `noNftAssetMetadata`: If `true`, the response shape is limited to a list of collections and token ids, omitting metadata and asset information. Helpful for faster response times and wallets holding a large number of NFTs.
|
|
399
|
+
* - `blockHeight`: Ending block to define a block range. Omitting this parameter defaults to the latest block height.
|
|
400
|
+
* - `date`: Ending date to define a block range (YYYY-MM-DD). Omitting this parameter defaults to the current date.
|
|
385
401
|
*
|
|
386
402
|
*/
|
|
387
|
-
getHistoricalTokenBalancesForWalletAddress(chainName: Chains, walletAddress: string,
|
|
403
|
+
getHistoricalTokenBalancesForWalletAddress(chainName: Chains, walletAddress: string, queryParamOpts?: GetHistoricalTokenBalancesForWalletAddressQueryParamOpts): Promise<Response<HistoricalBalancesResponse>>;
|
|
388
404
|
}
|
|
389
405
|
export {};
|