@covalenthq/client-sdk 0.7.5 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +25 -0
  2. package/dist/cjs/index.js +1183 -451
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/services/BalanceService.d.ts +15 -13
  5. package/dist/cjs/services/BaseService.d.ts +13 -11
  6. package/dist/cjs/services/CovalentClient.d.ts +8 -4
  7. package/dist/cjs/services/NftService.d.ts +19 -17
  8. package/dist/cjs/services/PricingService.d.ts +5 -3
  9. package/dist/cjs/services/SecurityService.d.ts +6 -4
  10. package/dist/cjs/services/TransactionService.d.ts +83 -12
  11. package/dist/cjs/services/XykService.d.ts +287 -22
  12. package/dist/cjs/util/ApiHelpers.d.ts +2 -1
  13. package/dist/cjs/util/backoff.d.ts +2 -1
  14. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +11 -0
  15. package/dist/cjs/util/types/XykServiceTypes.d.ts +160 -8
  16. package/dist/es/index.js +1183 -451
  17. package/dist/es/index.js.map +1 -1
  18. package/dist/es/services/BalanceService.d.ts +15 -13
  19. package/dist/es/services/BaseService.d.ts +13 -11
  20. package/dist/es/services/CovalentClient.d.ts +8 -4
  21. package/dist/es/services/NftService.d.ts +19 -17
  22. package/dist/es/services/PricingService.d.ts +5 -3
  23. package/dist/es/services/SecurityService.d.ts +6 -4
  24. package/dist/es/services/TransactionService.d.ts +83 -12
  25. package/dist/es/services/XykService.d.ts +287 -22
  26. package/dist/es/util/ApiHelpers.d.ts +2 -1
  27. package/dist/es/util/backoff.d.ts +2 -1
  28. package/dist/es/util/types/TransactionServiceTypes.d.ts +11 -0
  29. package/dist/es/util/types/XykServiceTypes.d.ts +160 -8
  30. package/dist/esm/index.js +1183 -451
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/services/BalanceService.d.ts +15 -13
  33. package/dist/esm/services/BaseService.d.ts +13 -11
  34. package/dist/esm/services/CovalentClient.d.ts +8 -4
  35. package/dist/esm/services/NftService.d.ts +19 -17
  36. package/dist/esm/services/PricingService.d.ts +5 -3
  37. package/dist/esm/services/SecurityService.d.ts +6 -4
  38. package/dist/esm/services/TransactionService.d.ts +83 -12
  39. package/dist/esm/services/XykService.d.ts +287 -22
  40. package/dist/esm/util/ApiHelpers.d.ts +2 -1
  41. package/dist/esm/util/backoff.d.ts +2 -1
  42. package/dist/esm/util/types/TransactionServiceTypes.d.ts +11 -0
  43. package/dist/esm/util/types/XykServiceTypes.d.ts +160 -8
  44. package/dist/services/BalanceService.d.ts +15 -13
  45. package/dist/services/BalanceService.js +47 -39
  46. package/dist/services/BalanceService.js.map +1 -1
  47. package/dist/services/BaseService.d.ts +13 -11
  48. package/dist/services/BaseService.js +77 -65
  49. package/dist/services/BaseService.js.map +1 -1
  50. package/dist/services/CovalentClient.d.ts +8 -4
  51. package/dist/services/CovalentClient.js +19 -19
  52. package/dist/services/CovalentClient.js.map +1 -1
  53. package/dist/services/NftService.d.ts +19 -17
  54. package/dist/services/NftService.js +96 -81
  55. package/dist/services/NftService.js.map +1 -1
  56. package/dist/services/PricingService.d.ts +5 -3
  57. package/dist/services/PricingService.js +10 -7
  58. package/dist/services/PricingService.js.map +1 -1
  59. package/dist/services/SecurityService.d.ts +6 -4
  60. package/dist/services/SecurityService.js +17 -13
  61. package/dist/services/SecurityService.js.map +1 -1
  62. package/dist/services/TransactionService.d.ts +83 -12
  63. package/dist/services/TransactionService.js +434 -90
  64. package/dist/services/TransactionService.js.map +1 -1
  65. package/dist/services/XykService.d.ts +287 -22
  66. package/dist/services/XykService.js +438 -93
  67. package/dist/services/XykService.js.map +1 -1
  68. package/dist/util/ApiHelpers.d.ts +2 -1
  69. package/dist/util/ApiHelpers.js +7 -6
  70. package/dist/util/ApiHelpers.js.map +1 -1
  71. package/dist/util/backoff.d.ts +2 -1
  72. package/dist/util/backoff.js +3 -3
  73. package/dist/util/backoff.js.map +1 -1
  74. package/dist/util/types/TransactionServiceTypes.d.ts +11 -0
  75. package/dist/util/types/XykServiceTypes.d.ts +160 -8
  76. package/package.json +1 -1
