@covalenthq/client-sdk 0.4.2 → 0.5.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.
Files changed (73) hide show
  1. package/README.md +62 -40
  2. package/dist/cjs/index.js +956 -239
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/services/BalanceService.d.ts +100 -0
  5. package/dist/cjs/services/BaseService.d.ts +17 -0
  6. package/dist/cjs/services/CovalentClient.d.ts +3 -3
  7. package/dist/cjs/services/NftService.d.ts +137 -1
  8. package/dist/cjs/services/SecurityService.d.ts +62 -0
  9. package/dist/cjs/services/TransactionService.d.ts +65 -0
  10. package/dist/cjs/services/XykService.d.ts +4 -0
  11. package/dist/cjs/util/types/BalanceServiceTypes.d.ts +38 -0
  12. package/dist/cjs/util/types/BaseServiceTypes.d.ts +16 -0
  13. package/dist/cjs/util/types/NftServiceTypes.d.ts +76 -0
  14. package/dist/cjs/util/types/SecurityServiceTypes.d.ts +50 -0
  15. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +27 -0
  16. package/dist/es/index.js +956 -239
  17. package/dist/es/index.js.map +1 -1
  18. package/dist/es/services/BalanceService.d.ts +100 -0
  19. package/dist/es/services/BaseService.d.ts +17 -0
  20. package/dist/es/services/CovalentClient.d.ts +3 -3
  21. package/dist/es/services/NftService.d.ts +137 -1
  22. package/dist/es/services/SecurityService.d.ts +62 -0
  23. package/dist/es/services/TransactionService.d.ts +65 -0
  24. package/dist/es/services/XykService.d.ts +4 -0
  25. package/dist/es/util/types/BalanceServiceTypes.d.ts +38 -0
  26. package/dist/es/util/types/BaseServiceTypes.d.ts +16 -0
  27. package/dist/es/util/types/NftServiceTypes.d.ts +76 -0
  28. package/dist/es/util/types/SecurityServiceTypes.d.ts +50 -0
  29. package/dist/es/util/types/TransactionServiceTypes.d.ts +27 -0
  30. package/dist/esm/index.js +956 -239
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/services/BalanceService.d.ts +100 -0
  33. package/dist/esm/services/BaseService.d.ts +17 -0
  34. package/dist/esm/services/CovalentClient.d.ts +3 -3
  35. package/dist/esm/services/NftService.d.ts +137 -1
  36. package/dist/esm/services/SecurityService.d.ts +62 -0
  37. package/dist/esm/services/TransactionService.d.ts +65 -0
  38. package/dist/esm/services/XykService.d.ts +4 -0
  39. package/dist/esm/util/types/BalanceServiceTypes.d.ts +38 -0
  40. package/dist/esm/util/types/BaseServiceTypes.d.ts +16 -0
  41. package/dist/esm/util/types/NftServiceTypes.d.ts +76 -0
  42. package/dist/esm/util/types/SecurityServiceTypes.d.ts +50 -0
  43. package/dist/esm/util/types/TransactionServiceTypes.d.ts +27 -0
  44. package/dist/services/BalanceService.d.ts +100 -0
  45. package/dist/services/BalanceService.js +193 -6
  46. package/dist/services/BalanceService.js.map +1 -1
  47. package/dist/services/BaseService.d.ts +17 -0
  48. package/dist/services/BaseService.js +23 -12
  49. package/dist/services/BaseService.js.map +1 -1
  50. package/dist/services/CovalentClient.d.ts +3 -3
  51. package/dist/services/CovalentClient.js +1 -1
  52. package/dist/services/NftService.d.ts +137 -1
  53. package/dist/services/NftService.js +294 -16
  54. package/dist/services/NftService.js.map +1 -1
  55. package/dist/services/PricingService.js +2 -2
  56. package/dist/services/PricingService.js.map +1 -1
  57. package/dist/services/SecurityService.d.ts +62 -0
  58. package/dist/services/SecurityService.js +103 -2
  59. package/dist/services/SecurityService.js.map +1 -1
  60. package/dist/services/TransactionService.d.ts +65 -0
  61. package/dist/services/TransactionService.js +116 -7
  62. package/dist/services/TransactionService.js.map +1 -1
  63. package/dist/services/XykService.d.ts +4 -0
  64. package/dist/services/XykService.js +34 -28
  65. package/dist/services/XykService.js.map +1 -1
  66. package/dist/util/ApiHelpers.js +1 -1
  67. package/dist/util/ApiHelpers.js.map +1 -1
  68. package/dist/util/types/BalanceServiceTypes.d.ts +38 -0
  69. package/dist/util/types/BaseServiceTypes.d.ts +16 -0
  70. package/dist/util/types/NftServiceTypes.d.ts +76 -0
  71. package/dist/util/types/SecurityServiceTypes.d.ts +50 -0
  72. package/dist/util/types/TransactionServiceTypes.d.ts +27 -0
  73. package/package.json +2 -1
