@covalenthq/client-sdk 0.5.2 → 0.6.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.
- package/README.md +12 -6
- package/dist/cjs/index.js +582 -26
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/BalanceService.d.ts +31 -1
- package/dist/cjs/services/BaseService.d.ts +94 -2
- package/dist/cjs/services/CovalentClient.d.ts +1 -1
- package/dist/cjs/services/NftService.d.ts +48 -1
- package/dist/cjs/services/TransactionService.d.ts +4 -1
- package/dist/cjs/util/types/BaseServiceTypes.d.ts +1 -1
- package/dist/cjs/util/types/GenericTypes.d.ts +1 -1
- package/dist/cjs/util/types/NftServiceTypes.d.ts +6 -0
- package/dist/es/index.js +582 -26
- package/dist/es/index.js.map +1 -1
- package/dist/es/services/BalanceService.d.ts +31 -1
- package/dist/es/services/BaseService.d.ts +94 -2
- package/dist/es/services/CovalentClient.d.ts +1 -1
- package/dist/es/services/NftService.d.ts +48 -1
- package/dist/es/services/TransactionService.d.ts +4 -1
- package/dist/es/util/types/BaseServiceTypes.d.ts +1 -1
- package/dist/es/util/types/GenericTypes.d.ts +1 -1
- package/dist/es/util/types/NftServiceTypes.d.ts +6 -0
- package/dist/esm/index.js +582 -26
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/BalanceService.d.ts +31 -1
- package/dist/esm/services/BaseService.d.ts +94 -2
- package/dist/esm/services/CovalentClient.d.ts +1 -1
- package/dist/esm/services/NftService.d.ts +48 -1
- package/dist/esm/services/TransactionService.d.ts +4 -1
- package/dist/esm/util/types/BaseServiceTypes.d.ts +1 -1
- package/dist/esm/util/types/GenericTypes.d.ts +1 -1
- package/dist/esm/util/types/NftServiceTypes.d.ts +6 -0
- package/dist/services/BalanceService.d.ts +31 -1
- package/dist/services/BalanceService.js +86 -0
- package/dist/services/BalanceService.js.map +1 -1
- package/dist/services/BaseService.d.ts +94 -2
- package/dist/services/BaseService.js +243 -0
- package/dist/services/BaseService.js.map +1 -1
- package/dist/services/CovalentClient.d.ts +1 -1
- package/dist/services/CovalentClient.js +1 -1
- package/dist/services/NftService.d.ts +48 -1
- package/dist/services/NftService.js +170 -0
- package/dist/services/NftService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +4 -1
- package/dist/services/TransactionService.js +4 -0
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/XykService.js.map +1 -1
- package/dist/util/types/BaseServiceTypes.d.ts +1 -1
- package/dist/util/types/GenericTypes.d.ts +1 -1
- package/dist/util/types/NftServiceTypes.d.ts +6 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -619,7 +619,7 @@ class Erc20TransfersResponse {
|
|
|
619
619
|
this.chain_id = data.chain_id;
|
|
620
620
|
this.chain_name = data.chain_name;
|
|
621
621
|
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$
|
|
622
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination$3(data.pagination) : null;
|
|
623
623
|
}
|
|
624
624
|
}
|
|
625
625
|
class BlockTransactionWithContractTransfers {
|
|
@@ -646,7 +646,7 @@ class BlockTransactionWithContractTransfers {
|
|
|
646
646
|
this.transfers = data.transfers && data.transfers !== null ? data.transfers.map((itemData) => new TokenTransferItem(itemData)) : null;
|
|
647
647
|
}
|
|
648
648
|
}
|
|
649
|
-
let Pagination$
|
|
649
|
+
let Pagination$3 = class Pagination {
|
|
650
650
|
constructor(data) {
|
|
651
651
|
this.has_more = data.has_more;
|
|
652
652
|
this.page_number = data.page_number;
|
|
@@ -683,6 +683,15 @@ class MethodCallsForTransfers {
|
|
|
683
683
|
this.method = data.method;
|
|
684
684
|
}
|
|
685
685
|
}
|
|
686
|
+
class TokenHoldersResponse {
|
|
687
|
+
constructor(data) {
|
|
688
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
689
|
+
this.chain_id = data.chain_id;
|
|
690
|
+
this.chain_name = data.chain_name;
|
|
691
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenHolder(itemData)) : null;
|
|
692
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination$3(data.pagination) : null;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
686
695
|
class TokenHolder {
|
|
687
696
|
constructor(data) {
|
|
688
697
|
this.contract_decimals = data.contract_decimals;
|
|
@@ -1074,6 +1083,7 @@ class BalanceService {
|
|
|
1074
1083
|
* - `blockHeight`: Ending block to define a block range. Omitting this parameter defaults to the latest block height.
|
|
1075
1084
|
* - `pageSize`: Number of items per page. Note: Currently, only values of `100` and `1000` are supported. Omitting this parameter defaults to 100.
|
|
1076
1085
|
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
1086
|
+
* - `date`: Ending date to define a block range (YYYY-MM-DD). Omitting this parameter defaults to the current date.
|
|
1077
1087
|
*
|
|
1078
1088
|
*/
|
|
1079
1089
|
async *getTokenHoldersV2ForTokenAddress(chainName, tokenAddress, queryParamOpts) {
|
|
@@ -1091,6 +1101,9 @@ class BalanceService {
|
|
|
1091
1101
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1092
1102
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1093
1103
|
}
|
|
1104
|
+
if (queryParamOpts?.date !== undefined) {
|
|
1105
|
+
urlParams.append("date", queryParamOpts?.date.toString());
|
|
1106
|
+
}
|
|
1094
1107
|
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
1108
|
yield res;
|
|
1096
1109
|
}
|
|
@@ -1102,6 +1115,88 @@ class BalanceService {
|
|
|
1102
1115
|
}
|
|
1103
1116
|
}
|
|
1104
1117
|
}
|
|
1118
|
+
/**
|
|
1119
|
+
*
|
|
1120
|
+
* 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.
|
|
1121
|
+
*
|
|
1122
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1123
|
+
* @param {string} tokenAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
1124
|
+
* @param {GetTokenHoldersV2ForTokenAddressQueryParamOpts} queryParamOpts
|
|
1125
|
+
* - `blockHeight`: Ending block to define a block range. Omitting this parameter defaults to the latest block height.
|
|
1126
|
+
* - `pageSize`: Number of items per page. Note: Currently, only values of `100` and `1000` are supported. Omitting this parameter defaults to 100.
|
|
1127
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
1128
|
+
* - `date`: Ending date to define a block range (YYYY-MM-DD). Omitting this parameter defaults to the current date.
|
|
1129
|
+
*
|
|
1130
|
+
*/
|
|
1131
|
+
async getTokenHoldersV2ForTokenAddressByPage(chainName, tokenAddress, queryParamOpts) {
|
|
1132
|
+
let success = false;
|
|
1133
|
+
let data;
|
|
1134
|
+
let response;
|
|
1135
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1136
|
+
while (!success) {
|
|
1137
|
+
try {
|
|
1138
|
+
const urlParams = new URLSearchParams();
|
|
1139
|
+
if (queryParamOpts?.blockHeight !== undefined) {
|
|
1140
|
+
urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
|
|
1141
|
+
}
|
|
1142
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
1143
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
1144
|
+
}
|
|
1145
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1146
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1147
|
+
}
|
|
1148
|
+
if (queryParamOpts?.date !== undefined) {
|
|
1149
|
+
urlParams.append("date", queryParamOpts?.date.toString());
|
|
1150
|
+
}
|
|
1151
|
+
let startTime;
|
|
1152
|
+
if (this.debug) {
|
|
1153
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
1154
|
+
}
|
|
1155
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/?${urlParams}`, {
|
|
1156
|
+
headers: {
|
|
1157
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
1158
|
+
"X-Requested-With": userAgent
|
|
1159
|
+
}
|
|
1160
|
+
}));
|
|
1161
|
+
debugOutput(response.url, response.status, startTime);
|
|
1162
|
+
if (response.status === 429) {
|
|
1163
|
+
try {
|
|
1164
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1165
|
+
}
|
|
1166
|
+
catch (error) {
|
|
1167
|
+
success = true;
|
|
1168
|
+
return {
|
|
1169
|
+
data: null,
|
|
1170
|
+
error: true,
|
|
1171
|
+
error_code: response.status,
|
|
1172
|
+
error_message: error.message
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
else {
|
|
1177
|
+
data = await response.json();
|
|
1178
|
+
}
|
|
1179
|
+
const dataClass = new TokenHoldersResponse(data.data);
|
|
1180
|
+
checkAndModifyResponse(dataClass);
|
|
1181
|
+
success = true;
|
|
1182
|
+
return {
|
|
1183
|
+
data: dataClass,
|
|
1184
|
+
error: data.error,
|
|
1185
|
+
error_code: data ? data.error_code : response.status,
|
|
1186
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
catch (error) {
|
|
1190
|
+
success = true;
|
|
1191
|
+
return {
|
|
1192
|
+
data: null,
|
|
1193
|
+
error: true,
|
|
1194
|
+
error_code: data ? data.error_code : response.status,
|
|
1195
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1105
1200
|
/**
|
|
1106
1201
|
*
|
|
1107
1202
|
* 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 +1393,23 @@ class ResolvedAddressItem {
|
|
|
1298
1393
|
this.name = data.name;
|
|
1299
1394
|
}
|
|
1300
1395
|
}
|
|
1396
|
+
class BlockHeightsResponse {
|
|
1397
|
+
constructor(data) {
|
|
1398
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
1399
|
+
this.chain_id = data.chain_id;
|
|
1400
|
+
this.chain_name = data.chain_name;
|
|
1401
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new Block(itemData)) : null;
|
|
1402
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination$2(data.pagination) : null;
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
let Pagination$2 = class Pagination {
|
|
1406
|
+
constructor(data) {
|
|
1407
|
+
this.has_more = data.has_more;
|
|
1408
|
+
this.page_number = data.page_number;
|
|
1409
|
+
this.page_size = data.page_size;
|
|
1410
|
+
this.total_count = data.total_count;
|
|
1411
|
+
}
|
|
1412
|
+
};
|
|
1301
1413
|
class GetLogsResponse {
|
|
1302
1414
|
constructor(data) {
|
|
1303
1415
|
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
@@ -1341,6 +1453,15 @@ let Param$2 = class Param {
|
|
|
1341
1453
|
this.value = data.value;
|
|
1342
1454
|
}
|
|
1343
1455
|
};
|
|
1456
|
+
class LogEventsByAddressResponse {
|
|
1457
|
+
constructor(data) {
|
|
1458
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
1459
|
+
this.chain_id = data.chain_id;
|
|
1460
|
+
this.chain_name = data.chain_name;
|
|
1461
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new LogEvent$2(itemData)) : null;
|
|
1462
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination$2(data.pagination) : null;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1344
1465
|
let LogEvent$2 = class LogEvent {
|
|
1345
1466
|
constructor(data) {
|
|
1346
1467
|
this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? dateFns.parseISO(data.block_signed_at.toString()) : null;
|
|
@@ -1359,6 +1480,15 @@ let LogEvent$2 = class LogEvent {
|
|
|
1359
1480
|
this.decoded = data.decoded && data.decoded !== null ? new DecodedItem$2(data.decoded) : null;
|
|
1360
1481
|
}
|
|
1361
1482
|
};
|
|
1483
|
+
class LogEventsByTopicHashResponse {
|
|
1484
|
+
constructor(data) {
|
|
1485
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
1486
|
+
this.chain_id = data.chain_id;
|
|
1487
|
+
this.chain_name = data.chain_name;
|
|
1488
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new LogEvent$2(itemData)) : null;
|
|
1489
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination$2(data.pagination) : null;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1362
1492
|
class AllChainsResponse {
|
|
1363
1493
|
constructor(data) {
|
|
1364
1494
|
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
@@ -1600,6 +1730,81 @@ class BaseService {
|
|
|
1600
1730
|
}
|
|
1601
1731
|
}
|
|
1602
1732
|
}
|
|
1733
|
+
/**
|
|
1734
|
+
*
|
|
1735
|
+
* Commonly used to get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day.
|
|
1736
|
+
*
|
|
1737
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1738
|
+
* @param {string} startDate - The start date in YYYY-MM-DD format.
|
|
1739
|
+
* @param {string} endDate - The end date in YYYY-MM-DD format.
|
|
1740
|
+
* @param {GetBlockHeightsQueryParamOpts} queryParamOpts
|
|
1741
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
1742
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
1743
|
+
*
|
|
1744
|
+
*/
|
|
1745
|
+
async getBlockHeightsByPage(chainName, startDate, endDate, queryParamOpts) {
|
|
1746
|
+
let success = false;
|
|
1747
|
+
let data;
|
|
1748
|
+
let response;
|
|
1749
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1750
|
+
while (!success) {
|
|
1751
|
+
try {
|
|
1752
|
+
const urlParams = new URLSearchParams();
|
|
1753
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
1754
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
1755
|
+
}
|
|
1756
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1757
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1758
|
+
}
|
|
1759
|
+
let startTime;
|
|
1760
|
+
if (this.debug) {
|
|
1761
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
1762
|
+
}
|
|
1763
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/?${urlParams}`, {
|
|
1764
|
+
headers: {
|
|
1765
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
1766
|
+
"X-Requested-With": userAgent
|
|
1767
|
+
}
|
|
1768
|
+
}));
|
|
1769
|
+
debugOutput(response.url, response.status, startTime);
|
|
1770
|
+
if (response.status === 429) {
|
|
1771
|
+
try {
|
|
1772
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1773
|
+
}
|
|
1774
|
+
catch (error) {
|
|
1775
|
+
success = true;
|
|
1776
|
+
return {
|
|
1777
|
+
data: null,
|
|
1778
|
+
error: true,
|
|
1779
|
+
error_code: response.status,
|
|
1780
|
+
error_message: error.message
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
else {
|
|
1785
|
+
data = await response.json();
|
|
1786
|
+
}
|
|
1787
|
+
const dataClass = new BlockHeightsResponse(data.data);
|
|
1788
|
+
checkAndModifyResponse(dataClass);
|
|
1789
|
+
success = true;
|
|
1790
|
+
return {
|
|
1791
|
+
data: dataClass,
|
|
1792
|
+
error: data.error,
|
|
1793
|
+
error_code: data ? data.error_code : response.status,
|
|
1794
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
catch (error) {
|
|
1798
|
+
success = true;
|
|
1799
|
+
return {
|
|
1800
|
+
data: null,
|
|
1801
|
+
error: true,
|
|
1802
|
+
error_code: data ? data.error_code : response.status,
|
|
1803
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1804
|
+
};
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1603
1808
|
/**
|
|
1604
1809
|
*
|
|
1605
1810
|
* 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 +1819,137 @@ class BaseService {
|
|
|
1614
1819
|
* - `skipDecode`: Omit decoded log events.
|
|
1615
1820
|
*
|
|
1616
1821
|
*/
|
|
1617
|
-
async getLogs(chainName, queryParamOpts) {
|
|
1822
|
+
async getLogs(chainName, queryParamOpts) {
|
|
1823
|
+
let success = false;
|
|
1824
|
+
let data;
|
|
1825
|
+
let response;
|
|
1826
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1827
|
+
while (!success) {
|
|
1828
|
+
try {
|
|
1829
|
+
const urlParams = new URLSearchParams();
|
|
1830
|
+
if (queryParamOpts?.startingBlock !== undefined) {
|
|
1831
|
+
urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
|
|
1832
|
+
}
|
|
1833
|
+
if (queryParamOpts?.endingBlock !== undefined) {
|
|
1834
|
+
urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
|
|
1835
|
+
}
|
|
1836
|
+
if (queryParamOpts?.address !== undefined) {
|
|
1837
|
+
urlParams.append("address", queryParamOpts?.address.toString());
|
|
1838
|
+
}
|
|
1839
|
+
if (queryParamOpts?.topics !== undefined) {
|
|
1840
|
+
urlParams.append("topics", queryParamOpts?.topics.toString());
|
|
1841
|
+
}
|
|
1842
|
+
if (queryParamOpts?.blockHash !== undefined) {
|
|
1843
|
+
urlParams.append("block-hash", queryParamOpts?.blockHash.toString());
|
|
1844
|
+
}
|
|
1845
|
+
if (queryParamOpts?.skipDecode !== undefined) {
|
|
1846
|
+
urlParams.append("skip-decode", queryParamOpts?.skipDecode.toString());
|
|
1847
|
+
}
|
|
1848
|
+
let startTime;
|
|
1849
|
+
if (this.debug) {
|
|
1850
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
1851
|
+
}
|
|
1852
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`, {
|
|
1853
|
+
headers: {
|
|
1854
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
1855
|
+
"X-Requested-With": userAgent
|
|
1856
|
+
}
|
|
1857
|
+
}));
|
|
1858
|
+
debugOutput(response.url, response.status, startTime);
|
|
1859
|
+
if (response.status === 429) {
|
|
1860
|
+
try {
|
|
1861
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1862
|
+
}
|
|
1863
|
+
catch (error) {
|
|
1864
|
+
success = true;
|
|
1865
|
+
return {
|
|
1866
|
+
data: null,
|
|
1867
|
+
error: true,
|
|
1868
|
+
error_code: response.status,
|
|
1869
|
+
error_message: error.message
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
else {
|
|
1874
|
+
data = await response.json();
|
|
1875
|
+
}
|
|
1876
|
+
const dataClass = new GetLogsResponse(data.data);
|
|
1877
|
+
checkAndModifyResponse(dataClass);
|
|
1878
|
+
success = true;
|
|
1879
|
+
return {
|
|
1880
|
+
data: dataClass,
|
|
1881
|
+
error: data.error,
|
|
1882
|
+
error_code: data ? data.error_code : response.status,
|
|
1883
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1886
|
+
catch (error) {
|
|
1887
|
+
success = true;
|
|
1888
|
+
return {
|
|
1889
|
+
data: null,
|
|
1890
|
+
error: true,
|
|
1891
|
+
error_code: data ? data.error_code : response.status,
|
|
1892
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1893
|
+
};
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
/**
|
|
1898
|
+
*
|
|
1899
|
+
* Commonly used to get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions.
|
|
1900
|
+
*
|
|
1901
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1902
|
+
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
1903
|
+
* @param {GetLogEventsByAddressQueryParamOpts} queryParamOpts
|
|
1904
|
+
* - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
1905
|
+
* - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
1906
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
1907
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
1908
|
+
*
|
|
1909
|
+
*/
|
|
1910
|
+
async *getLogEventsByAddress(chainName, contractAddress, queryParamOpts) {
|
|
1911
|
+
let success = false;
|
|
1912
|
+
let res;
|
|
1913
|
+
while (!success) {
|
|
1914
|
+
try {
|
|
1915
|
+
const urlParams = new URLSearchParams();
|
|
1916
|
+
if (queryParamOpts?.startingBlock !== undefined) {
|
|
1917
|
+
urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
|
|
1918
|
+
}
|
|
1919
|
+
if (queryParamOpts?.endingBlock !== undefined) {
|
|
1920
|
+
urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
|
|
1921
|
+
}
|
|
1922
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
1923
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
1924
|
+
}
|
|
1925
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1926
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1927
|
+
}
|
|
1928
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
|
|
1929
|
+
yield res;
|
|
1930
|
+
}
|
|
1931
|
+
success = true;
|
|
1932
|
+
}
|
|
1933
|
+
catch (error) {
|
|
1934
|
+
success = true;
|
|
1935
|
+
throw new Error(error.message);
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
/**
|
|
1940
|
+
*
|
|
1941
|
+
* Commonly used to get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions.
|
|
1942
|
+
*
|
|
1943
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1944
|
+
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
1945
|
+
* @param {GetLogEventsByAddressQueryParamOpts} queryParamOpts
|
|
1946
|
+
* - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
1947
|
+
* - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
1948
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
1949
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
1950
|
+
*
|
|
1951
|
+
*/
|
|
1952
|
+
async getLogEventsByAddressByPage(chainName, contractAddress, queryParamOpts) {
|
|
1618
1953
|
let success = false;
|
|
1619
1954
|
let data;
|
|
1620
1955
|
let response;
|
|
@@ -1628,23 +1963,17 @@ class BaseService {
|
|
|
1628
1963
|
if (queryParamOpts?.endingBlock !== undefined) {
|
|
1629
1964
|
urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
|
|
1630
1965
|
}
|
|
1631
|
-
if (queryParamOpts?.
|
|
1632
|
-
urlParams.append("
|
|
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());
|
|
1966
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
1967
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
1639
1968
|
}
|
|
1640
|
-
if (queryParamOpts?.
|
|
1641
|
-
urlParams.append("
|
|
1969
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1970
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1642
1971
|
}
|
|
1643
1972
|
let startTime;
|
|
1644
1973
|
if (this.debug) {
|
|
1645
1974
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
1646
1975
|
}
|
|
1647
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`, {
|
|
1976
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/?${urlParams}`, {
|
|
1648
1977
|
headers: {
|
|
1649
1978
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1650
1979
|
"X-Requested-With": userAgent
|
|
@@ -1668,7 +1997,7 @@ class BaseService {
|
|
|
1668
1997
|
else {
|
|
1669
1998
|
data = await response.json();
|
|
1670
1999
|
}
|
|
1671
|
-
const dataClass = new
|
|
2000
|
+
const dataClass = new LogEventsByAddressResponse(data.data);
|
|
1672
2001
|
checkAndModifyResponse(dataClass);
|
|
1673
2002
|
success = true;
|
|
1674
2003
|
return {
|
|
@@ -1691,18 +2020,19 @@ class BaseService {
|
|
|
1691
2020
|
}
|
|
1692
2021
|
/**
|
|
1693
2022
|
*
|
|
1694
|
-
* Commonly used to get all
|
|
2023
|
+
* 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
2024
|
*
|
|
1696
2025
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1697
|
-
* @param {string}
|
|
1698
|
-
* @param {
|
|
2026
|
+
* @param {string} topicHash - The endpoint will return event logs that contain this topic hash.
|
|
2027
|
+
* @param {GetLogEventsByTopicHashQueryParamOpts} queryParamOpts
|
|
1699
2028
|
* - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
1700
2029
|
* - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
2030
|
+
* - `secondaryTopics`: Additional topic hash(es) to filter on - padded & unpadded address fields are supported. Separate multiple topics with a comma.
|
|
1701
2031
|
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
1702
2032
|
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
1703
2033
|
*
|
|
1704
2034
|
*/
|
|
1705
|
-
async *
|
|
2035
|
+
async *getLogEventsByTopicHash(chainName, topicHash, queryParamOpts) {
|
|
1706
2036
|
let success = false;
|
|
1707
2037
|
let res;
|
|
1708
2038
|
while (!success) {
|
|
@@ -1714,13 +2044,16 @@ class BaseService {
|
|
|
1714
2044
|
if (queryParamOpts?.endingBlock !== undefined) {
|
|
1715
2045
|
urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
|
|
1716
2046
|
}
|
|
2047
|
+
if (queryParamOpts?.secondaryTopics !== undefined) {
|
|
2048
|
+
urlParams.append("secondary-topics", queryParamOpts?.secondaryTopics.toString());
|
|
2049
|
+
}
|
|
1717
2050
|
if (queryParamOpts?.pageSize !== undefined) {
|
|
1718
2051
|
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
1719
2052
|
}
|
|
1720
2053
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1721
2054
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1722
2055
|
}
|
|
1723
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/
|
|
2056
|
+
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
2057
|
yield res;
|
|
1725
2058
|
}
|
|
1726
2059
|
success = true;
|
|
@@ -1745,9 +2078,11 @@ class BaseService {
|
|
|
1745
2078
|
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
1746
2079
|
*
|
|
1747
2080
|
*/
|
|
1748
|
-
async
|
|
2081
|
+
async getLogEventsByTopicHashByPage(chainName, topicHash, queryParamOpts) {
|
|
1749
2082
|
let success = false;
|
|
1750
|
-
let
|
|
2083
|
+
let data;
|
|
2084
|
+
let response;
|
|
2085
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1751
2086
|
while (!success) {
|
|
1752
2087
|
try {
|
|
1753
2088
|
const urlParams = new URLSearchParams();
|
|
@@ -1766,14 +2101,52 @@ class BaseService {
|
|
|
1766
2101
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1767
2102
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1768
2103
|
}
|
|
1769
|
-
|
|
1770
|
-
|
|
2104
|
+
let startTime;
|
|
2105
|
+
if (this.debug) {
|
|
2106
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
2107
|
+
}
|
|
2108
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/?${urlParams}`, {
|
|
2109
|
+
headers: {
|
|
2110
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
2111
|
+
"X-Requested-With": userAgent
|
|
2112
|
+
}
|
|
2113
|
+
}));
|
|
2114
|
+
debugOutput(response.url, response.status, startTime);
|
|
2115
|
+
if (response.status === 429) {
|
|
2116
|
+
try {
|
|
2117
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2118
|
+
}
|
|
2119
|
+
catch (error) {
|
|
2120
|
+
success = true;
|
|
2121
|
+
return {
|
|
2122
|
+
data: null,
|
|
2123
|
+
error: true,
|
|
2124
|
+
error_code: response.status,
|
|
2125
|
+
error_message: error.message
|
|
2126
|
+
};
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
else {
|
|
2130
|
+
data = await response.json();
|
|
1771
2131
|
}
|
|
2132
|
+
const dataClass = new LogEventsByTopicHashResponse(data.data);
|
|
2133
|
+
checkAndModifyResponse(dataClass);
|
|
1772
2134
|
success = true;
|
|
2135
|
+
return {
|
|
2136
|
+
data: dataClass,
|
|
2137
|
+
error: data.error,
|
|
2138
|
+
error_code: data ? data.error_code : response.status,
|
|
2139
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2140
|
+
};
|
|
1773
2141
|
}
|
|
1774
2142
|
catch (error) {
|
|
1775
2143
|
success = true;
|
|
1776
|
-
|
|
2144
|
+
return {
|
|
2145
|
+
data: null,
|
|
2146
|
+
error: true,
|
|
2147
|
+
error_code: data ? data.error_code : response.status,
|
|
2148
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2149
|
+
};
|
|
1777
2150
|
}
|
|
1778
2151
|
}
|
|
1779
2152
|
}
|
|
@@ -1974,6 +2347,15 @@ class BaseService {
|
|
|
1974
2347
|
}
|
|
1975
2348
|
}
|
|
1976
2349
|
|
|
2350
|
+
class ChainCollectionResponse {
|
|
2351
|
+
constructor(data) {
|
|
2352
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
2353
|
+
this.chain_id = data.chain_id;
|
|
2354
|
+
this.chain_name = data.chain_name;
|
|
2355
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new ChainCollectionItem(itemData)) : null;
|
|
2356
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination$1(data.pagination) : null;
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
1977
2359
|
class ChainCollectionItem {
|
|
1978
2360
|
constructor(data) {
|
|
1979
2361
|
this.contract_address = data.contract_address;
|
|
@@ -2011,6 +2393,9 @@ class NftTokenContractBalanceItem {
|
|
|
2011
2393
|
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
2012
2394
|
this.balance_24h = data.balance_24h;
|
|
2013
2395
|
this.type = data.type;
|
|
2396
|
+
this.floor_price_quote = data.floor_price_quote;
|
|
2397
|
+
this.pretty_floor_price_quote = data.pretty_floor_price_quote;
|
|
2398
|
+
this.floor_price_native_quote = data.floor_price_native_quote;
|
|
2014
2399
|
this.nft_data = data.nft_data && data.nft_data !== null ? data.nft_data.map((itemData) => new NftData(itemData)) : null;
|
|
2015
2400
|
}
|
|
2016
2401
|
}
|
|
@@ -2327,6 +2712,83 @@ class NftService {
|
|
|
2327
2712
|
}
|
|
2328
2713
|
}
|
|
2329
2714
|
}
|
|
2715
|
+
/**
|
|
2716
|
+
*
|
|
2717
|
+
* Commonly used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files.
|
|
2718
|
+
*
|
|
2719
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
2720
|
+
* @param {GetChainCollectionsQueryParamOpts} queryParamOpts
|
|
2721
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
2722
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
2723
|
+
* - `noSpam`: If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
|
|
2724
|
+
*
|
|
2725
|
+
*/
|
|
2726
|
+
async getChainCollectionsByPage(chainName, queryParamOpts) {
|
|
2727
|
+
let success = false;
|
|
2728
|
+
let data;
|
|
2729
|
+
let response;
|
|
2730
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
2731
|
+
while (!success) {
|
|
2732
|
+
try {
|
|
2733
|
+
const urlParams = new URLSearchParams();
|
|
2734
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
2735
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
2736
|
+
}
|
|
2737
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2738
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2739
|
+
}
|
|
2740
|
+
if (queryParamOpts?.noSpam !== undefined) {
|
|
2741
|
+
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
2742
|
+
}
|
|
2743
|
+
let startTime;
|
|
2744
|
+
if (this.debug) {
|
|
2745
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
2746
|
+
}
|
|
2747
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`, {
|
|
2748
|
+
headers: {
|
|
2749
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
2750
|
+
"X-Requested-With": userAgent
|
|
2751
|
+
}
|
|
2752
|
+
}));
|
|
2753
|
+
debugOutput(response.url, response.status, startTime);
|
|
2754
|
+
if (response.status === 429) {
|
|
2755
|
+
try {
|
|
2756
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2757
|
+
}
|
|
2758
|
+
catch (error) {
|
|
2759
|
+
success = true;
|
|
2760
|
+
return {
|
|
2761
|
+
data: null,
|
|
2762
|
+
error: true,
|
|
2763
|
+
error_code: response.status,
|
|
2764
|
+
error_message: error.message
|
|
2765
|
+
};
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
else {
|
|
2769
|
+
data = await response.json();
|
|
2770
|
+
}
|
|
2771
|
+
const dataClass = new ChainCollectionResponse(data.data);
|
|
2772
|
+
checkAndModifyResponse(dataClass);
|
|
2773
|
+
success = true;
|
|
2774
|
+
return {
|
|
2775
|
+
data: dataClass,
|
|
2776
|
+
error: data.error,
|
|
2777
|
+
error_code: data ? data.error_code : response.status,
|
|
2778
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2779
|
+
};
|
|
2780
|
+
}
|
|
2781
|
+
catch (error) {
|
|
2782
|
+
success = true;
|
|
2783
|
+
return {
|
|
2784
|
+
data: null,
|
|
2785
|
+
error: true,
|
|
2786
|
+
error_code: data ? data.error_code : response.status,
|
|
2787
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2788
|
+
};
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2330
2792
|
/**
|
|
2331
2793
|
*
|
|
2332
2794
|
* Commonly used to render the NFTs (including ERC721 and ERC1155) held by an address.
|
|
@@ -2455,6 +2917,96 @@ class NftService {
|
|
|
2455
2917
|
}
|
|
2456
2918
|
}
|
|
2457
2919
|
}
|
|
2920
|
+
/**
|
|
2921
|
+
*
|
|
2922
|
+
* Commonly used to get NFT token IDs with metadata from a collection. Useful for building NFT card displays.
|
|
2923
|
+
*
|
|
2924
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
2925
|
+
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
2926
|
+
* @param {GetTokenIdsForContractWithMetadataQueryParamOpts} queryParamOpts
|
|
2927
|
+
* - `noMetadata`: Omit metadata.
|
|
2928
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
2929
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
2930
|
+
* - `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.
|
|
2931
|
+
* - `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.
|
|
2932
|
+
* - `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.
|
|
2933
|
+
*
|
|
2934
|
+
*/
|
|
2935
|
+
async getTokenIdsForContractWithMetadataByPage(chainName, contractAddress, queryParamOpts) {
|
|
2936
|
+
let success = false;
|
|
2937
|
+
let data;
|
|
2938
|
+
let response;
|
|
2939
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
2940
|
+
while (!success) {
|
|
2941
|
+
try {
|
|
2942
|
+
const urlParams = new URLSearchParams();
|
|
2943
|
+
if (queryParamOpts?.noMetadata !== undefined) {
|
|
2944
|
+
urlParams.append("no-metadata", queryParamOpts?.noMetadata.toString());
|
|
2945
|
+
}
|
|
2946
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
2947
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
2948
|
+
}
|
|
2949
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2950
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2951
|
+
}
|
|
2952
|
+
if (queryParamOpts?.traitsFilter !== undefined) {
|
|
2953
|
+
urlParams.append("traits-filter", queryParamOpts?.traitsFilter.toString());
|
|
2954
|
+
}
|
|
2955
|
+
if (queryParamOpts?.valuesFilter !== undefined) {
|
|
2956
|
+
urlParams.append("values-filter", queryParamOpts?.valuesFilter.toString());
|
|
2957
|
+
}
|
|
2958
|
+
if (queryParamOpts?.withUncached !== undefined) {
|
|
2959
|
+
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
2960
|
+
}
|
|
2961
|
+
let startTime;
|
|
2962
|
+
if (this.debug) {
|
|
2963
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
2964
|
+
}
|
|
2965
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`, {
|
|
2966
|
+
headers: {
|
|
2967
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
2968
|
+
"X-Requested-With": userAgent
|
|
2969
|
+
}
|
|
2970
|
+
}));
|
|
2971
|
+
debugOutput(response.url, response.status, startTime);
|
|
2972
|
+
if (response.status === 429) {
|
|
2973
|
+
try {
|
|
2974
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2975
|
+
}
|
|
2976
|
+
catch (error) {
|
|
2977
|
+
success = true;
|
|
2978
|
+
return {
|
|
2979
|
+
data: null,
|
|
2980
|
+
error: true,
|
|
2981
|
+
error_code: response.status,
|
|
2982
|
+
error_message: error.message
|
|
2983
|
+
};
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
else {
|
|
2987
|
+
data = await response.json();
|
|
2988
|
+
}
|
|
2989
|
+
const dataClass = new NftMetadataResponse(data.data);
|
|
2990
|
+
checkAndModifyResponse(dataClass);
|
|
2991
|
+
success = true;
|
|
2992
|
+
return {
|
|
2993
|
+
data: dataClass,
|
|
2994
|
+
error: data.error,
|
|
2995
|
+
error_code: data ? data.error_code : response.status,
|
|
2996
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2997
|
+
};
|
|
2998
|
+
}
|
|
2999
|
+
catch (error) {
|
|
3000
|
+
success = true;
|
|
3001
|
+
return {
|
|
3002
|
+
data: null,
|
|
3003
|
+
error: true,
|
|
3004
|
+
error_code: data ? data.error_code : response.status,
|
|
3005
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3006
|
+
};
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
2458
3010
|
/**
|
|
2459
3011
|
*
|
|
2460
3012
|
* Commonly used to get a single NFT metadata by token ID from a collection. Useful for building NFT card displays.
|
|
@@ -3741,6 +4293,7 @@ class TransactionService {
|
|
|
3741
4293
|
* @param {GetTransactionsForBlockQueryParamOpts} queryParamOpts
|
|
3742
4294
|
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
3743
4295
|
* - `noLogs`: Omit log events.
|
|
4296
|
+
* - `withSafe`: Include safe details.
|
|
3744
4297
|
*
|
|
3745
4298
|
*/
|
|
3746
4299
|
async getTransactionsForBlock(chainName, blockHeight, queryParamOpts) {
|
|
@@ -3757,6 +4310,9 @@ class TransactionService {
|
|
|
3757
4310
|
if (queryParamOpts?.noLogs !== undefined) {
|
|
3758
4311
|
urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
|
|
3759
4312
|
}
|
|
4313
|
+
if (queryParamOpts?.withSafe !== undefined) {
|
|
4314
|
+
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
4315
|
+
}
|
|
3760
4316
|
let startTime;
|
|
3761
4317
|
if (this.debug) {
|
|
3762
4318
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -5296,7 +5852,7 @@ class XykService {
|
|
|
5296
5852
|
}
|
|
5297
5853
|
}
|
|
5298
5854
|
|
|
5299
|
-
const userAgent = "com.covalenthq.sdk.typescript/0.
|
|
5855
|
+
const userAgent = "com.covalenthq.sdk.typescript/0.6.0";
|
|
5300
5856
|
/**
|
|
5301
5857
|
* CovalentClient Class
|
|
5302
5858
|
*/
|