@@ -218,11 +218,13 @@ class Param {
218
218
  }
219
219
  }
220
220
  class RecentTransactionsResponse {
221
- constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
221
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
222
222
  this._debug = _debug;
223
223
  this._apiKey = _apiKey;
224
224
  this._threadCount = _threadCount;
225
225
  this._urlParams = _urlParams;
226
+ this._enableRetry = _enableRetry;
227
+ this._source = _source;
226
228
  this.address = data.address;
227
229
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
228
230
  this.quote_currency = data.quote_currency;
@@ -253,16 +255,17 @@ class RecentTransactionsResponse {
253
255
  error_message: "Invalid URL: URL link cannot be null"
254
256
  };
255
257
  }
258
+ const url = `${this.links.prev}?${this._urlParams}`;
256
259
  response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
257
260
  headers: {
258
261
  "Authorization": `Bearer ${this._apiKey}`,
259
- "X-Requested-With": userAgent
262
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
260
263
  }
261
264
  }));
262
- debugOutput(response.url, response.status ?? 429, startTime);
263
- if (response.status === null || response.status === 429) {
265
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
266
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
264
267
  try {
265
- data = await LIMIT(() => backoff.backOff(response.url));
268
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
266
269
  }
267
270
  catch (error) {
268
271
  success = true;
@@ -277,7 +280,7 @@ class RecentTransactionsResponse {
277
280
  else {
278
281
  data = await response.json();
279
282
  }
280
- const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
283
+ const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
281
284
  checkAndModifyResponse(dataClass);
282
285
  success = true;
283
286
  return {
@@ -292,8 +295,8 @@ class RecentTransactionsResponse {
292
295
  return {
293
296
  data: null,
294
297
  error: true,
295
- error_code: data ? data.error_code : response.status,
296
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
298
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
299
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
297
300
  };
298
301
  }
299
302
  }
@@ -319,16 +322,17 @@ class RecentTransactionsResponse {
319
322
  error_message: "Invalid URL: URL link cannot be null"
320
323
  };
321
324
  }
325
+ const url = `${this.links.next}?${this._urlParams}`;
322
326
  response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
323
327
  headers: {
324
328
  "Authorization": `Bearer ${this._apiKey}`,
325
- "X-Requested-With": userAgent
329
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
326
330
  }
327
331
  }));