@@ -282,3 +282,41 @@ export interface HistoricalBalanceItem {
282
282
  /** * NFT-specific data. */
283
283
  nft_data: NftData[];
284
284
  }
285
+ export interface TokenBalanceNativeResponse {
286
+ /** * The requested address. */
287
+ address: string;
288
+ /** * The timestamp when the response was generated. Useful to show data staleness to users. */
289
+ updated_at: Date;
290
+ /** * The requested quote currency eg: `USD`. */
291
+ quote_currency: string;
292
+ /** * The requested chain ID eg: `1`. */
293
+ chain_id: number;
294
+ /** * The requested chain name eg: `eth-mainnet`. */
295
+ chain_name: string;
296
+ /** * List of response items. */
297
+ items: NativeBalanceItem[];
298
+ }
299
+ export interface NativeBalanceItem {
300
+ /** * Use contract decimals to format the token balance for display purposes - divide the balance by `10^{contract_decimals}`. */
301
+ contract_decimals: number;
302
+ /** * The string returned by the `name()` method. */
303
+ contract_name: string;
304
+ /** * The ticker symbol for this contract. This field is set by a developer and non-unique across a network. */
305
+ contract_ticker_symbol: string;
306
+ /** * Use the relevant `contract_address` to lookup prices, logos, token transfers, etc. */
307
+ contract_address: string;
308
+ /** * A list of supported standard ERC interfaces, eg: `ERC20` and `ERC721`. */
309
+ supports_erc: string;
310
+ /** * The contract logo URL. */
311
+ logo_url: string;
312
+ /** * The height of the block. */
313
+ block_height: number;
314
+ /** * The asset balance. Use `contract_decimals` to scale this balance for display purposes. */
315
+ balance: bigint | null;
316
+ /** * The exchange rate for the requested quote currency. */
317
+ quote_rate: number;
318
+ /** * The current balance converted to fiat in `quote-currency`. */
319
+ quote: number;
320
+ /** * A prettier version of the quote for rendering purposes. */
321
+ pretty_quote: string;
322
+ }
@@ -133,11 +133,27 @@ export interface ChainItem {
133
133
  black_logo_url: string;
134
134
  /** * A white png logo url for the chain. */
135
135
  white_logo_url: string;
136
+ /** * The color theme for the chain. */
137
+ color_theme: ColorTheme;
136
138
  /** * True if the chain is an AppChain. */
137
139
  is_appchain: boolean;
138
140
  /** * The ChainItem the appchain is a part of. */
139
141
  appchain_of: ChainItem;
140
142
  }
