@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.
Files changed (116) hide show
  1. package/README.md +64 -14
  2. package/dist/cjs/index.d.ts +9 -0
  3. package/dist/cjs/index.js +4619 -0
  4. package/dist/cjs/index.js.map +1 -0
  5. package/dist/cjs/services/BalanceService.d.ts +443 -0
  6. package/dist/cjs/services/BaseService.d.ts +357 -0
  7. package/dist/cjs/services/CovalentClient.d.ts +65 -0
  8. package/dist/cjs/services/NftService.d.ts +484 -0
  9. package/dist/cjs/services/PricingService.d.ts +88 -0
  10. package/dist/cjs/services/SecurityService.d.ts +96 -0
  11. package/dist/cjs/services/TransactionService.d.ts +440 -0
  12. package/dist/cjs/services/XykService.d.ts +682 -0
  13. package/dist/cjs/util/ApiHelpers.d.ts +5 -0
  14. package/dist/cjs/util/backoff.d.ts +11 -0
  15. package/dist/cjs/util/types/BalanceServiceTypes.d.ts +284 -0
  16. package/dist/cjs/util/types/BaseServiceTypes.d.ts +180 -0
  17. package/dist/cjs/util/types/GenericTypes.d.ts +96 -0
  18. package/dist/cjs/util/types/NftServiceTypes.d.ts +221 -0
  19. package/dist/cjs/util/types/PricingServiceTypes.d.ts +31 -0
  20. package/dist/cjs/util/types/SecurityServiceTypes.d.ts +71 -0
  21. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +312 -0
  22. package/dist/cjs/util/types/XykServiceTypes.d.ts +479 -0
  23. package/dist/es/index.d.ts +9 -0
  24. package/dist/es/index.js +4616 -0
  25. package/dist/es/index.js.map +1 -0
  26. package/dist/es/services/BalanceService.d.ts +443 -0
  27. package/dist/es/services/BaseService.d.ts +357 -0
  28. package/dist/es/services/CovalentClient.d.ts +65 -0
  29. package/dist/es/services/NftService.d.ts +484 -0
  30. package/dist/es/services/PricingService.d.ts +88 -0
  31. package/dist/es/services/SecurityService.d.ts +96 -0
  32. package/dist/es/services/TransactionService.d.ts +440 -0
  33. package/dist/es/services/XykService.d.ts +682 -0
  34. package/dist/es/util/ApiHelpers.d.ts +5 -0
  35. package/dist/es/util/backoff.d.ts +11 -0
  36. package/dist/es/util/types/BalanceServiceTypes.d.ts +284 -0
  37. package/dist/es/util/types/BaseServiceTypes.d.ts +180 -0
  38. package/dist/es/util/types/GenericTypes.d.ts +96 -0
  39. package/dist/es/util/types/NftServiceTypes.d.ts +221 -0
  40. package/dist/es/util/types/PricingServiceTypes.d.ts +31 -0
  41. package/dist/es/util/types/SecurityServiceTypes.d.ts +71 -0
  42. package/dist/es/util/types/TransactionServiceTypes.d.ts +312 -0
  43. package/dist/es/util/types/XykServiceTypes.d.ts +479 -0
  44. package/dist/esm/index.d.ts +9 -0
  45. package/dist/esm/index.js +4616 -0
  46. package/dist/esm/index.js.map +1 -0
  47. package/dist/esm/services/BalanceService.d.ts +443 -0
  48. package/dist/esm/services/BaseService.d.ts +357 -0
  49. package/dist/esm/services/CovalentClient.d.ts +65 -0
  50. package/dist/esm/services/NftService.d.ts +484 -0
  51. package/dist/esm/services/PricingService.d.ts +88 -0
  52. package/dist/esm/services/SecurityService.d.ts +96 -0
  53. package/dist/esm/services/TransactionService.d.ts +440 -0
  54. package/dist/esm/services/XykService.d.ts +682 -0
  55. package/dist/esm/util/ApiHelpers.d.ts +5 -0
  56. package/dist/esm/util/backoff.d.ts +11 -0
  57. package/dist/esm/util/types/BalanceServiceTypes.d.ts +284 -0
  58. package/dist/esm/util/types/BaseServiceTypes.d.ts +180 -0
  59. package/dist/esm/util/types/GenericTypes.d.ts +96 -0
  60. package/dist/esm/util/types/NftServiceTypes.d.ts +221 -0
  61. package/dist/esm/util/types/PricingServiceTypes.d.ts +31 -0
  62. package/dist/esm/util/types/SecurityServiceTypes.d.ts +71 -0
  63. package/dist/esm/util/types/TransactionServiceTypes.d.ts +312 -0
  64. package/dist/esm/util/types/XykServiceTypes.d.ts +479 -0
  65. package/dist/index.d.ts +1 -1
  66. package/dist/index.js +9 -27
  67. package/dist/index.js.map +1 -1
  68. package/dist/services/BalanceService.d.ts +49 -11
  69. package/dist/services/BalanceService.js +110 -81
  70. package/dist/services/BalanceService.js.map +1 -1
  71. package/dist/services/BaseService.d.ts +46 -10
  72. package/dist/services/BaseService.js +193 -145
  73. package/dist/services/BaseService.js.map +1 -1
  74. package/dist/services/CovalentClient.d.ts +65 -0
  75. package/dist/services/CovalentClient.js +44 -0
  76. package/dist/services/CovalentClient.js.map +1 -0
  77. package/dist/services/NftService.d.ts +52 -22
  78. package/dist/services/NftService.js +236 -235
  79. package/dist/services/NftService.js.map +1 -1
  80. package/dist/services/PricingService.d.ts +8 -3
  81. package/dist/services/PricingService.js +43 -37
  82. package/dist/services/PricingService.js.map +1 -1
  83. package/dist/services/SecurityService.d.ts +9 -3
  84. package/dist/services/SecurityService.js +38 -31
  85. package/dist/services/SecurityService.js.map +1 -1
  86. package/dist/services/TransactionService.d.ts +41 -9
  87. package/dist/services/TransactionService.js +133 -100
  88. package/dist/services/TransactionService.js.map +1 -1
  89. package/dist/services/XykService.d.ts +81 -19
  90. package/dist/services/XykService.js +451 -278
  91. package/dist/services/XykService.js.map +1 -1
  92. package/dist/util/ApiHelpers.d.ts +2 -1
  93. package/dist/util/ApiHelpers.js +57 -36
  94. package/dist/util/ApiHelpers.js.map +1 -1
  95. package/dist/util/backoff.d.ts +5 -3
  96. package/dist/util/backoff.js +35 -13
  97. package/dist/util/backoff.js.map +1 -1
  98. package/dist/util/types/BalanceServiceTypes.d.ts +25 -0
  99. package/dist/util/types/BalanceServiceTypes.js +1 -2
  100. package/dist/util/types/BaseServiceTypes.d.ts +8 -0
  101. package/dist/util/types/BaseServiceTypes.js +1 -2
  102. package/dist/util/types/GenericTypes.d.ts +7 -0
  103. package/dist/util/types/GenericTypes.js +1 -2
  104. package/dist/util/types/NftServiceTypes.d.ts +10 -2
  105. package/dist/util/types/NftServiceTypes.js +1 -2
  106. package/dist/util/types/PricingServiceTypes.js +1 -2
  107. package/dist/util/types/SecurityServiceTypes.d.ts +1 -0
  108. package/dist/util/types/SecurityServiceTypes.js +1 -2
  109. package/dist/util/types/TransactionServiceTypes.d.ts +14 -2
  110. package/dist/util/types/TransactionServiceTypes.js +1 -2
  111. package/dist/util/types/XykServiceTypes.d.ts +20 -6
  112. package/dist/util/types/XykServiceTypes.js +1 -2
  113. package/package.json +19 -4
  114. package/dist/services/Client.d.ts +0 -29
  115. package/dist/services/Client.js +0 -30
  116. package/dist/services/Client.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { Chains, Quotes, Response } from "./Client";