328
- debugOutput(response.url, response.status ?? 429, startTime);
329
- if (response.status === null || response.status === 429) {
332
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
333
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
330
334
  try {
331
- data = await LIMIT(() => backoff.backOff(response.url));
335
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
332
336
  }
333
337
  catch (error) {
334
338
  success = true;
@@ -343,7 +347,7 @@ class RecentTransactionsResponse {
343
347
  else {
344
348
  data = await response.json();
345
349
  }
346
- const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
350
+ const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
347
351
  checkAndModifyResponse(dataClass);
348
352
  success = true;
349
353
  return {
@@ -358,8 +362,8 @@ class RecentTransactionsResponse {
358
362
  return {
359
363
  data: null,
360
364
  error: true,
361
- error_code: data ? data.error_code : response.status,
362
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
365
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
366
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
363
367
  };
364
368
  }
365
369
  }
@@ -371,6 +375,155 @@ class PaginationLinks {
371
375
  this.next = data.next;
372
376
  }
373
377
  }
378
+ class TransactionsBlockPageResponse {
379
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
380
+ this._debug = _debug;
381
+ this._apiKey = _apiKey;
382
+ this._threadCount = _threadCount;
383
+ this._urlParams = _urlParams;
384
+ this._enableRetry = _enableRetry;
385
+ this._source = _source;
386
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
387
+ this.chain_id = data.chain_id;
388
+ this.chain_name = data.chain_name;
389
+ this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
390
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
391
+ }
392
+ async prev() {
393
+ let success = false;
394
+ let data;
395
+ let response;
396
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
397
+ const LIMIT = pLimit(this._threadCount);
398
+ while (!success) {
399
+ try {
400
+ let startTime;
401
+ if (this._debug) {
402
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
403
+ }
404
+ if (this.links.prev === null) {
405
+ success = true;
406
+ return {
407
+ data: null,
408
+ error: true,
409
+ error_code: 400,
410
+ error_message: "Invalid URL: URL link cannot be null"
411
+ };
412
+ }
413
+ const url = `${this.links.prev}?${this._urlParams}`;
414
+ response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
415
+ headers: {
416
+ "Authorization": `Bearer ${this._apiKey}`,
417
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
418
+ }
419
+ }));
420
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
421
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
422
+ try {
423
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
424
+ }
425
+ catch (error) {
426
+ success = true;
427
+ return {
428
+ data: null,
429
+ error: true,
430
+ error_code: response.status ?? 429,
431
+ error_message: error.message
432
+ };
433
+ }
434
+ }
435
+ else {
436
+ data = await response.json();
437
+ }
438
+ const dataClass = new TransactionsBlockPageResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
439
+ checkAndModifyResponse(dataClass);
440
+ success = true;
441
+ return {
442
+ data: dataClass,
443
+ error: data.error,
444
+ error_code: data ? data.error_code : response.status,
445
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
446
+ };
447
+ }
448
+ catch (error) {
449
+ success = true;
450
+ return {
451
+ data: null,
452
+ error: true,
453
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
454
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
455
+ };
456
+ }
457
+ }
458
+ }
459
+ async next() {
460
+ let success = false;
461
+ let data;
462
+ let response;
463
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
464
+ const LIMIT = pLimit(this._threadCount);
465
+ while (!success) {
466
+ try {
467
+ let startTime;
468
+ if (this._debug) {
469
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
470
+ }
471
+ if (this.links.next === null) {
472
+ success = true;
473
+ return {
474
+ data: null,
475
+ error: true,
476
+ error_code: 400,
477
+ error_message: "Invalid URL: URL link cannot be null"
478
+ };
479
+ }
480
+ const url = `${this.links.next}?${this._urlParams}`;
481
+ response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
482
+ headers: {
483
+ "Authorization": `Bearer ${this._apiKey}`,
484
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
485
+ }
486
+ }));
487
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
488
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
489
+ try {
490
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
491
+ }
492
+ catch (error) {
493
+ success = true;
494
+ return {
495
+ data: null,
496
+ error: true,
497
+ error_code: response.status ?? 429,
498
+ error_message: error.message
499
+ };
500
+ }
501
+ }
502
+ else {
503
+ data = await response.json();
504
+ }
505
+ const dataClass = new TransactionsBlockPageResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
506
+ checkAndModifyResponse(dataClass);
507
+ success = true;
508
+ return {
509
+ data: dataClass,
510
+ error: data.error,
511
+ error_code: data ? data.error_code : response.status,
512
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
513
+ };
514
+ }
515
+ catch (error) {
516
+ success = true;
517
+ return {
518
+ data: null,
519
+ error: true,
520
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
521
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
522
+ };
523
+ }
524
+ }
525
+ }
526
+ }
374
527
  class TransactionsBlockResponse {
375
528
  constructor(data) {
376
529
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
@@ -403,11 +556,13 @@ class TransactionSummary {
403
556
  }
404
557
  }
405
558
  class TransactionsResponse {
406
- constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
559
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
407
560
  this._debug = _debug;
408
561
  this._apiKey = _apiKey;
409
562
  this._threadCount = _threadCount;
410
563
  this._urlParams = _urlParams;
564
+ this._enableRetry = _enableRetry;
565
+ this._source = _source;
411
566
  this.address = data.address;
412
567
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
413
568
  this.quote_currency = data.quote_currency;
@@ -438,16 +593,17 @@ class TransactionsResponse {
438
593
  error_message: "Invalid URL: URL link cannot be null"
439
594
  };
440
595
  }
596
+ const url = `${this.links.prev}?${this._urlParams}`;
441
597
  response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
442
598
  headers: {
443
599
  "Authorization": `Bearer ${this._apiKey}`,
444
- "X-Requested-With": userAgent
600
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
445
601
  }
446
602
  }));