143
+ export interface ColorTheme {
144
+ /** * The red color code. */
145
+ red: number;
146
+ /** * The green color code. */
147
+ green: number;
148
+ /** * The blue color code. */
149
+ blue: number;
150
+ /** * The alpha color code. */
151
+ alpha: number;
152
+ /** * The hexadecimal color code. */
153
+ hex: string;
154
+ /** * The color represented in css rgb() functional notation. */
155
+ css_rgb: string;
156
+ }
141
157
  export interface AllChainsStatusResponse {
142
158
  /** * The timestamp when the response was generated. Useful to show data staleness to users. */
143
159
  updated_at: Date;
@@ -219,3 +219,79 @@ export interface NftOwnershipForCollectionItem {
219
219
  type: string;
220
220
  nft_data: NftData;
221
221
  }
222
+ export interface NftMarketSaleCountResponse {
223
+ /** * The timestamp when the response was generated. Useful to show data staleness to users. */
224
+ updated_at: Date;
225
+ /** * The requested address. */
226
+ address: string;
227
+ /** * The requested quote currency eg: `USD`. */
228
+ quote_currency: string;
229
+ /** * The requested chain name eg: `eth-mainnet`. */
230
+ chain_name: string;
231
+ /** * The requested chain ID eg: `1`. */
232
+ chain_id: number;
233
+ /** * List of response items. */
234
+ items: MarketSaleCountItem[];
235
+ }
236
+ export interface MarketSaleCountItem {
237
+ /** * The timestamp of the date of sale. */
238
+ date: Date;
239
+ /** * The total amount of sales for the current day. */
240
+ sale_count: number;
241
+ }
242
+ export interface NftMarketVolumeResponse {
243
+ /** * The timestamp when the response was generated. Useful to show data staleness to users. */
244
+ updated_at: Date;
245
+ /** * The requested address. */
246
+ address: string;
247
+ /** * The requested quote currency eg: `USD`. */
248
+ quote_currency: string;
249
+ /** * The requested chain name eg: `eth-mainnet`. */
250
+ chain_name: string;
251
+ /** * The requested chain ID eg: `1`. */
252
+ chain_id: number;
253
+ /** * List of response items. */
254
+ items: MarketVolumeItem[];
255
+ }
256
+ export interface MarketVolumeItem {
257
+ /** * The timestamp of the date of sale. */
258
+ date: Date;
259
+ /** * The ticker symbol for the native currency. */
260
+ native_ticker_symbol: string;
261
+ /** * The contract name of the native currency. */
262
+ native_name: string;
263
+ /** * The current volume converted to fiat in `quote-currency`. */
264
+ volume_quote: number;
265
+ /** * The current volume in native currency. */
266
+ volume_native_quote: number;
267
+ /** * A prettier version of the volume quote for rendering purposes. */
268
+ pretty_volume_quote: string;
269
+ }
270
+ export interface NftMarketFloorPriceResponse {
271
+ /** * The timestamp when the response was generated. Useful to show data staleness to users. */
272
+ updated_at: Date;
273
+ /** * The requested address. */
274
+ address: string;
275
+ /** * The requested quote currency eg: `USD`. */
276
+ quote_currency: string;
277
+ /** * The requested chain name eg: `eth-mainnet`. */
278
+ chain_name: string;
279
+ /** * The requested chain ID eg: `1`. */
280
+ chain_id: number;
281
+ /** * List of response items. */
282
+ items: MarketFloorPriceItem[];
283
+ }
284
+ export interface MarketFloorPriceItem {
285
+ /** * The timestamp of the date of sale. */
286
+ date: Date;
287
+ /** * The ticker symbol for the native currency. */
288
+ native_ticker_symbol: string;
289
+ /** * The contract name of the native currency. */
290
+ native_name: string;
291
+ /** * The current floor price in native currency. */
292
+ floor_price_native_quote: number;
293
+ /** * The current floor price converted to fiat in `quote-currency`. */
294
+ floor_price_quote: number;
295
+ /** * A prettier version of the floor price quote for rendering purposes. */
296
+ pretty_floor_price_quote: string;
297
+ }
@@ -69,3 +69,53 @@ export interface TokenSpenderItem {
69
69
  pretty_value_at_risk_quote: string;
70
70
  risk_factor: string;
71
71
  }
72
+ export interface NftApprovalsResponse {
73
+ /** * The timestamp when the response was generated. Useful to show data staleness to users. */
74
+ updated_at: Date;
75
+ /** * The requested chain ID eg: `1`. */
76
+ chain_id: number;
77
+ /** * The requested chain name eg: `eth-mainnet`. */
78
+ chain_name: string;
79
+ /** * The requested address. */
80
+ address: string;
81
+ /** * List of response items. */
82
+ items: NftApprovalsItem[];
83
+ }
84
+ export interface NftApprovalsItem {
85
+ /** * Use the relevant `contract_address` to lookup prices, logos, token transfers, etc. */
86
+ contract_address: string;
87
+ /** * The label of the contract address. */
88
+ contract_address_label: string;
89
+ /** * The ticker symbol for this contract. This field is set by a developer and non-unique across a network. */
90
+ contract_ticker_symbol: string;
91
+ /** * List of asset balances held by the user. */
92
+ token_balances: NftApprovalBalance[];
93
+ /** * Contracts with non-zero approvals for this token. */
94
+ spenders: NftApprovalSpender[];
95
+ }
96
+ export interface NftApprovalBalance {
97
+ /** * The token's id. */
98
+ token_id: bigint | null;
99
+ /** * The NFT's token balance. */
100
+ token_balance: bigint | null;
101
+ }
102
+ export interface NftApprovalSpender {
103
+ /** * The height of the block. */
104
+ block_height: number;
105
+ /** * The offset is the position of the tx in the block. */
106
+ tx_offset: number;
107
+ /** * The offset is the position of the log entry within an event log." */
108
+ log_offset: number;
109
+ /** * The block signed timestamp in UTC. */
110
+ block_signed_at: Date;
111
+ /** * Most recent transaction that updated approval amounts for the token. */
112
+ tx_hash: string;
113
+ /** * Address of the contract with approval for the token. */
114
+ spender_address: string;
115
+ /** * Name of the contract with approval for the token. */
116
+ spender_address_label: string;
117
+ /** * The token ids approved. */
118
+ token_ids_approved: string;
119
+ /** * Remaining number of tokens granted to the spender by the approval. */
120
+ allowance: string;
121
+ }
@@ -61,6 +61,8 @@ export interface Transaction {
61
61
  lending_details: LendingReport;
62
62
  /** * The log events. */
63
63
  log_events: LogEvent[];
64
+ /** * The details related to the safe transaction. */
65
+ safe_details: SafeDetails[];
64
66
  }
65
67
  export interface DexReport {
66
68
  /** * The offset is the position of the log entry within an event log. */
@@ -249,6 +251,14 @@ export interface LendingReport {
249
251
  /** * Stores the wallet address of the user initiating the event. */
250
252
  user: string;
251
253
  }
254
+ export interface SafeDetails {
255
+ /** * The address that signed the safe transaction. */
256
+ owner_address: string;
257
+ /** * The signature of the owner for the safe transaction. */
258
+ signature: string;
259
+ /** * The type of safe signature used. */
260
+ signature_type: string;
261
+ }
252
262
  export interface RecentTransactionsResponse {
253
263
  /** * The requested address. */
254
264
  address: string;
@@ -310,3 +320,20 @@ export interface TransactionSummary {
310
320
  /** * The link to the transaction details using the Covalent API. */
311
321
  tx_detail_link: string;
312
322
  }
323
+ export interface TransactionsResponse {
324
+ /** * The requested address. */
325
+ address: string;
326
+ /** * The timestamp when the response was generated. Useful to show data staleness to users. */
327
+ updated_at: Date;
328
+ /** * The requested quote currency eg: `USD`. */
329
+ quote_currency: string;
330
+ /** * The requested chain ID eg: `1`. */
331
+ chain_id: number;
332
+ /** * The requested chain name eg: `eth-mainnet`. */
333
+ chain_name: string;
334
+ /** * The current page of the response. */
335
+ current_page: number;
336
+ links: PaginationLinks;
337
+ /** * List of response items. */
338
+ items: Transaction[];
339
+ }
@@ -137,6 +137,23 @@ declare class OhlcItem {
137
137
  pretty_quote: string;
138
138
  constructor(data: OhlcItem);
139
139
  }
140
+ declare class Erc20TransfersResponse {
141
+ /** * The requested address. */
142
+ address: string;
143
+ /** * The timestamp when the response was generated. Useful to show data staleness to users. */
144
+ updated_at: Date;
145
+ /** * The requested quote currency eg: `USD`. */
146
+ quote_currency: string;
147
+ /** * The requested chain ID eg: `1`. */
148
+ chain_id: number;
149
+ /** * The requested chain name eg: `eth-mainnet`. */
150
+ chain_name: string;
151
+ /** * List of response items. */
152
+ items: BlockTransactionWithContractTransfers[];
153
+ /** * Pagination metadata. */
154
+ pagination: Pagination;
155
+ constructor(data: Erc20TransfersResponse);
156
+ }
140
157
  declare class BlockTransactionWithContractTransfers {
141
158
  /** * The block signed timestamp in UTC. */
142
159
  block_signed_at: Date;
@@ -178,6 +195,17 @@ declare class BlockTransactionWithContractTransfers {
178
195
  transfers: TokenTransferItem[];
179
196
  constructor(data: BlockTransactionWithContractTransfers);
180
197
  }
198
+ declare class Pagination {
199
+ /** * True is there is another page. */
200
+ has_more: boolean;
201
+ /** * The requested page number. */
202
+ page_number: number;
203
+ /** * The requested number of items on the current page. */
204
+ page_size: number;
205
+ /** * The total number of items across all pages for this request. */
206
+ total_count: number;
207
+ constructor(data: Pagination);
208
+ }
181
209
  declare class TokenTransferItem {
182
210
  /** * The block signed timestamp in UTC. */
183
211
  block_signed_at: Date;
@@ -300,6 +328,46 @@ declare class HistoricalBalanceItem {
300
328
  nft_data: NftData[];
301
329
  constructor(data: HistoricalBalanceItem);
302
330
  }
331
+ declare class TokenBalanceNativeResponse {
332
+ /** * The requested address. */
333
+ address: string;
334
+ /** * The timestamp when the response was generated. Useful to show data staleness to users. */
335
+ updated_at: Date;
336
+ /** * The requested quote currency eg: `USD`. */
337
+ quote_currency: string;
338
+ /** * The requested chain ID eg: `1`. */
339
+ chain_id: number;
340
+ /** * The requested chain name eg: `eth-mainnet`. */
341
+ chain_name: string;
342
+ /** * List of response items. */
343
+ items: NativeBalanceItem[];
344
+ constructor(data: TokenBalanceNativeResponse);
345
+ }
346
+ declare class NativeBalanceItem {
347
+ /** * Use contract decimals to format the token balance for display purposes - divide the balance by `10^{contract_decimals}`. */
348
+ contract_decimals: number;
349
+ /** * The string returned by the `name()` method. */
350
+ contract_name: string;
351
+ /** * The ticker symbol for this contract. This field is set by a developer and non-unique across a network. */
352
+ contract_ticker_symbol: string;
353
+ /** * Use the relevant `contract_address` to lookup prices, logos, token transfers, etc. */
354
+ contract_address: string;
355
+ /** * A list of supported standard ERC interfaces, eg: `ERC20` and `ERC721`. */
356
+ supports_erc: string;
357
+ /** * The contract logo URL. */
358
+ logo_url: string;
359
+ /** * The height of the block. */
360
+ block_height: number;
361
+ /** * The asset balance. Use `contract_decimals` to scale this balance for display purposes. */
362
+ balance: bigint | null;
363
+ /** * The exchange rate for the requested quote currency. */
364
+ quote_rate: number;
365
+ /** * The current balance converted to fiat in `quote-currency`. */
366
+ quote: number;
367
+ /** * A prettier version of the quote for rendering purposes. */
368
+ pretty_quote: string;
369
+ constructor(data: NativeBalanceItem);
370
+ }
303
371
  export interface GetTokenBalancesForWalletAddressQueryParamOpts {
304
372
  /** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
305
373
  quoteCurrency?: Quote;
@@ -356,6 +424,12 @@ export interface GetHistoricalTokenBalancesForWalletAddressQueryParamOpts {
356
424
  /** * Ending date to define a block range (YYYY-MM-DD). Omitting this parameter defaults to the current date. */
357
425
  date?: number;
358
426
  }
427
+ export interface GetNativeTokenBalanceQueryParamOpts {
428
+ /** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
429
+ quoteCurrency?: Quote;
430
+ /** * Ending block to define a block range. Omitting this parameter defaults to the latest block height. */
431
+ blockHeight?: number;
432
+ }
359
433
  /**
360
434
  * Balances APIs
361
435
  *
@@ -409,6 +483,22 @@ export declare class BalanceService {
409
483
  *
410
484
  */
411
485
  getErc20TransfersForWalletAddress(chainName: Chain, walletAddress: string, queryParamOpts?: GetErc20TransfersForWalletAddressQueryParamOpts): AsyncIterable<BlockTransactionWithContractTransfers>;
486
+ /**
487
+ *
488
+ * Commonly used to render the transfer-in and transfer-out of a token along with historical prices from an address.
489
+ *
490
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
491
+ * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
492
+ * @param {GetErc20TransfersForWalletAddressQueryParamOpts} queryParamOpts
493
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
494
+ * - `contractAddress`: The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
495
+ * - `startingBlock`: The block height to start from, defaults to `0`.
496
+ * - `endingBlock`: The block height to end at, defaults to current block height.
497
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
498
+ * - `pageNumber`: 0-indexed page number to begin pagination.
499
+ *
500
+ */
501
+ getErc20TransfersForWalletAddressByPage(chainName: Chain, walletAddress: string, queryParamOpts?: GetErc20TransfersForWalletAddressQueryParamOpts): Promise<Response<Erc20TransfersResponse>>;
412
502
  /**
413
503
  *
414
504
  * Commonly used to 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.
@@ -439,5 +529,15 @@ export declare class BalanceService {
439
529
  *
440
530
  */
441
531
  getHistoricalTokenBalancesForWalletAddress(chainName: Chain, walletAddress: string, queryParamOpts?: GetHistoricalTokenBalancesForWalletAddressQueryParamOpts): Promise<Response<HistoricalBalancesResponse>>;
532
+ /**
533
+ *
534
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
535
+ * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
536
+ * @param {GetNativeTokenBalanceQueryParamOpts} queryParamOpts
537
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
538
+ * - `blockHeight`: Ending block to define a block range. Omitting this parameter defaults to the latest block height.
539
+ *
540
+ */
541
+ getNativeTokenBalance(chainName: Chain, walletAddress: string, queryParamOpts?: GetNativeTokenBalanceQueryParamOpts): Promise<Response<TokenBalanceNativeResponse>>;
442
542
  }
443
543
  export {};
@@ -232,6 +232,31 @@ class HistoricalBalanceItem {
232
232
  this.nft_data = data.nft_data && data.nft_data !== null ? data.nft_data.map((itemData) => new NftData(itemData)) : null;
233
233
  }
234
234
  }
235
+ class TokenBalanceNativeResponse {
236
+ constructor(data) {
237
+ this.address = data.address;
238
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
239
+ this.quote_currency = data.quote_currency;
240
+ this.chain_id = data.chain_id;
241
+ this.chain_name = data.chain_name;
242
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new NativeBalanceItem(itemData)) : null;
243
+ }
244
+ }
245
+ class NativeBalanceItem {
246
+ constructor(data) {
247
+ this.contract_decimals = data.contract_decimals;
248
+ this.contract_name = data.contract_name;
249
+ this.contract_ticker_symbol = data.contract_ticker_symbol;
250
+ this.contract_address = data.contract_address;
251
+ this.supports_erc = data.supports_erc;
252
+ this.logo_url = data.logo_url;
253
+ this.block_height = data.block_height;
254
+ this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
255
+ this.quote_rate = data.quote_rate;
256
+ this.quote = data.quote;
257
+ this.pretty_quote = data.pretty_quote;
258
+ }
259
+ }
235
260
  /**
236
261
  * Balances APIs
237
262
  *
@@ -315,7 +340,7 @@ export class BalanceService {
315
340
  data: dataClass,
316
341
  error: data.error,
317
342
  error_code: data ? data.error_code : response.status,
318
- error_message: data ? data.error_message : "401 Authorization Required"
343
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
319
344
  };
320
345
  }
321
346
  catch (error) {
@@ -324,7 +349,7 @@ export class BalanceService {
324
349
  data: null,
325
350
  error: true,
326
351
  error_code: data ? data.error_code : response.status,
327
- error_message: data ? data.error_message : "401 Authorization Required"
352
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
328
353
  };
329
354
  }
330
355
  }
@@ -389,7 +414,7 @@ export class BalanceService {
389
414
  data: dataClass,
390
415
  error: data.error,
391
416
  error_code: data ? data.error_code : response.status,
392
- error_message: data ? data.error_message : "401 Authorization Required"
417
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
393
418
  };
394
419
  }
395
420
  catch (error) {
@@ -398,7 +423,7 @@ export class BalanceService {
398
423
  data: null,
399
424
  error: true,
400
425
  error_code: data ? data.error_code : response.status,
401
- error_message: data ? data.error_message : "401 Authorization Required"
426
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
402
427
  };
403
428
  }
404
429
  }
@@ -453,6 +478,96 @@ export class BalanceService {
453
478
  }
454
479
  }
455
480
  }
481
+ /**
482
+ *
483
+ * Commonly used to render the transfer-in and transfer-out of a token along with historical prices from an address.
484
+ *
485
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
486
+ * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
487
+ * @param {GetErc20TransfersForWalletAddressQueryParamOpts} queryParamOpts
488
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
489
+ * - `contractAddress`: The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
490
+ * - `startingBlock`: The block height to start from, defaults to `0`.
491
+ * - `endingBlock`: The block height to end at, defaults to current block height.
492
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
493
+ * - `pageNumber`: 0-indexed page number to begin pagination.
494
+ *
495
+ */
496
+ async getErc20TransfersForWalletAddressByPage(chainName, walletAddress, queryParamOpts) {
497
+ let success = false;
498
+ let data;
499
+ let response;
500
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
501
+ while (!success) {
502
+ try {
503
+ const urlParams = new URLSearchParams();
504
+ if (queryParamOpts?.quoteCurrency !== undefined) {
505
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
506
+ }
507
+ if (queryParamOpts?.contractAddress !== undefined) {
508
+ urlParams.append("contract-address", queryParamOpts?.contractAddress.toString());
509
+ }
510
+ if (queryParamOpts?.startingBlock !== undefined) {
511
+ urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
512
+ }
513
+ if (queryParamOpts?.endingBlock !== undefined) {
514
+ urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
515
+ }
516
+ if (queryParamOpts?.pageSize !== undefined) {
517
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
518
+ }
519
+ if (queryParamOpts?.pageNumber !== undefined) {
520
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
521
+ }
522
+ let startTime;
523
+ if (this.debug) {
524
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
525
+ }
526
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/?${urlParams}`, {
527
+ headers: {
528
+ "Authorization": `Bearer ${this.apiKey}`,
529
+ "X-Requested-With": userAgent
530
+ }
531
+ }));
532
+ debugOutput(response.url, response.status, startTime);
533
+ if (response.status === 429) {
534
+ try {
535
+ data = await this.LIMIT(() => backoff.backOff(response.url));
536
+ }
537
+ catch (error) {
538
+ success = true;
539
+ return {
540
+ data: null,
541
+ error: true,
542
+ error_code: response.status,
543
+ error_message: error.message
544
+ };
545
+ }
546
+ }
547
+ else {
548
+ data = await response.json();
549
+ }
550
+ const dataClass = new Erc20TransfersResponse(data.data);
551
+ checkAndModifyResponse(dataClass);
552
+ success = true;
553
+ return {
554
+ data: dataClass,
555
+ error: data.error,
556
+ error_code: data ? data.error_code : response.status,
557
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
558
+ };
559
+ }
560
+ catch (error) {
561
+ success = true;
562
+ return {
563
+ data: null,
564
+ error: true,
565
+ error_code: data ? data.error_code : response.status,
566
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
567
+ };
568
+ }
569
+ }
570
+ }
456
571
  /**
457
572
  *
458
573
  * Commonly used to 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.
@@ -571,7 +686,79 @@ export class BalanceService {
571
686
  data: dataClass,
572
687
  error: data.error,
573
688
  error_code: data ? data.error_code : response.status,
574
- error_message: data ? data.error_message : "401 Authorization Required"
689
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
690
+ };
691
+ }
692
+ catch (error) {
693
+ success = true;
694
+ return {
695
+ data: null,
696
+ error: true,
697
+ error_code: data ? data.error_code : response.status,
698
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
699
+ };
700
+ }
701
+ }
702
+ }
703
+ /**
704
+ *
705
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
706
+ * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
707
+ * @param {GetNativeTokenBalanceQueryParamOpts} queryParamOpts
708
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
709
+ * - `blockHeight`: Ending block to define a block range. Omitting this parameter defaults to the latest block height.
710
+ *
711
+ */
712
+ async getNativeTokenBalance(chainName, walletAddress, queryParamOpts) {
713
+ let success = false;
714
+ let data;
715
+ let response;
716
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
717
+ while (!success) {
718
+ try {
719
+ const urlParams = new URLSearchParams();
720
+ if (queryParamOpts?.quoteCurrency !== undefined) {
721
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
722
+ }
723
+ if (queryParamOpts?.blockHeight !== undefined) {
724
+ urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
725
+ }
726
+ let startTime;
727
+ if (this.debug) {
728
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
729
+ }
730
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_native/?${urlParams}`, {
731
+ headers: {
732
+ "Authorization": `Bearer ${this.apiKey}`,
733
+ "X-Requested-With": userAgent
734
+ }
735
+ }));
736
+ debugOutput(response.url, response.status, startTime);
737
+ if (response.status === 429) {
738
+ try {
739
+ data = await this.LIMIT(() => backoff.backOff(response.url));
740
+ }
741
+ catch (error) {
742
+ success = true;
743
+ return {
744
+ data: null,
745
+ error: true,
746
+ error_code: response.status,
747
+ error_message: error.message
748
+ };
749
+ }
750
+ }
751
+ else {
752
+ data = await response.json();
753
+ }
754
+ const dataClass = new TokenBalanceNativeResponse(data.data);
755
+ checkAndModifyResponse(dataClass);
756
+ success = true;
757
+ return {
758
+ data: dataClass,
759
+ error: data.error,
760
+ error_code: data ? data.error_code : response.status,
761
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
575
762
  };
576
763
  }
577
764
  catch (error) {
@@ -580,7 +767,7 @@ export class BalanceService {
580
767
  data: null,
581
768
  error: true,
582
769
  error_code: data ? data.error_code : response.status,
583
- error_message: data ? data.error_message : "401 Authorization Required"
770
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
584
771
  };
585
772
  }
586
773
  }