1
+ import { Chain, Quote, Response } from "./CovalentClient";
2
2
  declare class TransactionResponse {
3
3
  /** * The timestamp when the response was generated. Useful to show data staleness to users. */
4
4
  updated_at: Date;
@@ -15,15 +15,23 @@ declare class Transaction {
15
15
  block_signed_at: Date;
16
16
  /** * The height of the block. */
17
17
  block_height: number;
18
+ /** * The hash of the block. Use it to remove transactions from re-org-ed blocks. */
19
+ block_hash: string;
18
20
  /** * The requested transaction hash. */
19
21
  tx_hash: string;
20
22
  /** * The offset is the position of the tx in the block. */
21
23
  tx_offset: number;
22
24
  /** * Indicates whether a transaction failed or succeeded. */
23
25
  successful: boolean;
26
+ /** * The sender's wallet address. */
24
27
  from_address: string;
28
+ /** * The address of the miner. */
29
+ miner_address: string;
30
+ /** * The label of `from` address. */
25
31
  from_address_label: string;
32
+ /** * The receiver's wallet address. */
26
33
  to_address: string;
34
+ /** * The label of `to` address. */
27
35
  to_address_label: string;
28
36
  /** * The value attached to this tx. */
29
37
  value: bigint | null;
@@ -34,7 +42,9 @@ declare class Transaction {
34
42
  /** * The requested chain native gas token metadata. */
35
43
  gas_metadata: ContractMetadata;
36
44
  gas_offered: string;
45
+ /** * The gas spent for this tx. */
37
46
  gas_spent: string;
47
+ /** * The gas price at the time of this tx. */
38
48
  gas_price: string;
39
49
  /** * The total transaction fees (`gas_price` * `gas_spent`) paid for this tx, denoted in wei. */
40
50
  fees_paid: bigint | null;
@@ -50,6 +60,7 @@ declare class Transaction {
50
60
  nft_sale_details: NftSalesReport;
51
61
  /** * The details for the lending protocol transaction. */
52
62
  lending_details: LendingReport;
63
+ /** * The log events. */
53
64
  log_events: LogEvent[];
54
65
  constructor(data: Transaction);
55
66
  }
@@ -69,6 +80,7 @@ declare class ContractMetadata {
69
80
  constructor(data: ContractMetadata);
70
81
  }
71
82
  declare class DexReport {
83
+ /** * The offset is the position of the log entry within an event log. */
72
84
  log_offset: number;
73
85
  /** * Stores the name of the protocol that facilitated the event. */
74
86
  protocol_name: string;
@@ -132,6 +144,7 @@ declare class DexReport {
132
144
  constructor(data: DexReport);
133
145
  }
134
146
  declare class NftSalesReport {
147
+ /** * The offset is the position of the log entry within an event log. */
135
148
  log_offset: number;
136
149
  /** * Stores the topic event hash. All events have a unique topic event hash. */
137
150
  topic0: string;
@@ -183,6 +196,7 @@ declare class NftSalesReport {
183
196
  constructor(data: NftSalesReport);
184
197
  }
185
198
  declare class LendingReport {
199
+ /** * The offset is the position of the log entry within an event log. */
186
200
  log_offset: number;
187
201
  /** * Stores the name of the lending protocol that facilitated the event. */
188
202
  protocol_name: string;
@@ -262,19 +276,26 @@ declare class LogEvent {
262
276
  block_height: number;
263
277
  /** * The offset is the position of the tx in the block. */
264
278
  tx_offset: number;
279
+ /** * The offset is the position of the log entry within an event log. */
265
280
  log_offset: number;
266
281
  /** * The requested transaction hash. */
267
282
  tx_hash: string;
283
+ /** * The log topics in raw data. */
268
284
  raw_log_topics: string;
269
285
  /** * Use contract decimals to format the token balance for display purposes - divide the balance by `10^{contract_decimals}`. */
270
286
  sender_contract_decimals: number;
287
+ /** * The name of the sender. */
271
288
  sender_name: string;
272
289
  sender_contract_ticker_symbol: string;
290
+ /** * The address of the sender. */
273
291
  sender_address: string;
292
+ /** * The label of the sender address. */
274
293
  sender_address_label: string;
275
294
  /** * The contract logo URL. */
276
295
  sender_logo_url: string;
296
+ /** * The log events in raw. */
277
297
  raw_log_data: string;
298
+ /** * The decoded item. */
278
299
  decoded: DecodedItem;
279
300
  constructor(data: LogEvent);
280
301
  }
@@ -336,7 +357,7 @@ declare class TransactionSummary {
336
357
  }
337
358
  export interface GetTransactionQueryParamOpts {
338
359
  /** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
339
- quoteCurrency?: Quotes;
360
+ quoteCurrency?: Quote;
340
361
  /** * Omit log events. */
341
362
  noLogs?: boolean;
342
363
  /** * Decoded DEX details including protocol (e.g. Uniswap), event (e.g 'add_liquidity') and tokens involved with historical prices. Additional 0.05 credits charged if data available. */
@@ -348,7 +369,7 @@ export interface GetTransactionQueryParamOpts {
348
369
  }
349
370
  export interface GetAllTransactionsForAddressQueryParamOpts {
350
371
  /** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
351
- quoteCurrency?: Quotes;
372
+ quoteCurrency?: Quote;
352
373
  /** * Omit log events. */
353
374
  noLogs?: boolean;
354
375
  /** * Sort the transactions in ascending chronological order. By default, it's set to `false` and returns transactions in descending chronological order. */
@@ -356,14 +377,19 @@ export interface GetAllTransactionsForAddressQueryParamOpts {
356
377
  }
357
378
  export interface GetTransactionsForBlockQueryParamOpts {
358
379
  /** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
359
- quoteCurrency?: Quotes;
380
+ quoteCurrency?: Quote;
360
381
  /** * Omit log events. */
361
382
  noLogs?: boolean;
362
383
  }
363
384
  export declare class TransactionService {
364
385
  private apiKey;
365
- constructor(apiKey: string);
386
+ private debug;
387
+ private threadCount;
388
+ private LIMIT;
389
+ constructor(apiKey: string, debug?: boolean, threadCount?: number);
366
390
  /**
391
+ *
392
+ * Commonly used to fetch and render a single transaction including its decoded log events. Additionally return semantically decoded information for DEX trades, lending and NFT sales.
367
393
  *
368
394
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
369
395
  * @param {string} txHash - The transaction hash.
@@ -375,8 +401,10 @@ export declare class TransactionService {
375
401
  * - `withLending`: Decoded lending details including protocol (e.g. Aave), event (e.g. 'deposit') and tokens involved with prices. Additional 0.05 credits charged if data available.
376
402
  *
377
403
  */
378
- getTransaction(chainName: Chains, txHash: string, queryParamOpts?: GetTransactionQueryParamOpts): Promise<Response<TransactionResponse>>;
404
+ getTransaction(chainName: Chain, txHash: string, queryParamOpts?: GetTransactionQueryParamOpts): Promise<Response<TransactionResponse>>;
379
405
  /**
406
+ *
407
+ * Commonly used to fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
380
408
  *
381
409
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
382
410
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -386,8 +414,10 @@ export declare class TransactionService {
386
414
  * - `blockSignedAtAsc`: Sort the transactions in ascending chronological order. By default, it's set to `false` and returns transactions in descending chronological order.
387
415
  *
388
416
  */
389
- getAllTransactionsForAddress(chainName: Chains, walletAddress: string, queryParamOpts?: GetAllTransactionsForAddressQueryParamOpts): AsyncIterable<Transaction>;
417
+ getAllTransactionsForAddress(chainName: Chain, walletAddress: string, queryParamOpts?: GetAllTransactionsForAddressQueryParamOpts): AsyncIterable<Transaction>;
390
418
  /**
419
+ *
420
+ * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
391
421
  *
392
422
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
393
423
  * @param {number} blockHeight - The requested block height.
@@ -396,13 +426,15 @@ export declare class TransactionService {
396
426
  * - `noLogs`: Omit log events.
397
427
  *
398
428
  */
399
- getTransactionsForBlock(chainName: Chains, blockHeight: number, queryParamOpts?: GetTransactionsForBlockQueryParamOpts): Promise<Response<TransactionsBlockResponse>>;
429
+ getTransactionsForBlock(chainName: Chain, blockHeight: number, queryParamOpts?: GetTransactionsForBlockQueryParamOpts): Promise<Response<TransactionsBlockResponse>>;
400
430
  /**
431
+ *
432
+ * Commonly used to fetch the earliest and latest transactions, and the transaction count for a wallet. Calculate the age of the wallet and the time it has been idle and quickly gain insights into their engagement with web3.
401
433
  *
402
434
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
403
435
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
404
436
  *
405
437
  */
406
- getTransactionSummary(chainName: Chains, walletAddress: string): Promise<Response<TransactionsSummaryResponse>>;
438
+ getTransactionSummary(chainName: Chain, walletAddress: string): Promise<Response<TransactionsSummaryResponse>>;
407
439
  }
408
440
  export {};
@@ -1,13 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransactionService = void 0;
4
- const Client_1 = require("./Client");
5
- const ApiHelpers_1 = require("../util/ApiHelpers");
6
- const date_fns_1 = require("date-fns");
7
- const backoff_1 = require("../util/backoff");
1
+ import { userAgent } from "./CovalentClient";
2
+ import { checkAndModifyResponse, debugOutput } from "../util/ApiHelpers";
3
+ import { parseISO } from "date-fns";
4
+ import { ExponentialBackoff } from "../util/backoff";
5
+ import pLimit from "p-limit";
8
6
  class TransactionResponse {
9
7
  constructor(data) {
10
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
8
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
11
9
  this.chain_id = data.chain_id;
12
10
  this.chain_name = data.chain_name;
13
11
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
@@ -15,12 +13,14 @@ class TransactionResponse {
15
13
  }
16
14
  class Transaction {
17
15
  constructor(data) {
18
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? (0, date_fns_1.parseISO)(data.block_signed_at.toString()) : null;
16
+ this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
19
17
  this.block_height = data.block_height;
18
+ this.block_hash = data.block_hash;
20
19
  this.tx_hash = data.tx_hash;
21
20
  this.tx_offset = data.tx_offset;
22
21
  this.successful = data.successful;
23
22
  this.from_address = data.from_address;
23
+ this.miner_address = data.miner_address;
24
24
  this.from_address_label = data.from_address_label;
25
25
  this.to_address = data.to_address;
26
26
  this.to_address_label = data.to_address_label;
@@ -169,7 +169,7 @@ class LendingReport {
169
169
  }
170
170
  class LogEvent {
171
171
  constructor(data) {
172
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? (0, date_fns_1.parseISO)(data.block_signed_at.toString()) : null;
172
+ this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
173
173
  this.block_height = data.block_height;
174
174
  this.tx_offset = data.tx_offset;
175
175
  this.log_offset = data.log_offset;
@@ -204,8 +204,7 @@ class Param {
204
204
  class RecentTransactionsResponse {
205
205
  constructor(data) {
206
206
  this.address = data.address;
207
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
208
- this.next_update_at = data.next_update_at && data.next_update_at !== null ? (0, date_fns_1.parseISO)(data.next_update_at.toString()) : null;
207
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
209
208
  this.quote_currency = data.quote_currency;
210
209
  this.chain_id = data.chain_id;
211
210
  this.chain_name = data.chain_name;
@@ -222,7 +221,7 @@ class PaginationLinks {
222
221
  }
223
222
  class TransactionsBlockResponse {
224
223
  constructor(data) {
225
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
224
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
226
225
  this.chain_id = data.chain_id;
227
226
  this.chain_name = data.chain_name;
228
227
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
@@ -230,7 +229,7 @@ class TransactionsBlockResponse {
230
229
  }
231
230
  class TransactionsSummaryResponse {
232
231
  constructor(data) {
233
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
232
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
234
233
  this.address = data.address;
235
234
  this.chain_id = data.chain_id;
236
235
  this.chain_name = data.chain_name;
@@ -246,7 +245,7 @@ class TransactionsSummary {
246
245
  }
247
246
  class TransactionSummary {
248
247
  constructor(data) {
249
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? (0, date_fns_1.parseISO)(data.block_signed_at.toString()) : null;
248
+ this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
250
249
  this.tx_hash = data.tx_hash;
251
250
  this.tx_detail_link = data.tx_detail_link;
252
251
  }
@@ -255,58 +254,72 @@ class TransactionSummary {
255
254
  * Transactions APIs
256
255
  *
257
256
  */
258
- async function* paginateEndpoint(url, apiKey, urlsParams) {
257
+ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
259
258
  let hasNext = true;
260
259
  let response;
261
260
  let data;
262
- const backoff = new backoff_1.ExponentialBackoff();
261
+ const backoff = new ExponentialBackoff(apiKey, debug);
262
+ const LIMIT = pLimit(threadCount);
263
263
  while (hasNext) {
264
264
  try {
265
- response = await fetch(`${url}?${urlsParams}`, {
265
+ let startTime;
266
+ if (debug) {
267
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
268
+ }
269
+ response = await LIMIT(() => fetch(`${url}?${urlsParams}`, {
266
270
  headers: {
267
271
  "Authorization": `Bearer ${apiKey}`,
268
- "X-Requested-With": Client_1.userAgent
272
+ "X-Requested-With": userAgent
269
273
  }
270
- });
271
- data = await response.json();
272
- if (data.error && data.error_code === 429) {
274
+ }));
275
+ debugOutput(response.url, response.status, startTime);
276
+ if (response.status === 429) {
273
277
  try {
274
- await backoff.backOff();
278
+ data = await LIMIT(() => backoff.backOff(response.url));
275
279
  }
276
280
  catch (error) {
277
281
  hasNext = false;
278
- console.error(`An error occurred ${data.error_code}:`, data.error_message);
282
+ throw new Error(`An error occurred ${response.status}: ${error.message}`);
279
283
  }
280
284
  }
281
285
  else {
282
- for (const tx of data.data.items) {
283
- const dataClass = new Transaction(tx);
284
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
285
- yield dataClass;
286
- }
287
- backoff.setNumAttempts(1);
288
- if (!data.error) {
289
- if ((data.data !== null) && data.data.links.prev === null) {
290
- hasNext = false;
291
- }
292
- url = data.data !== null ? data.data.links.prev : "";
293
- }
294
- else {
286
+ data = await response.json();
287
+ }
288
+ for (const tx of data.data.items) {
289
+ const dataClass = new Transaction(tx);
290
+ checkAndModifyResponse(dataClass);
291
+ yield dataClass;
292
+ }
293
+ backoff.setNumAttempts(1);
294
+ if (!data.error) {
295
+ if ((data.data !== null) && data.data.links.prev === null) {
295
296
  hasNext = false;
296
297
  }
298
+ url = data.data !== null ? data.data.links.prev : "";
299
+ }
300
+ else {
301
+ hasNext = false;
297
302
  }
298
303
  }
299
304
  catch (error) {
300
305
  hasNext = false;
301
- console.error(`An error occurred ${data ? data.error_code : response.status}: `, data ? data.error_message : "401 Authorization Required");
306
+ if (error.message.includes("An error occurred 429")) {
307
+ throw new Error(error.message);
308
+ }
309
+ throw new Error(`An error occurred ${data ? data.error_code : response.status}: ${data ? data.error_message : "401 Authorization Required"}`);
302
310
  }
303
311
  }
304
312
  }
305
- class TransactionService {
306
- constructor(apiKey) {
313
+ export class TransactionService {
314
+ constructor(apiKey, debug = false, threadCount = 3) {
307
315
  this.apiKey = apiKey;
316
+ this.debug = debug;
317
+ this.threadCount = threadCount;
318
+ this.LIMIT = pLimit(this.threadCount);
308
319
  }
309
320
  /**
321
+ *
322
+ * Commonly used to fetch and render a single transaction including its decoded log events. Additionally return semantically decoded information for DEX trades, lending and NFT sales.
310
323
  *
311
324
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
312
325
  * @param {string} txHash - The transaction hash.
@@ -322,7 +335,7 @@ class TransactionService {
322
335
  let success = false;
323
336
  let data;
324
337
  let response;
325
- const backoff = new backoff_1.ExponentialBackoff();
338
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
326
339
  while (!success) {
327
340
  try {
328
341
  const urlParams = new URLSearchParams();
@@ -341,38 +354,43 @@ class TransactionService {
341
354
  if (queryParamOpts?.withLending !== undefined) {
342
355
  urlParams.append("with-lending", queryParamOpts?.withLending.toString());
343
356
  }
344
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
357
+ let startTime;
358
+ if (this.debug) {
359
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
360
+ }
361
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
345
362
  headers: {
346
363
  "Authorization": `Bearer ${this.apiKey}`,
347
- "X-Requested-With": Client_1.userAgent
364
+ "X-Requested-With": userAgent
348
365
  }
349
- });
350
- data = await response.json();
351
- if (data.error && data.error_code === 429) {
366
+ }));
367
+ debugOutput(response.url, response.status, startTime);
368
+ if (response.status === 429) {
352
369
  try {
353
- await backoff.backOff();
370
+ data = await this.LIMIT(() => backoff.backOff(response.url));
354
371
  }
355
372
  catch (error) {
356
373
  success = true;
357
374
  return {
358
375
  data: null,
359
- error: data.error,
360
- error_code: data ? data.error_code : response.status,
361
- error_message: data ? data.error_message : "401 Authorization Required"
376
+ error: true,
377
+ error_code: response.status,
378
+ error_message: error.message
362
379
  };
363
380
  }
364
381
  }
365
382
  else {
366
- const dataClass = new TransactionResponse(data.data);
367
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
368
- success = true;
369
- return {
370
- data: dataClass,
371
- error: data.error,
372
- error_code: data ? data.error_code : response.status,
373
- error_message: data ? data.error_message : "401 Authorization Required"
374
- };
383
+ data = await response.json();
375
384
  }
385
+ const dataClass = new TransactionResponse(data.data);
386
+ checkAndModifyResponse(dataClass);
387
+ success = true;
388
+ return {
389
+ data: dataClass,
390
+ error: data.error,
391
+ error_code: data ? data.error_code : response.status,
392
+ error_message: data ? data.error_message : "401 Authorization Required"
393
+ };
376
394
  }
377
395
  catch (error) {
378
396
  success = true;
@@ -386,6 +404,8 @@ class TransactionService {
386
404
  }
387
405
  }
388
406
  /**
407
+ *
408
+ * Commonly used to fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
389
409
  *
390
410
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
391
411
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -410,18 +430,20 @@ class TransactionService {
410
430
  if (queryParamOpts?.blockSignedAtAsc !== undefined) {
411
431
  urlParams.append("block-signed-at-asc", queryParamOpts?.blockSignedAtAsc.toString());
412
432
  }
413
- for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams)) {
433
+ for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount)) {
414
434
  yield tx;
415
435
  }
416
436
  success = true;
417
437
  }
418
438
  catch (error) {
419
439
  success = true;
420
- return tx;
440
+ throw new Error(error.message);
421
441
  }
422
442
  }
423
443
  }
424
444
  /**
445
+ *
446
+ * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
425
447
  *
426
448
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
427
449
  * @param {number} blockHeight - The requested block height.
@@ -434,7 +456,7 @@ class TransactionService {
434
456
  let success = false;
435
457
  let data;
436
458
  let response;
437
- const backoff = new backoff_1.ExponentialBackoff();
459
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
438
460
  while (!success) {
439
461
  try {
440
462
  const urlParams = new URLSearchParams();
@@ -444,38 +466,43 @@ class TransactionService {
444
466
  if (queryParamOpts?.noLogs !== undefined) {
445
467
  urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
446
468
  }
447
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
469
+ let startTime;
470
+ if (this.debug) {
471
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
472
+ }
473
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
448
474
  headers: {
449
475
  "Authorization": `Bearer ${this.apiKey}`,
450
- "X-Requested-With": Client_1.userAgent
476
+ "X-Requested-With": userAgent
451
477
  }
452
- });
453
- data = await response.json();
454
- if (data.error && data.error_code === 429) {
478
+ }));
479
+ debugOutput(response.url, response.status, startTime);
480
+ if (response.status === 429) {
455
481
  try {
456
- await backoff.backOff();
482
+ data = await this.LIMIT(() => backoff.backOff(response.url));
457
483
  }
458
484
  catch (error) {
459
485
  success = true;
460
486
  return {
461
487
  data: null,
462
- error: data.error,
463
- error_code: data ? data.error_code : response.status,
464
- error_message: data ? data.error_message : "401 Authorization Required"
488
+ error: true,
489
+ error_code: response.status,
490
+ error_message: error.message
465
491
  };
466
492
  }
467
493
  }
468
494
  else {
469
- const dataClass = new TransactionsBlockResponse(data.data);
470
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
471
- success = true;
472
- return {
473
- data: dataClass,
474
- error: data.error,
475
- error_code: data ? data.error_code : response.status,
476
- error_message: data ? data.error_message : "401 Authorization Required"
477
- };
495
+ data = await response.json();
478
496
  }
497
+ const dataClass = new TransactionsBlockResponse(data.data);
498
+ checkAndModifyResponse(dataClass);
499
+ success = true;
500
+ return {
501
+ data: dataClass,
502
+ error: data.error,
503
+ error_code: data ? data.error_code : response.status,
504
+ error_message: data ? data.error_message : "401 Authorization Required"
505
+ };
479
506
  }
480
507
  catch (error) {
481
508
  success = true;
@@ -489,6 +516,8 @@ class TransactionService {
489
516
  }
490
517
  }
491
518
  /**
519
+ *
520
+ * Commonly used to fetch the earliest and latest transactions, and the transaction count for a wallet. Calculate the age of the wallet and the time it has been idle and quickly gain insights into their engagement with web3.
492
521
  *
493
522
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
494
523
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -498,42 +527,47 @@ class TransactionService {
498
527
  let success = false;
499
528
  let data;
500
529
  let response;
501
- const backoff = new backoff_1.ExponentialBackoff();
530
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
502
531
  while (!success) {
503
532
  try {
504
533
  const urlParams = new URLSearchParams();
505
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
534
+ let startTime;
535
+ if (this.debug) {
536
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
537
+ }
538
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
506
539
  headers: {
507
540
  "Authorization": `Bearer ${this.apiKey}`,
508
- "X-Requested-With": Client_1.userAgent
541
+ "X-Requested-With": userAgent
509
542
  }
510
- });
511
- data = await response.json();
512
- if (data.error && data.error_code === 429) {
543
+ }));
544
+ debugOutput(response.url, response.status, startTime);
545
+ if (response.status === 429) {
513
546
  try {
514
- await backoff.backOff();
547
+ data = await this.LIMIT(() => backoff.backOff(response.url));
515
548
  }
516
549
  catch (error) {
517
550
  success = true;
518
551
  return {
519
552
  data: null,
520
- error: data.error,
521
- error_code: data ? data.error_code : response.status,
522
- error_message: data ? data.error_message : "401 Authorization Required"
553
+ error: true,
554
+ error_code: response.status,
555
+ error_message: error.message
523
556
  };
524
557
  }
525
558
  }
526
559
  else {
527
- const dataClass = new TransactionsSummaryResponse(data.data);
528
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
529
- success = true;
530
- return {
531
- data: dataClass,
532
- error: data.error,
533
- error_code: data ? data.error_code : response.status,
534
- error_message: data ? data.error_message : "401 Authorization Required"
535
- };
560
+ data = await response.json();
536
561
  }
562
+ const dataClass = new TransactionsSummaryResponse(data.data);
563
+ checkAndModifyResponse(dataClass);
564
+ success = true;
565
+ return {
566
+ data: dataClass,
567
+ error: data.error,
568
+ error_code: data ? data.error_code : response.status,
569
+ error_message: data ? data.error_message : "401 Authorization Required"
570
+ };
537
571
  }
538
572
  catch (error) {
539
573
  success = true;
@@ -547,5 +581,4 @@ class TransactionService {
547
581
  }
548
582
  }
549
583
  }
550
- exports.TransactionService = TransactionService;
551
584
  //# sourceMappingURL=TransactionService.js.map