447
- debugOutput(response.url, response.status ?? 429, startTime);
448
- if (response.status === null || response.status === 429) {
603
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
604
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
449
605
  try {
450
- data = await LIMIT(() => backoff.backOff(response.url));
606
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
451
607
  }
452
608
  catch (error) {
453
609
  success = true;
@@ -462,7 +618,7 @@ class TransactionsResponse {
462
618
  else {
463
619
  data = await response.json();
464
620
  }
465
- const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
621
+ const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
466
622
  checkAndModifyResponse(dataClass);
467
623
  success = true;
468
624
  return {
@@ -477,8 +633,8 @@ class TransactionsResponse {
477
633
  return {
478
634
  data: null,
479
635
  error: true,
480
- error_code: data ? data.error_code : response.status,
481
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
636
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
637
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
482
638
  };
483
639
  }
484
640
  }
@@ -504,16 +660,17 @@ class TransactionsResponse {
504
660
  error_message: "Invalid URL: URL link cannot be null"
505
661
  };
506
662
  }
663
+ const url = `${this.links.next}?${this._urlParams}`;
507
664
  response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
508
665
  headers: {
509
666
  "Authorization": `Bearer ${this._apiKey}`,
510
- "X-Requested-With": userAgent
667
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
511
668
  }
512
669
  }));
513
- debugOutput(response.url, response.status ?? 429, startTime);
514
- if (response.status === null || response.status === 429) {
670
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
671
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
515
672
  try {
516
- data = await LIMIT(() => backoff.backOff(response.url));
673
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
517
674
  }
518
675
  catch (error) {
519
676
  success = true;
@@ -528,7 +685,7 @@ class TransactionsResponse {
528
685
  else {
529
686
  data = await response.json();
530
687
  }
531
- const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
688
+ const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
532
689
  checkAndModifyResponse(dataClass);
533
690
  success = true;
534
691
  return {
@@ -543,19 +700,21 @@ class TransactionsResponse {
543
700
  return {
544
701
  data: null,
545
702
  error: true,
546
- error_code: data ? data.error_code : response.status,
547
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
703
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
704
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
548
705
  };
549
706
  }
550
707
  }
551
708
  }
552
709
  }
553
710
  class TransactionsTimeBucketResponse {
554
- constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
711
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
555
712
  this._debug = _debug;
556
713
  this._apiKey = _apiKey;
557
714
  this._threadCount = _threadCount;
558
715
  this._urlParams = _urlParams;
716
+ this._enableRetry = _enableRetry;
717
+ this._source = _source;
559
718
  this.address = data.address;
560
719
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
561
720
  this.quote_currency = data.quote_currency;
@@ -587,16 +746,17 @@ class TransactionsTimeBucketResponse {
587
746
  error_message: "Invalid URL: URL link cannot be null"
588
747
  };
589
748
  }
749
+ const url = `${this.links.prev}?${this._urlParams}`;
590
750
  response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
591
751
  headers: {
592
752
  "Authorization": `Bearer ${this._apiKey}`,
593
- "X-Requested-With": userAgent
753
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
594
754
  }
595
755
  }));
