@covalenthq/client-sdk 0.5.3 → 0.6.1

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 (46) hide show
  1. package/README.md +12 -6
  2. package/dist/cjs/index.js +597 -26
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/services/BalanceService.d.ts +51 -1
  5. package/dist/cjs/services/BaseService.d.ts +92 -0
  6. package/dist/cjs/services/CovalentClient.d.ts +1 -1
  7. package/dist/cjs/services/NftService.d.ts +47 -0
  8. package/dist/cjs/services/TransactionService.d.ts +3 -0
  9. package/dist/cjs/util/types/BalanceServiceTypes.d.ts +18 -0
  10. package/dist/cjs/util/types/NftServiceTypes.d.ts +6 -0
  11. package/dist/es/index.js +597 -26
  12. package/dist/es/index.js.map +1 -1
  13. package/dist/es/services/BalanceService.d.ts +51 -1
  14. package/dist/es/services/BaseService.d.ts +92 -0
  15. package/dist/es/services/CovalentClient.d.ts +1 -1
  16. package/dist/es/services/NftService.d.ts +47 -0
  17. package/dist/es/services/TransactionService.d.ts +3 -0
  18. package/dist/es/util/types/BalanceServiceTypes.d.ts +18 -0
  19. package/dist/es/util/types/NftServiceTypes.d.ts +6 -0
  20. package/dist/esm/index.js +597 -26
  21. package/dist/esm/index.js.map +1 -1
  22. package/dist/esm/services/BalanceService.d.ts +51 -1
  23. package/dist/esm/services/BaseService.d.ts +92 -0
  24. package/dist/esm/services/CovalentClient.d.ts +1 -1
  25. package/dist/esm/services/NftService.d.ts +47 -0
  26. package/dist/esm/services/TransactionService.d.ts +3 -0
  27. package/dist/esm/util/types/BalanceServiceTypes.d.ts +18 -0
  28. package/dist/esm/util/types/NftServiceTypes.d.ts +6 -0
  29. package/dist/services/BalanceService.d.ts +51 -1
  30. package/dist/services/BalanceService.js +101 -0
  31. package/dist/services/BalanceService.js.map +1 -1
  32. package/dist/services/BaseService.d.ts +92 -0
  33. package/dist/services/BaseService.js +243 -0
  34. package/dist/services/BaseService.js.map +1 -1
  35. package/dist/services/CovalentClient.d.ts +1 -1
  36. package/dist/services/CovalentClient.js +1 -1
  37. package/dist/services/NftService.d.ts +47 -0
  38. package/dist/services/NftService.js +170 -0
  39. package/dist/services/NftService.js.map +1 -1
  40. package/dist/services/TransactionService.d.ts +3 -0
  41. package/dist/services/TransactionService.js +4 -0
  42. package/dist/services/TransactionService.js.map +1 -1
  43. package/dist/services/XykService.js.map +1 -1
  44. package/dist/util/types/BalanceServiceTypes.d.ts +18 -0
  45. package/dist/util/types/NftServiceTypes.d.ts +6 -0
  46. package/package.json +1 -1
package/dist/cjs/index.js CHANGED
@@ -524,6 +524,7 @@ class BalanceItem {
524
524
  this.contract_name = data.contract_name;
525
525
  this.contract_ticker_symbol = data.contract_ticker_symbol;
526
526
  this.contract_address = data.contract_address;
527
+ this.contract_display_name = data.contract_display_name;
527
528
  this.supports_erc = data.supports_erc;
528
529
  this.logo_url = data.logo_url;
529
530
  this.last_transferred_at = data.last_transferred_at && data.last_transferred_at !== null ? dateFns.parseISO(data.last_transferred_at.toString()) : null;
@@ -538,9 +539,23 @@ class BalanceItem {
538
539
  this.quote_24h = data.quote_24h;
539
540
  this.pretty_quote = data.pretty_quote;
540
541
  this.pretty_quote_24h = data.pretty_quote_24h;
542
+ this.logo_urls = data.logo_urls && data.logo_urls !== null ? new LogoUrls(data.logo_urls) : null;
543
+ this.protocol_metadata = data.protocol_metadata && data.protocol_metadata !== null ? new ProtocolMetadata(data.protocol_metadata) : null;
541
544
  this.nft_data = data.nft_data && data.nft_data !== null ? data.nft_data.map((itemData) => new NftData$1(itemData)) : null;
542
545
  }
543
546
  }
