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