596
- debugOutput(response.url, response.status ?? 429, startTime);
597
- if (response.status === null || response.status === 429) {
756
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
757
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
598
758
  try {
599
- data = await LIMIT(() => backoff.backOff(response.url));
759
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
600
760
  }
601
761
  catch (error) {
602
762
  success = true;
@@ -611,7 +771,7 @@ class TransactionsTimeBucketResponse {
611
771
  else {
612
772
  data = await response.json();
613
773
  }
614
- const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
774
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
615
775
  checkAndModifyResponse(dataClass);
616
776
  success = true;
617
777
  return {
@@ -626,8 +786,8 @@ class TransactionsTimeBucketResponse {
626
786
  return {
627
787
  data: null,
628
788
  error: true,
629
- error_code: data ? data.error_code : response.status,
630
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
789
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
790
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
631
791
  };
632
792
  }
633
793
  }
@@ -653,16 +813,17 @@ class TransactionsTimeBucketResponse {
653
813
  error_message: "Invalid URL: URL link cannot be null"
654
814
  };
655
815
  }
816
+ const url = `${this.links.next}?${this._urlParams}`;
656
817
  response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
657
818
  headers: {
658
819
  "Authorization": `Bearer ${this._apiKey}`,
659
- "X-Requested-With": userAgent
820
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
660
821
  }
661
822
  }));