547
+ class LogoUrls {
548
+ constructor(data) {
549
+ this.token_logo_url = data.token_logo_url;
550
+ this.protocol_logo_url = data.protocol_logo_url;
551
+ this.chain_logo_url = data.chain_logo_url;
552
+ }
553
+ }
554
+ class ProtocolMetadata {
555
+ constructor(data) {
556
+ this.protocol_name = data.protocol_name;
557
+ }
558
+ }
544
559
  let NftData$1 = class NftData {
545
560
  constructor(data) {
546
561
  this.token_id = data.token_id && data.token_id !== null ? BigInt(data.token_id) : null;
@@ -619,7 +634,7 @@ class Erc20TransfersResponse {
619
634
  this.chain_id = data.chain_id;
620
635
  this.chain_name = data.chain_name;
621
636
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new BlockTransactionWithContractTransfers(itemData)) : null;
622
- this.pagination = data.pagination && data.pagination !== null ? new Pagination$2(data.pagination) : null;
637
+ this.pagination = data.pagination && data.pagination !== null ? new Pagination$3(data.pagination) : null;
623
638
  }
624
639
  }
625
640
  class BlockTransactionWithContractTransfers {
@@ -646,7 +661,7 @@ class BlockTransactionWithContractTransfers {
646
661
  this.transfers = data.transfers && data.transfers !== null ? data.transfers.map((itemData) => new TokenTransferItem(itemData)) : null;
647
662
  }
648
663
  }
