@covalenthq/client-sdk 0.2.9 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -14
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.js +4619 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/services/BalanceService.d.ts +443 -0
- package/dist/cjs/services/BaseService.d.ts +357 -0
- package/dist/cjs/services/CovalentClient.d.ts +65 -0
- package/dist/cjs/services/NftService.d.ts +484 -0
- package/dist/cjs/services/PricingService.d.ts +88 -0
- package/dist/cjs/services/SecurityService.d.ts +96 -0
- package/dist/cjs/services/TransactionService.d.ts +440 -0
- package/dist/cjs/services/XykService.d.ts +682 -0
- package/dist/cjs/util/ApiHelpers.d.ts +5 -0
- package/dist/cjs/util/backoff.d.ts +11 -0
- package/dist/cjs/util/types/BalanceServiceTypes.d.ts +284 -0
- package/dist/cjs/util/types/BaseServiceTypes.d.ts +180 -0
- package/dist/cjs/util/types/GenericTypes.d.ts +96 -0
- package/dist/cjs/util/types/NftServiceTypes.d.ts +221 -0
- package/dist/cjs/util/types/PricingServiceTypes.d.ts +31 -0
- package/dist/cjs/util/types/SecurityServiceTypes.d.ts +71 -0
- package/dist/cjs/util/types/TransactionServiceTypes.d.ts +312 -0
- package/dist/cjs/util/types/XykServiceTypes.d.ts +479 -0
- package/dist/es/index.d.ts +9 -0
- package/dist/es/index.js +4616 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/services/BalanceService.d.ts +443 -0
- package/dist/es/services/BaseService.d.ts +357 -0
- package/dist/es/services/CovalentClient.d.ts +65 -0
- package/dist/es/services/NftService.d.ts +484 -0
- package/dist/es/services/PricingService.d.ts +88 -0
- package/dist/es/services/SecurityService.d.ts +96 -0
- package/dist/es/services/TransactionService.d.ts +440 -0
- package/dist/es/services/XykService.d.ts +682 -0
- package/dist/es/util/ApiHelpers.d.ts +5 -0
- package/dist/es/util/backoff.d.ts +11 -0
- package/dist/es/util/types/BalanceServiceTypes.d.ts +284 -0
- package/dist/es/util/types/BaseServiceTypes.d.ts +180 -0
- package/dist/es/util/types/GenericTypes.d.ts +96 -0
- package/dist/es/util/types/NftServiceTypes.d.ts +221 -0
- package/dist/es/util/types/PricingServiceTypes.d.ts +31 -0
- package/dist/es/util/types/SecurityServiceTypes.d.ts +71 -0
- package/dist/es/util/types/TransactionServiceTypes.d.ts +312 -0
- package/dist/es/util/types/XykServiceTypes.d.ts +479 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +4616 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/services/BalanceService.d.ts +443 -0
- package/dist/esm/services/BaseService.d.ts +357 -0
- package/dist/esm/services/CovalentClient.d.ts +65 -0
- package/dist/esm/services/NftService.d.ts +484 -0
- package/dist/esm/services/PricingService.d.ts +88 -0
- package/dist/esm/services/SecurityService.d.ts +96 -0
- package/dist/esm/services/TransactionService.d.ts +440 -0
- package/dist/esm/services/XykService.d.ts +682 -0
- package/dist/esm/util/ApiHelpers.d.ts +5 -0
- package/dist/esm/util/backoff.d.ts +11 -0
- package/dist/esm/util/types/BalanceServiceTypes.d.ts +284 -0
- package/dist/esm/util/types/BaseServiceTypes.d.ts +180 -0
- package/dist/esm/util/types/GenericTypes.d.ts +96 -0
- package/dist/esm/util/types/NftServiceTypes.d.ts +221 -0
- package/dist/esm/util/types/PricingServiceTypes.d.ts +31 -0
- package/dist/esm/util/types/SecurityServiceTypes.d.ts +71 -0
- package/dist/esm/util/types/TransactionServiceTypes.d.ts +312 -0
- package/dist/esm/util/types/XykServiceTypes.d.ts +479 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -27
- package/dist/index.js.map +1 -1
- package/dist/services/BalanceService.d.ts +49 -11
- package/dist/services/BalanceService.js +110 -81
- package/dist/services/BalanceService.js.map +1 -1
- package/dist/services/BaseService.d.ts +46 -10
- package/dist/services/BaseService.js +193 -145
- package/dist/services/BaseService.js.map +1 -1
- package/dist/services/CovalentClient.d.ts +65 -0
- package/dist/services/CovalentClient.js +44 -0
- package/dist/services/CovalentClient.js.map +1 -0
- package/dist/services/NftService.d.ts +52 -22
- package/dist/services/NftService.js +236 -235
- package/dist/services/NftService.js.map +1 -1
- package/dist/services/PricingService.d.ts +8 -3
- package/dist/services/PricingService.js +43 -37
- package/dist/services/PricingService.js.map +1 -1
- package/dist/services/SecurityService.d.ts +9 -3
- package/dist/services/SecurityService.js +38 -31
- package/dist/services/SecurityService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +41 -9
- package/dist/services/TransactionService.js +133 -100
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/XykService.d.ts +81 -19
- package/dist/services/XykService.js +451 -278
- package/dist/services/XykService.js.map +1 -1
- package/dist/util/ApiHelpers.d.ts +2 -1
- package/dist/util/ApiHelpers.js +57 -36
- package/dist/util/ApiHelpers.js.map +1 -1
- package/dist/util/backoff.d.ts +5 -3
- package/dist/util/backoff.js +35 -13
- package/dist/util/backoff.js.map +1 -1
- package/dist/util/types/BalanceServiceTypes.d.ts +25 -0
- package/dist/util/types/BalanceServiceTypes.js +1 -2
- package/dist/util/types/BaseServiceTypes.d.ts +8 -0
- package/dist/util/types/BaseServiceTypes.js +1 -2
- package/dist/util/types/GenericTypes.d.ts +7 -0
- package/dist/util/types/GenericTypes.js +1 -2
- package/dist/util/types/NftServiceTypes.d.ts +10 -2
- package/dist/util/types/NftServiceTypes.js +1 -2
- package/dist/util/types/PricingServiceTypes.js +1 -2
- package/dist/util/types/SecurityServiceTypes.d.ts +1 -0
- package/dist/util/types/SecurityServiceTypes.js +1 -2
- package/dist/util/types/TransactionServiceTypes.d.ts +14 -2
- package/dist/util/types/TransactionServiceTypes.js +1 -2
- package/dist/util/types/XykServiceTypes.d.ts +20 -6
- package/dist/util/types/XykServiceTypes.js +1 -2
- package/package.json +19 -4
- package/dist/services/Client.d.ts +0 -29
- package/dist/services/Client.js +0 -30
- package/dist/services/Client.js.map +0 -1
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const date_fns_1 = require("date-fns");
|
|
7
|
-
const backoff_1 = require("../util/backoff");
|
|
1
|
+
import { userAgent } from "./CovalentClient";
|
|
2
|
+
import { checkAndModifyResponse, debugOutput, paginateEndpoint } from "../util/ApiHelpers";
|
|
3
|
+
import { parseISO } from "date-fns";
|
|
4
|
+
import { ExponentialBackoff } from "../util/backoff";
|
|
5
|
+
import pLimit from "p-limit";
|
|
8
6
|
class ChainCollectionResponse {
|
|
9
7
|
constructor(data) {
|
|
10
|
-
this.updated_at = data.updated_at && data.updated_at !== null ?
|
|
8
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
11
9
|
this.chain_id = data.chain_id;
|
|
12
10
|
this.chain_name = data.chain_name;
|
|
13
11
|
this.items = data.items && data.items !== null ? data.items.map((itemData) => new ChainCollectionItem(itemData)) : null;
|
|
@@ -22,7 +20,7 @@ class ChainCollectionItem {
|
|
|
22
20
|
this.token_total_supply = data.token_total_supply;
|
|
23
21
|
this.cached_metadata_count = data.cached_metadata_count;
|
|
24
22
|
this.cached_asset_count = data.cached_asset_count;
|
|
25
|
-
this.last_scraped_at = data.last_scraped_at && data.last_scraped_at !== null ?
|
|
23
|
+
this.last_scraped_at = data.last_scraped_at && data.last_scraped_at !== null ? parseISO(data.last_scraped_at.toString()) : null;
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
class Pagination {
|
|
@@ -36,7 +34,7 @@ class Pagination {
|
|
|
36
34
|
class NftAddressBalanceNftResponse {
|
|
37
35
|
constructor(data) {
|
|
38
36
|
this.address = data.address;
|
|
39
|
-
this.updated_at = data.updated_at && data.updated_at !== null ?
|
|
37
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
40
38
|
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTokenContractBalanceItem(itemData)) : null;
|
|
41
39
|
}
|
|
42
40
|
}
|
|
@@ -47,9 +45,9 @@ class NftTokenContractBalanceItem {
|
|
|
47
45
|
this.contract_address = data.contract_address;
|
|
48
46
|
this.supports_erc = data.supports_erc;
|
|
49
47
|
this.is_spam = data.is_spam;
|
|
50
|
-
this.last_transfered_at = data.last_transfered_at && data.last_transfered_at !== null ?
|
|
48
|
+
this.last_transfered_at = data.last_transfered_at && data.last_transfered_at !== null ? parseISO(data.last_transfered_at.toString()) : null;
|
|
51
49
|
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
52
|
-
this.
|
|
50
|
+
this.balance_24h = data.balance_24h;
|
|
53
51
|
this.type = data.type;
|
|
54
52
|
this.nft_data = data.nft_data && data.nft_data !== null ? data.nft_data.map((itemData) => new NftData(itemData)) : null;
|
|
55
53
|
}
|
|
@@ -89,7 +87,7 @@ class NftCollectionAttribute {
|
|
|
89
87
|
}
|
|
90
88
|
class NftMetadataResponse {
|
|
91
89
|
constructor(data) {
|
|
92
|
-
this.updated_at = data.updated_at && data.updated_at !== null ?
|
|
90
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
93
91
|
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTokenContract(itemData)) : null;
|
|
94
92
|
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
95
93
|
}
|
|
@@ -106,7 +104,7 @@ class NftTokenContract {
|
|
|
106
104
|
}
|
|
107
105
|
class NftTransactionsResponse {
|
|
108
106
|
constructor(data) {
|
|
109
|
-
this.updated_at = data.updated_at && data.updated_at !== null ?
|
|
107
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
110
108
|
this.chain_id = data.chain_id;
|
|
111
109
|
this.chain_name = data.chain_name;
|
|
112
110
|
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTransaction(itemData)) : null;
|
|
@@ -126,7 +124,7 @@ class NftTransaction {
|
|
|
126
124
|
}
|
|
127
125
|
class NftTransactionItem {
|
|
128
126
|
constructor(data) {
|
|
129
|
-
this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ?
|
|
127
|
+
this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
|
|
130
128
|
this.block_height = data.block_height;
|
|
131
129
|
this.tx_hash = data.tx_hash;
|
|
132
130
|
this.tx_offset = data.tx_offset;
|
|
@@ -150,7 +148,7 @@ class NftTransactionItem {
|
|
|
150
148
|
}
|
|
151
149
|
class LogEvent {
|
|
152
150
|
constructor(data) {
|
|
153
|
-
this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ?
|
|
151
|
+
this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
|
|
154
152
|
this.block_height = data.block_height;
|
|
155
153
|
this.tx_offset = data.tx_offset;
|
|
156
154
|
this.log_offset = data.log_offset;
|
|
@@ -184,7 +182,7 @@ class Param {
|
|
|
184
182
|
}
|
|
185
183
|
class NftCollectionTraitsResponse {
|
|
186
184
|
constructor(data) {
|
|
187
|
-
this.updated_at = data.updated_at && data.updated_at !== null ?
|
|
185
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
188
186
|
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTrait(itemData)) : null;
|
|
189
187
|
}
|
|
190
188
|
}
|
|
@@ -195,7 +193,7 @@ class NftTrait {
|
|
|
195
193
|
}
|
|
196
194
|
class NftCollectionAttributesForTraitResponse {
|
|
197
195
|
constructor(data) {
|
|
198
|
-
this.updated_at = data.updated_at && data.updated_at !== null ?
|
|
196
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
199
197
|
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftSummaryAttribute(itemData)) : null;
|
|
200
198
|
}
|
|
201
199
|
}
|
|
@@ -214,7 +212,7 @@ class NftAttribute {
|
|
|
214
212
|
}
|
|
215
213
|
class NftCollectionTraitSummaryResponse {
|
|
216
214
|
constructor(data) {
|
|
217
|
-
this.updated_at = data.updated_at && data.updated_at !== null ?
|
|
215
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
218
216
|
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTraitSummary(itemData)) : null;
|
|
219
217
|
}
|
|
220
218
|
}
|
|
@@ -242,7 +240,7 @@ class NftTraitString {
|
|
|
242
240
|
}
|
|
243
241
|
class NftOwnershipForCollectionResponse {
|
|
244
242
|
constructor(data) {
|
|
245
|
-
this.updated_at = data.updated_at && data.updated_at !== null ?
|
|
243
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
246
244
|
this.address = data.address;
|
|
247
245
|
this.collection = data.collection;
|
|
248
246
|
this.is_spam = data.is_spam;
|
|
@@ -256,9 +254,9 @@ class NftOwnershipForCollectionItem {
|
|
|
256
254
|
this.contract_address = data.contract_address;
|
|
257
255
|
this.token_id = data.token_id && data.token_id !== null ? BigInt(data.token_id) : null;
|
|
258
256
|
this.supports_erc = data.supports_erc;
|
|
259
|
-
this.last_transfered_at = data.last_transfered_at && data.last_transfered_at !== null ?
|
|
257
|
+
this.last_transfered_at = data.last_transfered_at && data.last_transfered_at !== null ? parseISO(data.last_transfered_at.toString()) : null;
|
|
260
258
|
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
261
|
-
this.
|
|
259
|
+
this.balance_24h = data.balance_24h;
|
|
262
260
|
this.type = data.type;
|
|
263
261
|
this.nft_data = data.nft_data && data.nft_data !== null ? new NftData(data.nft_data) : null;
|
|
264
262
|
}
|
|
@@ -267,11 +265,16 @@ class NftOwnershipForCollectionItem {
|
|
|
267
265
|
* NFT APIs
|
|
268
266
|
*
|
|
269
267
|
*/
|
|
270
|
-
class NftService {
|
|
271
|
-
constructor(apiKey) {
|
|
268
|
+
export class NftService {
|
|
269
|
+
constructor(apiKey, debug = false, threadCount = 3) {
|
|
272
270
|
this.apiKey = apiKey;
|
|
271
|
+
this.debug = debug;
|
|
272
|
+
this.threadCount = threadCount;
|
|
273
|
+
this.LIMIT = pLimit(this.threadCount);
|
|
273
274
|
}
|
|
274
275
|
/**
|
|
276
|
+
*
|
|
277
|
+
* Commonly used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files.
|
|
275
278
|
*
|
|
276
279
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
277
280
|
* @param {GetChainCollectionsQueryParamOpts} queryParamOpts
|
|
@@ -295,18 +298,20 @@ class NftService {
|
|
|
295
298
|
if (queryParamOpts?.noSpam !== undefined) {
|
|
296
299
|
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
297
300
|
}
|
|
298
|
-
for await (res of
|
|
301
|
+
for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount)) {
|
|
299
302
|
yield res;
|
|
300
303
|
}
|
|
301
304
|
success = true;
|
|
302
305
|
}
|
|
303
306
|
catch (error) {
|
|
304
307
|
success = true;
|
|
305
|
-
|
|
308
|
+
throw new Error(error.message);
|
|
306
309
|
}
|
|
307
310
|
}
|
|
308
311
|
}
|
|
309
312
|
/**
|
|
313
|
+
*
|
|
314
|
+
* Commonly used to render the NFTs (including ERC721 and ERC1155) held by an address.
|
|
310
315
|
*
|
|
311
316
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
312
317
|
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
@@ -320,7 +325,7 @@ class NftService {
|
|
|
320
325
|
let success = false;
|
|
321
326
|
let data;
|
|
322
327
|
let response;
|
|
323
|
-
const backoff = new
|
|
328
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
324
329
|
while (!success) {
|
|
325
330
|
try {
|
|
326
331
|
const urlParams = new URLSearchParams();
|
|
@@ -333,38 +338,43 @@ class NftService {
|
|
|
333
338
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
334
339
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
335
340
|
}
|
|
336
|
-
|
|
341
|
+
let startTime;
|
|
342
|
+
if (this.debug) {
|
|
343
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
344
|
+
}
|
|
345
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`, {
|
|
337
346
|
headers: {
|
|
338
347
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
339
|
-
"X-Requested-With":
|
|
348
|
+
"X-Requested-With": userAgent
|
|
340
349
|
}
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
if (
|
|
350
|
+
}));
|
|
351
|
+
debugOutput(response.url, response.status, startTime);
|
|
352
|
+
if (response.status === 429) {
|
|
344
353
|
try {
|
|
345
|
-
await backoff.backOff();
|
|
354
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
346
355
|
}
|
|
347
356
|
catch (error) {
|
|
348
357
|
success = true;
|
|
349
358
|
return {
|
|
350
359
|
data: null,
|
|
351
|
-
error:
|
|
352
|
-
error_code:
|
|
353
|
-
error_message:
|
|
360
|
+
error: true,
|
|
361
|
+
error_code: response.status,
|
|
362
|
+
error_message: error.message
|
|
354
363
|
};
|
|
355
364
|
}
|
|
356
365
|
}
|
|
357
366
|
else {
|
|
358
|
-
|
|
359
|
-
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
360
|
-
success = true;
|
|
361
|
-
return {
|
|
362
|
-
data: dataClass,
|
|
363
|
-
error: data.error,
|
|
364
|
-
error_code: data ? data.error_code : response.status,
|
|
365
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
366
|
-
};
|
|
367
|
+
data = await response.json();
|
|
367
368
|
}
|
|
369
|
+
const dataClass = new NftAddressBalanceNftResponse(data.data);
|
|
370
|
+
checkAndModifyResponse(dataClass);
|
|
371
|
+
success = true;
|
|
372
|
+
return {
|
|
373
|
+
data: dataClass,
|
|
374
|
+
error: data.error,
|
|
375
|
+
error_code: data ? data.error_code : response.status,
|
|
376
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
377
|
+
};
|
|
368
378
|
}
|
|
369
379
|
catch (error) {
|
|
370
380
|
success = true;
|
|
@@ -378,6 +388,8 @@ class NftService {
|
|
|
378
388
|
}
|
|
379
389
|
}
|
|
380
390
|
/**
|
|
391
|
+
*
|
|
392
|
+
* Commonly used to get NFT token IDs with metadata from a collection. Useful for building NFT card displays.
|
|
381
393
|
*
|
|
382
394
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
383
395
|
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
@@ -414,18 +426,20 @@ class NftService {
|
|
|
414
426
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
415
427
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
416
428
|
}
|
|
417
|
-
for await (res of
|
|
429
|
+
for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount)) {
|
|
418
430
|
yield res;
|
|
419
431
|
}
|
|
420
432
|
success = true;
|
|
421
433
|
}
|
|
422
434
|
catch (error) {
|
|
423
435
|
success = true;
|
|
424
|
-
|
|
436
|
+
throw new Error(error.message);
|
|
425
437
|
}
|
|
426
438
|
}
|
|
427
439
|
}
|
|
428
440
|
/**
|
|
441
|
+
*
|
|
442
|
+
* Commonly used to get a single NFT metadata by token ID from a collection. Useful for building NFT card displays.
|
|
429
443
|
*
|
|
430
444
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
431
445
|
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
@@ -439,7 +453,7 @@ class NftService {
|
|
|
439
453
|
let success = false;
|
|
440
454
|
let data;
|
|
441
455
|
let response;
|
|
442
|
-
const backoff = new
|
|
456
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
443
457
|
while (!success) {
|
|
444
458
|
try {
|
|
445
459
|
const urlParams = new URLSearchParams();
|
|
@@ -449,38 +463,43 @@ class NftService {
|
|
|
449
463
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
450
464
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
451
465
|
}
|
|
452
|
-
|
|
466
|
+
let startTime;
|
|
467
|
+
if (this.debug) {
|
|
468
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
469
|
+
}
|
|
470
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`, {
|
|
453
471
|
headers: {
|
|
454
472
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
455
|
-
"X-Requested-With":
|
|
473
|
+
"X-Requested-With": userAgent
|
|
456
474
|
}
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
if (
|
|
475
|
+
}));
|
|
476
|
+
debugOutput(response.url, response.status, startTime);
|
|
477
|
+
if (response.status === 429) {
|
|
460
478
|
try {
|
|
461
|
-
await backoff.backOff();
|
|
479
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
462
480
|
}
|
|
463
481
|
catch (error) {
|
|
464
482
|
success = true;
|
|
465
483
|
return {
|
|
466
484
|
data: null,
|
|
467
|
-
error:
|
|
468
|
-
error_code:
|
|
469
|
-
error_message:
|
|
485
|
+
error: true,
|
|
486
|
+
error_code: response.status,
|
|
487
|
+
error_message: error.message
|
|
470
488
|
};
|
|
471
489
|
}
|
|
472
490
|
}
|
|
473
491
|
else {
|
|
474
|
-
|
|
475
|
-
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
476
|
-
success = true;
|
|
477
|
-
return {
|
|
478
|
-
data: dataClass,
|
|
479
|
-
error: data.error,
|
|
480
|
-
error_code: data ? data.error_code : response.status,
|
|
481
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
482
|
-
};
|
|
492
|
+
data = await response.json();
|
|
483
493
|
}
|
|
494
|
+
const dataClass = new NftMetadataResponse(data.data);
|
|
495
|
+
checkAndModifyResponse(dataClass);
|
|
496
|
+
success = true;
|
|
497
|
+
return {
|
|
498
|
+
data: dataClass,
|
|
499
|
+
error: data.error,
|
|
500
|
+
error_code: data ? data.error_code : response.status,
|
|
501
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
502
|
+
};
|
|
484
503
|
}
|
|
485
504
|
catch (error) {
|
|
486
505
|
success = true;
|
|
@@ -494,6 +513,8 @@ class NftService {
|
|
|
494
513
|
}
|
|
495
514
|
}
|
|
496
515
|
/**
|
|
516
|
+
*
|
|
517
|
+
* Commonly used to get all transactions of an NFT token. Useful for building a transaction history table or price chart.
|
|
497
518
|
*
|
|
498
519
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
499
520
|
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
@@ -506,45 +527,50 @@ class NftService {
|
|
|
506
527
|
let success = false;
|
|
507
528
|
let data;
|
|
508
529
|
let response;
|
|
509
|
-
const backoff = new
|
|
530
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
510
531
|
while (!success) {
|
|
511
532
|
try {
|
|
512
533
|
const urlParams = new URLSearchParams();
|
|
513
534
|
if (queryParamOpts?.noSpam !== undefined) {
|
|
514
535
|
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
515
536
|
}
|
|
516
|
-
|
|
537
|
+
let startTime;
|
|
538
|
+
if (this.debug) {
|
|
539
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
540
|
+
}
|
|
541
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`, {
|
|
517
542
|
headers: {
|
|
518
543
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
519
|
-
"X-Requested-With":
|
|
544
|
+
"X-Requested-With": userAgent
|
|
520
545
|
}
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
if (
|
|
546
|
+
}));
|
|
547
|
+
debugOutput(response.url, response.status, startTime);
|
|
548
|
+
if (response.status === 429) {
|
|
524
549
|
try {
|
|
525
|
-
await backoff.backOff();
|
|
550
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
526
551
|
}
|
|
527
552
|
catch (error) {
|
|
528
553
|
success = true;
|
|
529
554
|
return {
|
|
530
555
|
data: null,
|
|
531
|
-
error:
|
|
532
|
-
error_code:
|
|
533
|
-
error_message:
|
|
556
|
+
error: true,
|
|
557
|
+
error_code: response.status,
|
|
558
|
+
error_message: error.message
|
|
534
559
|
};
|
|
535
560
|
}
|
|
536
561
|
}
|
|
537
562
|
else {
|
|
538
|
-
|
|
539
|
-
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
540
|
-
success = true;
|
|
541
|
-
return {
|
|
542
|
-
data: dataClass,
|
|
543
|
-
error: data.error,
|
|
544
|
-
error_code: data ? data.error_code : response.status,
|
|
545
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
546
|
-
};
|
|
563
|
+
data = await response.json();
|
|
547
564
|
}
|
|
565
|
+
const dataClass = new NftTransactionsResponse(data.data);
|
|
566
|
+
checkAndModifyResponse(dataClass);
|
|
567
|
+
success = true;
|
|
568
|
+
return {
|
|
569
|
+
data: dataClass,
|
|
570
|
+
error: data.error,
|
|
571
|
+
error_code: data ? data.error_code : response.status,
|
|
572
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
573
|
+
};
|
|
548
574
|
}
|
|
549
575
|
catch (error) {
|
|
550
576
|
success = true;
|
|
@@ -558,6 +584,8 @@ class NftService {
|
|
|
558
584
|
}
|
|
559
585
|
}
|
|
560
586
|
/**
|
|
587
|
+
*
|
|
588
|
+
* Commonly used to fetch and render the traits of a collection as seen in rarity calculators.
|
|
561
589
|
*
|
|
562
590
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
563
591
|
* @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
@@ -567,42 +595,47 @@ class NftService {
|
|
|
567
595
|
let success = false;
|
|
568
596
|
let data;
|
|
569
597
|
let response;
|
|
570
|
-
const backoff = new
|
|
598
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
571
599
|
while (!success) {
|
|
572
600
|
try {
|
|
573
601
|
const urlParams = new URLSearchParams();
|
|
574
|
-
|
|
602
|
+
let startTime;
|
|
603
|
+
if (this.debug) {
|
|
604
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
605
|
+
}
|
|
606
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`, {
|
|
575
607
|
headers: {
|
|
576
608
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
577
|
-
"X-Requested-With":
|
|
609
|
+
"X-Requested-With": userAgent
|
|
578
610
|
}
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
if (
|
|
611
|
+
}));
|
|
612
|
+
debugOutput(response.url, response.status, startTime);
|
|
613
|
+
if (response.status === 429) {
|
|
582
614
|
try {
|
|
583
|
-
await backoff.backOff();
|
|
615
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
584
616
|
}
|
|
585
617
|
catch (error) {
|
|
586
618
|
success = true;
|
|
587
619
|
return {
|
|
588
620
|
data: null,
|
|
589
|
-
error:
|
|
590
|
-
error_code:
|
|
591
|
-
error_message:
|
|
621
|
+
error: true,
|
|
622
|
+
error_code: response.status,
|
|
623
|
+
error_message: error.message
|
|
592
624
|
};
|
|
593
625
|
}
|
|
594
626
|
}
|
|
595
627
|
else {
|
|
596
|
-
|
|
597
|
-
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
598
|
-
success = true;
|
|
599
|
-
return {
|
|
600
|
-
data: dataClass,
|
|
601
|
-
error: data.error,
|
|
602
|
-
error_code: data ? data.error_code : response.status,
|
|
603
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
604
|
-
};
|
|
628
|
+
data = await response.json();
|
|
605
629
|
}
|
|
630
|
+
const dataClass = new NftCollectionTraitsResponse(data.data);
|
|
631
|
+
checkAndModifyResponse(dataClass);
|
|
632
|
+
success = true;
|
|
633
|
+
return {
|
|
634
|
+
data: dataClass,
|
|
635
|
+
error: data.error,
|
|
636
|
+
error_code: data ? data.error_code : response.status,
|
|
637
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
638
|
+
};
|
|
606
639
|
}
|
|
607
640
|
catch (error) {
|
|
608
641
|
success = true;
|
|
@@ -616,6 +649,8 @@ class NftService {
|
|
|
616
649
|
}
|
|
617
650
|
}
|
|
618
651
|
/**
|
|
652
|
+
*
|
|
653
|
+
* Commonly used to get the count of unique values for traits within an NFT collection.
|
|
619
654
|
*
|
|
620
655
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
621
656
|
* @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
@@ -626,42 +661,47 @@ class NftService {
|
|
|
626
661
|
let success = false;
|
|
627
662
|
let data;
|
|
628
663
|
let response;
|
|
629
|
-
const backoff = new
|
|
664
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
630
665
|
while (!success) {
|
|
631
666
|
try {
|
|
632
667
|
const urlParams = new URLSearchParams();
|
|
633
|
-
|
|
668
|
+
let startTime;
|
|
669
|
+
if (this.debug) {
|
|
670
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
671
|
+
}
|
|
672
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`, {
|
|
634
673
|
headers: {
|
|
635
674
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
636
|
-
"X-Requested-With":
|
|
675
|
+
"X-Requested-With": userAgent
|
|
637
676
|
}
|
|
638
|
-
});
|
|
639
|
-
|
|
640
|
-
if (
|
|
677
|
+
}));
|
|
678
|
+
debugOutput(response.url, response.status, startTime);
|
|
679
|
+
if (response.status === 429) {
|
|
641
680
|
try {
|
|
642
|
-
await backoff.backOff();
|
|
681
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
643
682
|
}
|
|
644
683
|
catch (error) {
|
|
645
684
|
success = true;
|
|
646
685
|
return {
|
|
647
686
|
data: null,
|
|
648
|
-
error:
|
|
649
|
-
error_code:
|
|
650
|
-
error_message:
|
|
687
|
+
error: true,
|
|
688
|
+
error_code: response.status,
|
|
689
|
+
error_message: error.message
|
|
651
690
|
};
|
|
652
691
|
}
|
|
653
692
|
}
|
|
654
693
|
else {
|
|
655
|
-
|
|
656
|
-
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
657
|
-
success = true;
|
|
658
|
-
return {
|
|
659
|
-
data: dataClass,
|
|
660
|
-
error: data.error,
|
|
661
|
-
error_code: data ? data.error_code : response.status,
|
|
662
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
663
|
-
};
|
|
694
|
+
data = await response.json();
|
|
664
695
|
}
|
|
696
|
+
const dataClass = new NftCollectionAttributesForTraitResponse(data.data);
|
|
697
|
+
checkAndModifyResponse(dataClass);
|
|
698
|
+
success = true;
|
|
699
|
+
return {
|
|
700
|
+
data: dataClass,
|
|
701
|
+
error: data.error,
|
|
702
|
+
error_code: data ? data.error_code : response.status,
|
|
703
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
704
|
+
};
|
|
665
705
|
}
|
|
666
706
|
catch (error) {
|
|
667
707
|
success = true;
|
|
@@ -675,6 +715,8 @@ class NftService {
|
|
|
675
715
|
}
|
|
676
716
|
}
|
|
677
717
|
/**
|
|
718
|
+
*
|
|
719
|
+
* Commonly used to calculate rarity scores for a collection based on its traits.
|
|
678
720
|
*
|
|
679
721
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
680
722
|
* @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
@@ -684,42 +726,47 @@ class NftService {
|
|
|
684
726
|
let success = false;
|
|
685
727
|
let data;
|
|
686
728
|
let response;
|
|
687
|
-
const backoff = new
|
|
729
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
688
730
|
while (!success) {
|
|
689
731
|
try {
|
|
690
732
|
const urlParams = new URLSearchParams();
|
|
691
|
-
|
|
733
|
+
let startTime;
|
|
734
|
+
if (this.debug) {
|
|
735
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
736
|
+
}
|
|
737
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`, {
|
|
692
738
|
headers: {
|
|
693
739
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
694
|
-
"X-Requested-With":
|
|
740
|
+
"X-Requested-With": userAgent
|
|
695
741
|
}
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
if (
|
|
742
|
+
}));
|
|
743
|
+
debugOutput(response.url, response.status, startTime);
|
|
744
|
+
if (response.status === 429) {
|
|
699
745
|
try {
|
|
700
|
-
await backoff.backOff();
|
|
746
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
701
747
|
}
|
|
702
748
|
catch (error) {
|
|
703
749
|
success = true;
|
|
704
750
|
return {
|
|
705
751
|
data: null,
|
|
706
|
-
error:
|
|
707
|
-
error_code:
|
|
708
|
-
error_message:
|
|
752
|
+
error: true,
|
|
753
|
+
error_code: response.status,
|
|
754
|
+
error_message: error.message
|
|
709
755
|
};
|
|
710
756
|
}
|
|
711
757
|
}
|
|
712
758
|
else {
|
|
713
|
-
|
|
714
|
-
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
715
|
-
success = true;
|
|
716
|
-
return {
|
|
717
|
-
data: dataClass,
|
|
718
|
-
error: data.error,
|
|
719
|
-
error_code: data ? data.error_code : response.status,
|
|
720
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
721
|
-
};
|
|
759
|
+
data = await response.json();
|
|
722
760
|
}
|
|
761
|
+
const dataClass = new NftCollectionTraitSummaryResponse(data.data);
|
|
762
|
+
checkAndModifyResponse(dataClass);
|
|
763
|
+
success = true;
|
|
764
|
+
return {
|
|
765
|
+
data: dataClass,
|
|
766
|
+
error: data.error,
|
|
767
|
+
error_code: data ? data.error_code : response.status,
|
|
768
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
769
|
+
};
|
|
723
770
|
}
|
|
724
771
|
catch (error) {
|
|
725
772
|
success = true;
|
|
@@ -733,6 +780,8 @@ class NftService {
|
|
|
733
780
|
}
|
|
734
781
|
}
|
|
735
782
|
/**
|
|
783
|
+
*
|
|
784
|
+
* Commonly used to verify ownership of NFTs (including ERC-721 and ERC-1155) within a collection.
|
|
736
785
|
*
|
|
737
786
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
738
787
|
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
@@ -743,42 +792,47 @@ class NftService {
|
|
|
743
792
|
let success = false;
|
|
744
793
|
let data;
|
|
745
794
|
let response;
|
|
746
|
-
const backoff = new
|
|
795
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
747
796
|
while (!success) {
|
|
748
797
|
try {
|
|
749
798
|
const urlParams = new URLSearchParams();
|
|
750
|
-
|
|
799
|
+
let startTime;
|
|
800
|
+
if (this.debug) {
|
|
801
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
802
|
+
}
|
|
803
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`, {
|
|
751
804
|
headers: {
|
|
752
805
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
753
|
-
"X-Requested-With":
|
|
806
|
+
"X-Requested-With": userAgent
|
|
754
807
|
}
|
|
755
|
-
});
|
|
756
|
-
|
|
757
|
-
if (
|
|
808
|
+
}));
|
|
809
|
+
debugOutput(response.url, response.status, startTime);
|
|
810
|
+
if (response.status === 429) {
|
|
758
811
|
try {
|
|
759
|
-
await backoff.backOff();
|
|
812
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
760
813
|
}
|
|
761
814
|
catch (error) {
|
|
762
815
|
success = true;
|
|
763
816
|
return {
|
|
764
817
|
data: null,
|
|
765
|
-
error:
|
|
766
|
-
error_code:
|
|
767
|
-
error_message:
|
|
818
|
+
error: true,
|
|
819
|
+
error_code: response.status,
|
|
820
|
+
error_message: error.message
|
|
768
821
|
};
|
|
769
822
|
}
|
|
770
823
|
}
|
|
771
824
|
else {
|
|
772
|
-
|
|
773
|
-
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
774
|
-
success = true;
|
|
775
|
-
return {
|
|
776
|
-
data: dataClass,
|
|
777
|
-
error: data.error,
|
|
778
|
-
error_code: data ? data.error_code : response.status,
|
|
779
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
780
|
-
};
|
|
825
|
+
data = await response.json();
|
|
781
826
|
}
|
|
827
|
+
const dataClass = new NftOwnershipForCollectionResponse(data.data);
|
|
828
|
+
checkAndModifyResponse(dataClass);
|
|
829
|
+
success = true;
|
|
830
|
+
return {
|
|
831
|
+
data: dataClass,
|
|
832
|
+
error: data.error,
|
|
833
|
+
error_code: data ? data.error_code : response.status,
|
|
834
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
835
|
+
};
|
|
782
836
|
}
|
|
783
837
|
catch (error) {
|
|
784
838
|
success = true;
|
|
@@ -792,6 +846,8 @@ class NftService {
|
|
|
792
846
|
}
|
|
793
847
|
}
|
|
794
848
|
/**
|
|
849
|
+
*
|
|
850
|
+
* Commonly used to verify ownership of a specific token (ERC-721 or ERC-1155) within a collection.
|
|
795
851
|
*
|
|
796
852
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
797
853
|
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
@@ -803,102 +859,48 @@ class NftService {
|
|
|
803
859
|
let success = false;
|
|
804
860
|
let data;
|
|
805
861
|
let response;
|
|
806
|
-
const backoff = new
|
|
862
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
807
863
|
while (!success) {
|
|
808
864
|
try {
|
|
809
865
|
const urlParams = new URLSearchParams();
|
|
810
|
-
|
|
866
|
+
let startTime;
|
|
867
|
+
if (this.debug) {
|
|
868
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
869
|
+
}
|
|
870
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`, {
|
|
811
871
|
headers: {
|
|
812
872
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
813
|
-
"X-Requested-With":
|
|
873
|
+
"X-Requested-With": userAgent
|
|
814
874
|
}
|
|
815
|
-
});
|
|
816
|
-
|
|
817
|
-
if (
|
|
875
|
+
}));
|
|
876
|
+
debugOutput(response.url, response.status, startTime);
|
|
877
|
+
if (response.status === 429) {
|
|
818
878
|
try {
|
|
819
|
-
await backoff.backOff();
|
|
879
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
820
880
|
}
|
|
821
881
|
catch (error) {
|
|
822
882
|
success = true;
|
|
823
883
|
return {
|
|
824
884
|
data: null,
|
|
825
|
-
error:
|
|
826
|
-
error_code:
|
|
827
|
-
error_message:
|
|
885
|
+
error: true,
|
|
886
|
+
error_code: response.status,
|
|
887
|
+
error_message: error.message
|
|
828
888
|
};
|
|
829
889
|
}
|
|
830
890
|
}
|
|
831
891
|
else {
|
|
832
|
-
|
|
833
|
-
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
834
|
-
success = true;
|
|
835
|
-
return {
|
|
836
|
-
data: dataClass,
|
|
837
|
-
error: data.error,
|
|
838
|
-
error_code: data ? data.error_code : response.status,
|
|
839
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
840
|
-
};
|
|
892
|
+
data = await response.json();
|
|
841
893
|
}
|
|
842
|
-
|
|
843
|
-
|
|
894
|
+
const dataClass = new NftOwnershipForCollectionResponse(data.data);
|
|
895
|
+
checkAndModifyResponse(dataClass);
|
|
844
896
|
success = true;
|
|
845
897
|
return {
|
|
846
|
-
data:
|
|
847
|
-
error:
|
|
898
|
+
data: dataClass,
|
|
899
|
+
error: data.error,
|
|
848
900
|
error_code: data ? data.error_code : response.status,
|
|
849
901
|
error_message: data ? data.error_message : "401 Authorization Required"
|
|
850
902
|
};
|
|
851
903
|
}
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
/**
|
|
855
|
-
*
|
|
856
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
857
|
-
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
858
|
-
* @param {string} tokenId - The requested token ID.
|
|
859
|
-
*
|
|
860
|
-
*/
|
|
861
|
-
async getNftExternalMetadataForContract(chainName, contractAddress, tokenId) {
|
|
862
|
-
let success = false;
|
|
863
|
-
let data;
|
|
864
|
-
let response;
|
|
865
|
-
const backoff = new backoff_1.ExponentialBackoff();
|
|
866
|
-
while (!success) {
|
|
867
|
-
try {
|
|
868
|
-
const urlParams = new URLSearchParams();
|
|
869
|
-
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_metadata/${tokenId}/?${urlParams}`, {
|
|
870
|
-
headers: {
|
|
871
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
872
|
-
"X-Requested-With": Client_1.userAgent
|
|
873
|
-
}
|
|
874
|
-
});
|
|
875
|
-
data = await response.json();
|
|
876
|
-
if (data.error && data.error_code === 429) {
|
|
877
|
-
try {
|
|
878
|
-
await backoff.backOff();
|
|
879
|
-
}
|
|
880
|
-
catch (error) {
|
|
881
|
-
success = true;
|
|
882
|
-
return {
|
|
883
|
-
data: null,
|
|
884
|
-
error: data.error,
|
|
885
|
-
error_code: data ? data.error_code : response.status,
|
|
886
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
887
|
-
};
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
else {
|
|
891
|
-
const dataClass = new NftMetadataResponse(data.data);
|
|
892
|
-
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
893
|
-
success = true;
|
|
894
|
-
return {
|
|
895
|
-
data: dataClass,
|
|
896
|
-
error: data.error,
|
|
897
|
-
error_code: data ? data.error_code : response.status,
|
|
898
|
-
error_message: data ? data.error_message : "401 Authorization Required"
|
|
899
|
-
};
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
904
|
catch (error) {
|
|
903
905
|
success = true;
|
|
904
906
|
return {
|
|
@@ -911,5 +913,4 @@ class NftService {
|
|
|
911
913
|
}
|
|
912
914
|
}
|
|
913
915
|
}
|
|
914
|
-
exports.NftService = NftService;
|
|
915
916
|
//# sourceMappingURL=NftService.js.map
|