662
- debugOutput(response.url, response.status ?? 429, startTime);
663
- if (response.status === null || response.status === 429) {
823
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
824
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
664
825
  try {
665
- data = await LIMIT(() => backoff.backOff(response.url));
826
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
666
827
  }
667
828
  catch (error) {
668
829
  success = true;
@@ -677,7 +838,7 @@ class TransactionsTimeBucketResponse {
677
838
  else {
678
839
  data = await response.json();
679
840
  }
680
- const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
841
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
681
842
  checkAndModifyResponse(dataClass);
682
843
  success = true;
683
844
  return {
@@ -692,8 +853,8 @@ class TransactionsTimeBucketResponse {
692
853
  return {
693
854
  data: null,
694
855
  error: true,
695
- error_code: data ? data.error_code : response.status,
696
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
856
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
857
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
697
858
  };
698
859
  }
699
860
  }
@@ -703,7 +864,7 @@ class TransactionsTimeBucketResponse {
703
864
  * Transactions APIs
704
865
  *
705
866
  */
706
- async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
867
+ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry, source) {
707
868
  let hasNext = true;
708
869
  let response;
709
870
  let data;
@@ -718,17 +879,17 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
718
879
  response = await LIMIT(() => fetch(`${url}?${urlsParams}`, {
719
880
  headers: {
720
881
  "Authorization": `Bearer ${apiKey}`,
721
- "X-Requested-With": userAgent
882
+ "X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
722
883
  }
723
884
  }));
724
- debugOutput(response.url, response.status ?? 429, startTime);
725
- if (response.status === null || response.status === 429) {
885
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
886
+ if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
726
887
  try {
727
- data = await LIMIT(() => backoff.backOff(response.url));
888
+ data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}`, this.source));
728
889
  }
729
890
  catch (error) {
730
891
  hasNext = false;
731
- throw new Error(`An error occurred ${response.status}: ${error.message}`);
892
+ throw new Error(`An error occurred ${response ? response.status : 429}: ${error.message}`);
732
893
  }
733
894
  }
734
895
  else {
@@ -760,11 +921,13 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
760
921
  }
761
922
  }
762
923
  export class TransactionService {
763
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
924
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
764
925
  this.apiKey = apiKey;
765
926
  this.debug = debug;
766
927
  this.threadCount = threadCount;
767
928
  this.is_key_valid = is_key_valid;
929
+ this.enableRetry = enableRetry;
930
+ this.source = source;
768
931
  this.LIMIT = pLimit(this.threadCount);
769
932
  }
770
933
  /**
@@ -820,16 +983,17 @@ export class TransactionService {
820
983
  if (this.debug) {
821
984
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
822
985
  }
986
+ const url = `https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`;
823
987
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
824
988
  headers: {
825
989
  "Authorization": `Bearer ${this.apiKey}`,
826
- "X-Requested-With": userAgent
990
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
827
991
  }
828
992
  }));
829
- debugOutput(response.url, response.status ?? 429, startTime);
830
- if (response.status === null || response.status === 429) {
993
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
994
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
831
995
  try {
832
- data = await this.LIMIT(() => backoff.backOff(response.url));
996
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
833
997
  }
834
998
  catch (error) {
835
999
  success = true;
@@ -859,8 +1023,8 @@ export class TransactionService {
859
1023
  return {
860
1024
  data: null,
861
1025
  error: true,
862
- error_code: data ? data.error_code : response.status,
863
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1026
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1027
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
864
1028
  };
865
1029
  }
866
1030
  }
@@ -899,7 +1063,7 @@ export class TransactionService {
899
1063
  if (queryParamOpts?.withSafe !== undefined) {
900
1064
  urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
901
1065
  }
902
- for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount)) {
1066
+ for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount, this.enableRetry, this.source)) {
903
1067
  yield tx;
904
1068
  }
905
1069
  success = true;
@@ -955,16 +1119,17 @@ export class TransactionService {
955
1119
  if (this.debug) {
956
1120
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
957
1121
  }
1122
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`;
958
1123
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
959
1124
  headers: {
960
1125
  "Authorization": `Bearer ${this.apiKey}`,
961
- "X-Requested-With": userAgent
1126
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
962
1127
  }
963
1128
  }));
964
- debugOutput(response.url, response.status ?? 429, startTime);
965
- if (response.status === null || response.status === 429) {
1129
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1130
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
966
1131
  try {
967
- data = await this.LIMIT(() => backoff.backOff(response.url));
1132
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
968
1133
  }
969
1134
  catch (error) {
970
1135
  success = true;
@@ -979,7 +1144,7 @@ export class TransactionService {
979
1144
  else {
980
1145
  data = await response.json();
981
1146
  }
982
- const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
1147
+ const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
983
1148
  checkAndModifyResponse(dataClass);
984
1149
  success = true;
985
1150
  return {
@@ -994,8 +1159,8 @@ export class TransactionService {
994
1159
  return {
995
1160
  data: null,
996
1161
  error: true,
997
- error_code: data ? data.error_code : response.status,
998
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1162
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1163
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
999
1164
  };
1000
1165
  }
1001
1166
  }
@@ -1041,16 +1206,17 @@ export class TransactionService {
1041
1206
  if (this.debug) {
1042
1207
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1043
1208
  }
1209
+ const url = `https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`;
1044
1210
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
1045
1211
  headers: {
1046
1212
  "Authorization": `Bearer ${this.apiKey}`,
1047
- "X-Requested-With": userAgent
1213
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1048
1214
  }
1049
1215
  }));
1050
- debugOutput(response.url, response.status ?? 429, startTime);
1051
- if (response.status === null || response.status === 429) {
1216
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1217
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1052
1218
  try {
1053
- data = await this.LIMIT(() => backoff.backOff(response.url));
1219
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1054
1220
  }
1055
1221
  catch (error) {
1056
1222
  success = true;
@@ -1080,8 +1246,8 @@ export class TransactionService {
1080
1246
  return {
1081
1247
  data: null,
1082
1248
  error: true,
1083
- error_code: data ? data.error_code : response.status,
1084
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1249
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1250
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1085
1251
  };
1086
1252
  }
1087
1253
  }
@@ -1114,16 +1280,17 @@ export class TransactionService {
1114
1280
  if (this.debug) {
1115
1281
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1116
1282
  }
1283
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`;
1117
1284
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
1118
1285
  headers: {
1119
1286
  "Authorization": `Bearer ${this.apiKey}`,
1120
- "X-Requested-With": userAgent
1287
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1121
1288
  }
1122
1289
  }));
1123
- debugOutput(response.url, response.status ?? 429, startTime);
1124
- if (response.status === null || response.status === 429) {
1290
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1291
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1125
1292
  try {
1126
- data = await this.LIMIT(() => backoff.backOff(response.url));
1293
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1127
1294
  }
1128
1295
  catch (error) {
1129
1296
  success = true;
@@ -1153,8 +1320,8 @@ export class TransactionService {
1153
1320
  return {
1154
1321
  data: null,
1155
1322
  error: true,
1156
- error_code: data ? data.error_code : response.status,
1157
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1323
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1324
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1158
1325
  };
1159
1326
  }
1160
1327
  }
@@ -1203,16 +1370,17 @@ export class TransactionService {
1203
1370
  if (this.debug) {
1204
1371
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1205
1372
  }
1373
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`;
1206
1374
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
1207
1375
  headers: {
1208
1376
  "Authorization": `Bearer ${this.apiKey}`,
1209
- "X-Requested-With": userAgent
1377
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1210
1378
  }
1211
1379
  }));
1212
- debugOutput(response.url, response.status ?? 429, startTime);
1213
- if (response.status === null || response.status === 429) {
1380
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1381
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1214
1382
  try {
1215
- data = await this.LIMIT(() => backoff.backOff(response.url));
1383
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1216
1384
  }
1217
1385
  catch (error) {
1218
1386
  success = true;
@@ -1227,7 +1395,7 @@ export class TransactionService {
1227
1395
  else {
1228
1396
  data = await response.json();
1229
1397
  }
1230
- const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
1398
+ const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
1231
1399
  checkAndModifyResponse(dataClass);
1232
1400
  success = true;
1233
1401
  return {
@@ -1242,8 +1410,8 @@ export class TransactionService {
1242
1410
  return {
1243
1411
  data: null,
1244
1412
  error: true,
1245
- error_code: data ? data.error_code : response.status,
1246
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1413
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1414
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1247
1415
  };
1248
1416
  }
1249
1417
  }
@@ -1288,16 +1456,105 @@ export class TransactionService {
1288
1456
  if (this.debug) {
1289
1457
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1290
1458
  }
1459
+ const url = `https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`;
1291
1460
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
1292
1461
  headers: {
1293
1462
  "Authorization": `Bearer ${this.apiKey}`,
1294
- "X-Requested-With": userAgent
1463
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1464
+ }
1465
+ }));
1466
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1467
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1468
+ try {
1469
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1470
+ }
1471
+ catch (error) {
1472
+ success = true;
1473
+ return {
1474
+ data: null,
1475
+ error: true,
1476
+ error_code: response.status ?? 429,
1477
+ error_message: error.message
1478
+ };
1479
+ }
1480
+ }
1481
+ else {
1482
+ data = await response.json();
1483
+ }
1484
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
1485
+ checkAndModifyResponse(dataClass);
1486
+ success = true;
1487
+ return {
1488
+ data: dataClass,
1489
+ error: data.error,
1490
+ error_code: data ? data.error_code : response.status,
1491
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1492
+ };
1493
+ }
1494
+ catch (error) {
1495
+ success = true;
1496
+ return {
1497
+ data: null,
1498
+ error: true,
1499
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1500
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1501
+ };
1502
+ }
1503
+ }
1504
+ }
1505
+ /**
1506
+ *
1507
+ * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
1508
+ *
1509
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
1510
+ * @param {string} blockHash - The requested block hash.
1511
+ * @param {number} page - The requested 0-indexed page number.
1512
+ * @param {GetTransactionsForBlockHashByPageQueryParamOpts} queryParamOpts
1513
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1514
+ * - `noLogs`: Omit log events.
1515
+ * - `withSafe`: Include safe details.
1516
+ *
1517
+ */
1518
+ async getTransactionsForBlockHashByPage(chainName, blockHash, page, queryParamOpts) {
1519
+ let success = false;
1520
+ let data;
1521
+ let response;
1522
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1523
+ while (!success) {
1524
+ try {
1525
+ const urlParams = new URLSearchParams();
1526
+ if (!this.is_key_valid) {
1527
+ return {
1528
+ data: null,
1529
+ error: true,
1530
+ error_code: 401,
1531
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1532
+ };
1533
+ }
1534
+ if (queryParamOpts?.quoteCurrency !== undefined) {
1535
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1536
+ }
1537
+ if (queryParamOpts?.noLogs !== undefined) {
1538
+ urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
1539
+ }
1540
+ if (queryParamOpts?.withSafe !== undefined) {
1541
+ urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
1542
+ }
1543
+ const url = `https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}/?${urlParams}`;
1544
+ let startTime;
1545
+ if (this.debug) {
1546
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1547
+ }
1548
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}/?${urlParams}`, {
1549
+ headers: {
1550
+ "Authorization": `Bearer ${this.apiKey}`,
1551
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1295
1552
  }
1296
1553
  }));
1297
- debugOutput(response.url, response.status ?? 429, startTime);
1298
- if (response.status === null || response.status === 429) {
1554
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1555
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1299
1556
  try {
1300
- data = await this.LIMIT(() => backoff.backOff(response.url));
1557
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1301
1558
  }
1302
1559
  catch (error) {
1303
1560
  success = true;
@@ -1312,7 +1569,7 @@ export class TransactionService {
1312
1569
  else {
1313
1570
  data = await response.json();
1314
1571
  }
1315
- const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
1572
+ const dataClass = new TransactionsBlockPageResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
1316
1573
  checkAndModifyResponse(dataClass);
1317
1574
  success = true;
1318
1575
  return {
@@ -1327,10 +1584,97 @@ export class TransactionService {
1327
1584
  return {
1328
1585
  data: null,
1329
1586
  error: true,
1587
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1588
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1589
+ };
1590
+ }
1591
+ }
1592
+ }
1593
+ /**
1594
+ *
1595
+ * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
1596
+ *
1597
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
1598
+ * @param {string} blockHash - The requested block hash.
1599
+ * @param {GetTransactionsForBlockHashQueryParamOpts} queryParamOpts
1600
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1601
+ * - `noLogs`: Omit log events.
1602
+ * - `withSafe`: Include safe details.
1603
+ *
1604
+ */
1605
+ async getTransactionsForBlockHash(chainName, blockHash, queryParamOpts) {
1606
+ let success = false;
1607
+ let data;
1608
+ let response;
1609
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1610
+ while (!success) {
1611
+ try {
1612
+ const urlParams = new URLSearchParams();
1613
+ if (!this.is_key_valid) {
1614
+ return {
1615
+ data: null,
1616
+ error: true,
1617
+ error_code: 401,
1618
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1619
+ };
1620
+ }
1621
+ if (queryParamOpts?.quoteCurrency !== undefined) {
1622
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1623
+ }
1624
+ if (queryParamOpts?.noLogs !== undefined) {
1625
+ urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
1626
+ }
1627
+ if (queryParamOpts?.withSafe !== undefined) {
1628
+ urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
1629
+ }
1630
+ const url = `https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/?${urlParams}`;
1631
+ let startTime;
1632
+ if (this.debug) {
1633
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1634
+ }
1635
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/?${urlParams}`, {
1636
+ headers: {
1637
+ "Authorization": `Bearer ${this.apiKey}`,
1638
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1639
+ }
1640
+ }));
1641
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1642
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1643
+ try {
1644
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1645
+ }
1646
+ catch (error) {
1647
+ success = true;
1648
+ return {
1649
+ data: null,
1650
+ error: true,
1651
+ error_code: response.status ?? 429,
1652
+ error_message: error.message
1653
+ };
1654
+ }
1655
+ }
1656
+ else {
1657
+ data = await response.json();
1658
+ }
1659
+ const dataClass = new TransactionsBlockResponse(data.data);
1660
+ checkAndModifyResponse(dataClass);
1661
+ success = true;
1662
+ return {
1663
+ data: dataClass,
1664
+ error: data.error,
1330
1665
  error_code: data ? data.error_code : response.status,
1331
1666
  error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1332
1667
  };
1333
1668
  }
1669
+ catch (error) {
1670
+ success = true;
1671
+ return {
1672
+ data: null,
1673
+ error: true,
1674
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1675
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1676
+ };
1677
+ }
1334
1678
  }
1335
1679
  }
1336
1680
  }