649
- let Pagination$2 = class Pagination {
664
+ let Pagination$3 = class Pagination {
650
665
  constructor(data) {
651
666
  this.has_more = data.has_more;
652
667
  this.page_number = data.page_number;
@@ -683,6 +698,15 @@ class MethodCallsForTransfers {
683
698
  this.method = data.method;
684
699
  }
685
700
  }
701
+ class TokenHoldersResponse {
702
+ constructor(data) {
703
+ this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
704
+ this.chain_id = data.chain_id;
705
+ this.chain_name = data.chain_name;
706
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenHolder(itemData)) : null;
707
+ this.pagination = data.pagination && data.pagination !== null ? new Pagination$3(data.pagination) : null;
708
+ }
709
+ }
686
710
  class TokenHolder {
687
711
  constructor(data) {
688
712
  this.contract_decimals = data.contract_decimals;
@@ -1074,6 +1098,7 @@ class BalanceService {
1074
1098
  * - `blockHeight`: Ending block to define a block range. Omitting this parameter defaults to the latest block height.
1075
1099
  * - `pageSize`: Number of items per page. Note: Currently, only values of `100` and `1000` are supported. Omitting this parameter defaults to 100.
1076
1100
  * - `pageNumber`: 0-indexed page number to begin pagination.
1101
+ * - `date`: Ending date to define a block range (YYYY-MM-DD). Omitting this parameter defaults to the current date.
1077
1102
  *
1078
1103
  */
1079
1104
  async *getTokenHoldersV2ForTokenAddress(chainName, tokenAddress, queryParamOpts) {
@@ -1091,6 +1116,9 @@ class BalanceService {
1091
1116
  if (queryParamOpts?.pageNumber !== undefined) {
1092
1117
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1093
1118
  }
1119
+ if (queryParamOpts?.date !== undefined) {
1120
+ urlParams.append("date", queryParamOpts?.date.toString());
1121
+ }
1094
1122
  for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/`, this.apiKey, urlParams, TokenHolder, this.debug, this.threadCount)) {
1095
1123
  yield res;
1096
1124
  }
@@ -1102,6 +1130,88 @@ class BalanceService {
1102
1130
  }
1103
1131
  }
1104
1132
  }
1133
+ /**
1134
+ *
1135
+ * 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.
1136
+ *
1137
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
1138
+ * @param {string} tokenAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1139
+ * @param {GetTokenHoldersV2ForTokenAddressQueryParamOpts} queryParamOpts
1140
+ * - `blockHeight`: Ending block to define a block range. Omitting this parameter defaults to the latest block height.
1141
+ * - `pageSize`: Number of items per page. Note: Currently, only values of `100` and `1000` are supported. Omitting this parameter defaults to 100.
1142
+ * - `pageNumber`: 0-indexed page number to begin pagination.
1143
+ * - `date`: Ending date to define a block range (YYYY-MM-DD). Omitting this parameter defaults to the current date.
1144
+ *
1145
+ */
1146
+ async getTokenHoldersV2ForTokenAddressByPage(chainName, tokenAddress, queryParamOpts) {
1147
+ let success = false;
1148
+ let data;
1149
+ let response;
1150
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1151
+ while (!success) {
1152
+ try {
1153
+ const urlParams = new URLSearchParams();
1154
+ if (queryParamOpts?.blockHeight !== undefined) {
1155
+ urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
1156
+ }
1157
+ if (queryParamOpts?.pageSize !== undefined) {
1158
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1159
+ }
1160
+ if (queryParamOpts?.pageNumber !== undefined) {
1161
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1162
+ }
1163
+ if (queryParamOpts?.date !== undefined) {
1164
+ urlParams.append("date", queryParamOpts?.date.toString());
1165
+ }
1166
+ let startTime;
1167
+ if (this.debug) {
1168
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1169
+ }
1170
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/?${urlParams}`, {
1171
+ headers: {
1172
+ "Authorization": `Bearer ${this.apiKey}`,
1173
+ "X-Requested-With": userAgent
1174
+ }
1175
+ }));
1176
+ debugOutput(response.url, response.status, startTime);
1177
+ if (response.status === 429) {
1178
+ try {
1179
+ data = await this.LIMIT(() => backoff.backOff(response.url));
1180
+ }
1181
+ catch (error) {
1182
+ success = true;
1183
+ return {
1184
+ data: null,
1185
+ error: true,
1186
+ error_code: response.status,
1187
+ error_message: error.message
1188
+ };
1189
+ }
1190
+ }
1191
+ else {
1192
+ data = await response.json();
1193
+ }
1194
+ const dataClass = new TokenHoldersResponse(data.data);
1195
+ checkAndModifyResponse(dataClass);
1196
+ success = true;
1197
+ return {
1198
+ data: dataClass,
1199
+ error: data.error,
1200
+ error_code: data ? data.error_code : response.status,
1201
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1202
+ };
1203
+ }
1204
+ catch (error) {
1205
+ success = true;
1206
+ return {
1207
+ data: null,
1208
+ error: true,
1209
+ error_code: data ? data.error_code : response.status,
1210
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1211
+ };
1212
+ }
1213
+ }
1214
+ }
1105
1215
  /**
1106
1216
  *
1107
1217
  * Commonly used to fetch the historical native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address at a given block height or date. Response includes daily prices and other metadata.
@@ -1298,6 +1408,23 @@ class ResolvedAddressItem {
1298
1408
  this.name = data.name;
1299
1409
  }
1300
1410
  }
1411
+ class BlockHeightsResponse {
1412
+ constructor(data) {
1413
+ this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
1414
+ this.chain_id = data.chain_id;
1415
+ this.chain_name = data.chain_name;
1416
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new Block(itemData)) : null;
1417
+ this.pagination = data.pagination && data.pagination !== null ? new Pagination$2(data.pagination) : null;
1418
+ }
1419
+ }
1420
+ let Pagination$2 = class Pagination {
1421
+ constructor(data) {
1422
+ this.has_more = data.has_more;
1423
+ this.page_number = data.page_number;
1424
+ this.page_size = data.page_size;
1425
+ this.total_count = data.total_count;
1426
+ }
1427
+ };
1301
1428
  class GetLogsResponse {
1302
1429
  constructor(data) {
1303
1430
  this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
@@ -1341,6 +1468,15 @@ let Param$2 = class Param {
1341
1468
  this.value = data.value;
1342
1469
  }
1343
1470
  };
1471
+ class LogEventsByAddressResponse {
1472
+ constructor(data) {
1473
+ this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
1474
+ this.chain_id = data.chain_id;
1475
+ this.chain_name = data.chain_name;
1476
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new LogEvent$2(itemData)) : null;
1477
+ this.pagination = data.pagination && data.pagination !== null ? new Pagination$2(data.pagination) : null;
1478
+ }
1479
+ }
1344
1480
  let LogEvent$2 = class LogEvent {
1345
1481
  constructor(data) {
1346
1482
  this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? dateFns.parseISO(data.block_signed_at.toString()) : null;
@@ -1359,6 +1495,15 @@ let LogEvent$2 = class LogEvent {
1359
1495
  this.decoded = data.decoded && data.decoded !== null ? new DecodedItem$2(data.decoded) : null;
1360
1496
  }
1361
1497
  };
1498
+ class LogEventsByTopicHashResponse {
1499
+ constructor(data) {
1500
+ this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
1501
+ this.chain_id = data.chain_id;
1502
+ this.chain_name = data.chain_name;
1503
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new LogEvent$2(itemData)) : null;
1504
+ this.pagination = data.pagination && data.pagination !== null ? new Pagination$2(data.pagination) : null;
1505
+ }
1506
+ }
1362
1507
  class AllChainsResponse {
1363
1508
  constructor(data) {
1364
1509
  this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
@@ -1600,6 +1745,81 @@ class BaseService {
1600
1745
  }
1601
1746
  }
1602
1747
  }
1748
+ /**
1749
+ *
1750
+ * Commonly used to get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day.
1751
+ *
1752
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
1753
+ * @param {string} startDate - The start date in YYYY-MM-DD format.
1754
+ * @param {string} endDate - The end date in YYYY-MM-DD format.
1755
+ * @param {GetBlockHeightsQueryParamOpts} queryParamOpts
1756
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1757
+ * - `pageNumber`: 0-indexed page number to begin pagination.
1758
+ *
1759
+ */
1760
+ async getBlockHeightsByPage(chainName, startDate, endDate, queryParamOpts) {
1761
+ let success = false;
1762
+ let data;
1763
+ let response;
1764
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1765
+ while (!success) {
1766
+ try {
1767
+ const urlParams = new URLSearchParams();
1768
+ if (queryParamOpts?.pageSize !== undefined) {
1769
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1770
+ }
1771
+ if (queryParamOpts?.pageNumber !== undefined) {
1772
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1773
+ }
1774
+ let startTime;
1775
+ if (this.debug) {
1776
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1777
+ }
1778
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/?${urlParams}`, {
1779
+ headers: {
1780
+ "Authorization": `Bearer ${this.apiKey}`,
1781
+ "X-Requested-With": userAgent
1782
+ }
1783
+ }));
1784
+ debugOutput(response.url, response.status, startTime);
1785
+ if (response.status === 429) {
1786
+ try {
1787
+ data = await this.LIMIT(() => backoff.backOff(response.url));
1788
+ }
1789
+ catch (error) {
1790
+ success = true;
1791
+ return {
1792
+ data: null,
1793
+ error: true,
1794
+ error_code: response.status,
1795
+ error_message: error.message
1796
+ };
1797
+ }
1798
+ }
1799
+ else {
1800
+ data = await response.json();
1801
+ }
1802
+ const dataClass = new BlockHeightsResponse(data.data);
1803
+ checkAndModifyResponse(dataClass);
1804
+ success = true;
1805
+ return {
1806
+ data: dataClass,
1807
+ error: data.error,
1808
+ error_code: data ? data.error_code : response.status,
1809
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1810
+ };
1811
+ }
1812
+ catch (error) {
1813
+ success = true;
1814
+ return {
1815
+ data: null,
1816
+ error: true,
1817
+ error_code: data ? data.error_code : response.status,
1818
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1819
+ };
1820
+ }
1821
+ }
1822
+ }
1603
1823
  /**
1604
1824
  *
1605
1825
  * Commonly used to get all the event logs of the latest block, or for a range of blocks. Includes sender contract metadata as well as decoded logs.
@@ -1614,7 +1834,137 @@ class BaseService {
1614
1834
  * - `skipDecode`: Omit decoded log events.
1615
1835
  *
1616
1836
  */
1617
- async getLogs(chainName, queryParamOpts) {
1837
+ async getLogs(chainName, queryParamOpts) {
1838
+ let success = false;
1839
+ let data;
1840
+ let response;
1841
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1842
+ while (!success) {
1843
+ try {
1844
+ const urlParams = new URLSearchParams();
1845
+ if (queryParamOpts?.startingBlock !== undefined) {
1846
+ urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
1847
+ }
1848
+ if (queryParamOpts?.endingBlock !== undefined) {
1849
+ urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
1850
+ }
1851
+ if (queryParamOpts?.address !== undefined) {
1852
+ urlParams.append("address", queryParamOpts?.address.toString());
1853
+ }
1854
+ if (queryParamOpts?.topics !== undefined) {
1855
+ urlParams.append("topics", queryParamOpts?.topics.toString());
1856
+ }
1857
+ if (queryParamOpts?.blockHash !== undefined) {
1858
+ urlParams.append("block-hash", queryParamOpts?.blockHash.toString());
1859
+ }
1860
+ if (queryParamOpts?.skipDecode !== undefined) {
1861
+ urlParams.append("skip-decode", queryParamOpts?.skipDecode.toString());
1862
+ }
1863
+ let startTime;
1864
+ if (this.debug) {
1865
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1866
+ }
1867
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`, {
1868
+ headers: {
1869
+ "Authorization": `Bearer ${this.apiKey}`,
1870
+ "X-Requested-With": userAgent
1871
+ }
1872
+ }));
1873
+ debugOutput(response.url, response.status, startTime);
1874
+ if (response.status === 429) {
1875
+ try {
1876
+ data = await this.LIMIT(() => backoff.backOff(response.url));
1877
+ }
1878
+ catch (error) {
1879
+ success = true;
1880
+ return {
1881
+ data: null,
1882
+ error: true,
1883
+ error_code: response.status,
1884
+ error_message: error.message
1885
+ };
1886
+ }
1887
+ }
1888
+ else {
1889
+ data = await response.json();
1890
+ }
1891
+ const dataClass = new GetLogsResponse(data.data);
1892
+ checkAndModifyResponse(dataClass);
1893
+ success = true;
1894
+ return {
1895
+ data: dataClass,
1896
+ error: data.error,
1897
+ error_code: data ? data.error_code : response.status,
1898
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1899
+ };
1900
+ }
1901
+ catch (error) {
1902
+ success = true;
1903
+ return {
1904
+ data: null,
1905
+ error: true,
1906
+ error_code: data ? data.error_code : response.status,
1907
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1908
+ };
1909
+ }
1910
+ }
1911
+ }
1912
+ /**
1913
+ *
1914
+ * Commonly used to get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions.
1915
+ *
1916
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
1917
+ * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1918
+ * @param {GetLogEventsByAddressQueryParamOpts} queryParamOpts
1919
+ * - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
1920
+ * - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
1921
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1922
+ * - `pageNumber`: 0-indexed page number to begin pagination.
1923
+ *
1924
+ */
1925
+ async *getLogEventsByAddress(chainName, contractAddress, queryParamOpts) {
1926
+ let success = false;
1927
+ let res;
1928
+ while (!success) {
1929
+ try {
1930
+ const urlParams = new URLSearchParams();
1931
+ if (queryParamOpts?.startingBlock !== undefined) {
1932
+ urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
1933
+ }
1934
+ if (queryParamOpts?.endingBlock !== undefined) {
1935
+ urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
1936
+ }
1937
+ if (queryParamOpts?.pageSize !== undefined) {
1938
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1939
+ }
1940
+ if (queryParamOpts?.pageNumber !== undefined) {
1941
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1942
+ }
1943
+ for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
1944
+ yield res;
1945
+ }
1946
+ success = true;
1947
+ }
1948
+ catch (error) {
1949
+ success = true;
1950
+ throw new Error(error.message);
1951
+ }
1952
+ }
1953
+ }
1954
+ /**
1955
+ *
1956
+ * Commonly used to get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions.
1957
+ *
1958
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
1959
+ * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1960
+ * @param {GetLogEventsByAddressQueryParamOpts} queryParamOpts
1961
+ * - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
1962
+ * - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
1963
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1964
+ * - `pageNumber`: 0-indexed page number to begin pagination.
1965
+ *
1966
+ */
1967
+ async getLogEventsByAddressByPage(chainName, contractAddress, queryParamOpts) {
1618
1968
  let success = false;
1619
1969
  let data;
1620
1970
  let response;
@@ -1628,23 +1978,17 @@ class BaseService {
1628
1978
  if (queryParamOpts?.endingBlock !== undefined) {
1629
1979
  urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
1630
1980
  }
1631
- if (queryParamOpts?.address !== undefined) {
1632
- urlParams.append("address", queryParamOpts?.address.toString());
1633
- }
1634
- if (queryParamOpts?.topics !== undefined) {
1635
- urlParams.append("topics", queryParamOpts?.topics.toString());
1636
- }
1637
- if (queryParamOpts?.blockHash !== undefined) {
1638
- urlParams.append("block-hash", queryParamOpts?.blockHash.toString());
1981
+ if (queryParamOpts?.pageSize !== undefined) {
1982
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1639
1983
  }
1640
- if (queryParamOpts?.skipDecode !== undefined) {
1641
- urlParams.append("skip-decode", queryParamOpts?.skipDecode.toString());
1984
+ if (queryParamOpts?.pageNumber !== undefined) {
1985
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1642
1986
  }
1643
1987
  let startTime;
1644
1988
  if (this.debug) {
1645
1989
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1646
1990
  }
1647
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`, {
1991
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/?${urlParams}`, {
1648
1992
  headers: {
1649
1993
  "Authorization": `Bearer ${this.apiKey}`,
1650
1994
  "X-Requested-With": userAgent
@@ -1668,7 +2012,7 @@ class BaseService {
1668
2012
  else {
1669
2013
  data = await response.json();
1670
2014
  }
1671
- const dataClass = new GetLogsResponse(data.data);
2015
+ const dataClass = new LogEventsByAddressResponse(data.data);
1672
2016
  checkAndModifyResponse(dataClass);
1673
2017
  success = true;
1674
2018
  return {
@@ -1691,18 +2035,19 @@ class BaseService {
1691
2035
  }
1692
2036
  /**
1693
2037
  *
1694
- * Commonly used to get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions.
2038
+ * Commonly used to get all event logs of the same topic hash across all contracts within a particular chain. Useful for cross-sectional analysis of event logs that are emitted on-chain.
1695
2039
  *
1696
2040
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
1697
- * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1698
- * @param {GetLogEventsByAddressQueryParamOpts} queryParamOpts
2041
+ * @param {string} topicHash - The endpoint will return event logs that contain this topic hash.
2042
+ * @param {GetLogEventsByTopicHashQueryParamOpts} queryParamOpts
1699
2043
  * - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
1700
2044
  * - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
2045
+ * - `secondaryTopics`: Additional topic hash(es) to filter on - padded & unpadded address fields are supported. Separate multiple topics with a comma.
1701
2046
  * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1702
2047
  * - `pageNumber`: 0-indexed page number to begin pagination.
1703
2048
  *
1704
2049
  */
1705
- async *getLogEventsByAddress(chainName, contractAddress, queryParamOpts) {
2050
+ async *getLogEventsByTopicHash(chainName, topicHash, queryParamOpts) {
1706
2051
  let success = false;
1707
2052
  let res;
1708
2053
  while (!success) {
@@ -1714,13 +2059,16 @@ class BaseService {
1714
2059
  if (queryParamOpts?.endingBlock !== undefined) {
1715
2060
  urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
1716
2061
  }
2062
+ if (queryParamOpts?.secondaryTopics !== undefined) {
2063
+ urlParams.append("secondary-topics", queryParamOpts?.secondaryTopics.toString());
2064
+ }
1717
2065
  if (queryParamOpts?.pageSize !== undefined) {
1718
2066
  urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1719
2067
  }
1720
2068
  if (queryParamOpts?.pageNumber !== undefined) {
1721
2069
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1722
2070
  }
1723
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
2071
+ for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
1724
2072
  yield res;
1725
2073
  }
1726
2074
  success = true;
@@ -1745,9 +2093,11 @@ class BaseService {
1745
2093
  * - `pageNumber`: 0-indexed page number to begin pagination.
1746
2094
  *
1747
2095
  */
1748
- async *getLogEventsByTopicHash(chainName, topicHash, queryParamOpts) {
2096
+ async getLogEventsByTopicHashByPage(chainName, topicHash, queryParamOpts) {
1749
2097
  let success = false;
1750
- let res;
2098
+ let data;
2099
+ let response;
2100
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1751
2101
  while (!success) {
1752
2102
  try {
1753
2103
  const urlParams = new URLSearchParams();
@@ -1766,14 +2116,52 @@ class BaseService {
1766
2116
  if (queryParamOpts?.pageNumber !== undefined) {
1767
2117
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1768
2118
  }
1769
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
1770
- yield res;
2119
+ let startTime;
2120
+ if (this.debug) {
2121
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
2122
+ }
2123
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/?${urlParams}`, {
2124
+ headers: {
2125
+ "Authorization": `Bearer ${this.apiKey}`,
2126
+ "X-Requested-With": userAgent
2127
+ }
2128
+ }));
2129
+ debugOutput(response.url, response.status, startTime);
2130
+ if (response.status === 429) {
2131
+ try {
2132
+ data = await this.LIMIT(() => backoff.backOff(response.url));
2133
+ }
2134
+ catch (error) {
2135
+ success = true;
2136
+ return {
2137
+ data: null,
2138
+ error: true,
2139
+ error_code: response.status,
2140
+ error_message: error.message
2141
+ };
2142
+ }
2143
+ }
2144
+ else {
2145
+ data = await response.json();
1771
2146
  }
2147
+ const dataClass = new LogEventsByTopicHashResponse(data.data);
2148
+ checkAndModifyResponse(dataClass);
1772
2149
  success = true;
2150
+ return {
2151
+ data: dataClass,
2152
+ error: data.error,
2153
+ error_code: data ? data.error_code : response.status,
2154
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2155
+ };
1773
2156
  }
1774
2157
  catch (error) {
1775
2158
  success = true;
1776
- throw new Error(error.message);
2159
+ return {
2160
+ data: null,
2161
+ error: true,
2162
+ error_code: data ? data.error_code : response.status,
2163
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2164
+ };
1777
2165
  }
1778
2166
  }
1779
2167
  }
@@ -1974,6 +2362,15 @@ class BaseService {
1974
2362
  }
1975
2363
  }
1976
2364
 
2365
+ class ChainCollectionResponse {
2366
+ constructor(data) {
2367
+ this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
2368
+ this.chain_id = data.chain_id;
2369
+ this.chain_name = data.chain_name;
2370
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new ChainCollectionItem(itemData)) : null;
2371
+ this.pagination = data.pagination && data.pagination !== null ? new Pagination$1(data.pagination) : null;
2372
+ }
2373
+ }
1977
2374
  class ChainCollectionItem {
1978
2375
  constructor(data) {
1979
2376
  this.contract_address = data.contract_address;
@@ -2011,6 +2408,9 @@ class NftTokenContractBalanceItem {
2011
2408
  this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
2012
2409
  this.balance_24h = data.balance_24h;
2013
2410
  this.type = data.type;
2411
+ this.floor_price_quote = data.floor_price_quote;
2412
+ this.pretty_floor_price_quote = data.pretty_floor_price_quote;
2413
+ this.floor_price_native_quote = data.floor_price_native_quote;
2014
2414
  this.nft_data = data.nft_data && data.nft_data !== null ? data.nft_data.map((itemData) => new NftData(itemData)) : null;
2015
2415
  }
2016
2416
  }
@@ -2327,6 +2727,83 @@ class NftService {
2327
2727
  }
2328
2728
  }
2329
2729
  }
2730
+ /**
2731
+ *
2732
+ * Commonly used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files.
2733
+ *
2734
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
2735
+ * @param {GetChainCollectionsQueryParamOpts} queryParamOpts
2736
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
2737
+ * - `pageNumber`: 0-indexed page number to begin pagination.
2738
+ * - `noSpam`: If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
2739
+ *
2740
+ */
2741
+ async getChainCollectionsByPage(chainName, queryParamOpts) {
2742
+ let success = false;
2743
+ let data;
2744
+ let response;
2745
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
2746
+ while (!success) {
2747
+ try {
2748
+ const urlParams = new URLSearchParams();
2749
+ if (queryParamOpts?.pageSize !== undefined) {
2750
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
2751
+ }
2752
+ if (queryParamOpts?.pageNumber !== undefined) {
2753
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
2754
+ }
2755
+ if (queryParamOpts?.noSpam !== undefined) {
2756
+ urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
2757
+ }
2758
+ let startTime;
2759
+ if (this.debug) {
2760
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
2761
+ }
2762
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`, {
2763
+ headers: {
2764
+ "Authorization": `Bearer ${this.apiKey}`,
2765
+ "X-Requested-With": userAgent
2766
+ }
2767
+ }));
2768
+ debugOutput(response.url, response.status, startTime);
2769
+ if (response.status === 429) {
2770
+ try {
2771
+ data = await this.LIMIT(() => backoff.backOff(response.url));
2772
+ }
2773
+ catch (error) {
2774
+ success = true;
2775
+ return {
2776
+ data: null,
2777
+ error: true,
2778
+ error_code: response.status,
2779
+ error_message: error.message
2780
+ };
2781
+ }
2782
+ }
2783
+ else {
2784
+ data = await response.json();
2785
+ }
2786
+ const dataClass = new ChainCollectionResponse(data.data);
2787
+ checkAndModifyResponse(dataClass);
2788
+ success = true;
2789
+ return {
2790
+ data: dataClass,
2791
+ error: data.error,
2792
+ error_code: data ? data.error_code : response.status,
2793
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2794
+ };
2795
+ }
2796
+ catch (error) {
2797
+ success = true;
2798
+ return {
2799
+ data: null,
2800
+ error: true,
2801
+ error_code: data ? data.error_code : response.status,
2802
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2803
+ };
2804
+ }
2805
+ }
2806
+ }
2330
2807
  /**
2331
2808
  *
2332
2809
  * Commonly used to render the NFTs (including ERC721 and ERC1155) held by an address.
@@ -2455,6 +2932,96 @@ class NftService {
2455
2932
  }
2456
2933
  }
2457
2934
  }
2935
+ /**
2936
+ *
2937
+ * Commonly used to get NFT token IDs with metadata from a collection. Useful for building NFT card displays.
2938
+ *
2939
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
2940
+ * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
2941
+ * @param {GetTokenIdsForContractWithMetadataQueryParamOpts} queryParamOpts
2942
+ * - `noMetadata`: Omit metadata.
2943
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
2944
+ * - `pageNumber`: 0-indexed page number to begin pagination.
2945
+ * - `traitsFilter`: Filters NFTs based on a specific trait. If this filter is used, the API will return all NFTs with the specified trait. Accepts comma-separated values, is case-sensitive, and requires proper URL encoding.
2946
+ * - `valuesFilter`: Filters NFTs based on a specific trait value. If this filter is used, the API will return all NFTs with the specified trait value. If used with "traits-filter", only NFTs matching both filters will be returned. Accepts comma-separated values, is case-sensitive, and requires proper URL encoding.
2947
+ * - `withUncached`: By default, this endpoint only works on chains where we've cached the assets and the metadata. When set to `true`, the API will fetch metadata from upstream servers even if it's not cached - the downside being that the upstream server can block or rate limit the call and therefore resulting in time outs or slow response times on the Covalent side.
2948
+ *
2949
+ */
2950
+ async getTokenIdsForContractWithMetadataByPage(chainName, contractAddress, queryParamOpts) {
2951
+ let success = false;
2952
+ let data;
2953
+ let response;
2954
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
2955
+ while (!success) {
2956
+ try {
2957
+ const urlParams = new URLSearchParams();
2958
+ if (queryParamOpts?.noMetadata !== undefined) {
2959
+ urlParams.append("no-metadata", queryParamOpts?.noMetadata.toString());
2960
+ }
2961
+ if (queryParamOpts?.pageSize !== undefined) {
2962
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
2963
+ }
2964
+ if (queryParamOpts?.pageNumber !== undefined) {
2965
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
2966
+ }
2967
+ if (queryParamOpts?.traitsFilter !== undefined) {
2968
+ urlParams.append("traits-filter", queryParamOpts?.traitsFilter.toString());
2969
+ }
2970
+ if (queryParamOpts?.valuesFilter !== undefined) {
2971
+ urlParams.append("values-filter", queryParamOpts?.valuesFilter.toString());
2972
+ }
2973
+ if (queryParamOpts?.withUncached !== undefined) {
2974
+ urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
2975
+ }
2976
+ let startTime;
2977
+ if (this.debug) {
2978
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
2979
+ }
2980
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`, {
2981
+ headers: {
2982
+ "Authorization": `Bearer ${this.apiKey}`,
2983
+ "X-Requested-With": userAgent
2984
+ }
2985
+ }));
2986
+ debugOutput(response.url, response.status, startTime);
2987
+ if (response.status === 429) {
2988
+ try {
2989
+ data = await this.LIMIT(() => backoff.backOff(response.url));
2990
+ }
2991
+ catch (error) {
2992
+ success = true;
2993
+ return {
2994
+ data: null,
2995
+ error: true,
2996
+ error_code: response.status,
2997
+ error_message: error.message
2998
+ };
2999
+ }
3000
+ }
3001
+ else {
3002
+ data = await response.json();
3003
+ }
3004
+ const dataClass = new NftMetadataResponse(data.data);
3005
+ checkAndModifyResponse(dataClass);
3006
+ success = true;
3007
+ return {
3008
+ data: dataClass,
3009
+ error: data.error,
3010
+ error_code: data ? data.error_code : response.status,
3011
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3012
+ };
3013
+ }
3014
+ catch (error) {
3015
+ success = true;
3016
+ return {
3017
+ data: null,
3018
+ error: true,
3019
+ error_code: data ? data.error_code : response.status,
3020
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3021
+ };
3022
+ }
3023
+ }
3024
+ }
2458
3025
  /**
2459
3026
  *
2460
3027
  * Commonly used to get a single NFT metadata by token ID from a collection. Useful for building NFT card displays.
@@ -3741,6 +4308,7 @@ class TransactionService {
3741
4308
  * @param {GetTransactionsForBlockQueryParamOpts} queryParamOpts
3742
4309
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
3743
4310
  * - `noLogs`: Omit log events.
4311
+ * - `withSafe`: Include safe details.
3744
4312
  *
3745
4313
  */
3746
4314
  async getTransactionsForBlock(chainName, blockHeight, queryParamOpts) {
@@ -3757,6 +4325,9 @@ class TransactionService {
3757
4325
  if (queryParamOpts?.noLogs !== undefined) {
3758
4326
  urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
3759
4327
  }
4328
+ if (queryParamOpts?.withSafe !== undefined) {
4329
+ urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
4330
+ }
3760
4331
  let startTime;
3761
4332
  if (this.debug) {
3762
4333
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -5296,7 +5867,7 @@ class XykService {
5296
5867
  }
5297
5868
  }
5298
5869
 
5299
- const userAgent = "com.covalenthq.sdk.typescript/0.5.3";
5870
+ const userAgent = "com.covalenthq.sdk.typescript/0.6.1";
5300
5871
  /**
5301
5872
  * CovalentClient Class
5302
5873
  */