@quicknode/sdk 1.0.0-beta.1 → 1.0.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 CHANGED
@@ -1,7 +1,5 @@
1
1
  # QuickNode SDK
2
2
 
3
- > :warning: **This is an beta release** This release is not production-ready yet and only meant as a technical preview. The API could break in subsequent beta releases until the 1.0.0 release is finalized.
4
-
5
3
  A SDK from [QuickNode](https://www.quicknode.com/) making it easy for developers to interact with QuickNode's services.
6
4
 
7
5
  QuickNode's SDK is a JavaScript and TypeScript framework-agnostic library that supports both CommonJS and ES module systems.
@@ -20,42 +18,6 @@ Currently the SDK makes it even easier to use the [QuickNode Graph API](https://
20
18
 
21
19
  <br>
22
20
 
23
- - [QuickNode SDK](#quicknode-sdk)
24
- - [Getting Started](#getting-started)
25
- - [Installation](#installation)
26
- - [Quickstart](#quickstart)
27
- - [API functions](#api-functions)
28
- - [Configuration](#configuration)
29
- - [Configuration Arguments](#configuration-arguments)
30
- - [nfts.getByWallet](#nftsgetbywallet)
31
- - [nfts.getTrendingCollections](#nftsgettrendingcollections)
32
- - [nfts.getByContractAddress](#nftsgetbycontractaddress)
33
- - [nfts.getNFTDetails](#nftsgetnftdetails)
34
- - [nfts.getCollectionDetails](#nftsgetcollectiondetails)
35
- - [tokens.getBalancesByWallet](#tokensgetbalancesbywallet)
36
- - [contracts.getDetails](#contractsgetdetails)
37
- - [transactions.getByWallet](#transactionsgetbywallet)
38
- - [transactions.getAll](#transactionsgetall)
39
- - [transactions.getByHash](#transactionsgetbyhash)
40
- - [events.getByContract](#eventsgetbycontract)
41
- - [events.getByNFTCollection](#eventsgetbynftcollection)
42
- - [events.getByNFT](#eventsgetbynft)
43
- - [events.getAll](#eventsgetall)
44
- - [utils.getGasPrices](#utilsgetgasprices)
45
- - [graphApiClient.query](#graphapiclientquery)
46
- - [Error Handling](#error-handling)
47
- - [Filters](#filters)
48
- - [Token Event Filters](#token-event-filters)
49
- - [Pagination](#pagination)
50
- - [Contributing corner](#contributing-corner)
51
- - [Issues](#issues)
52
- - [Development](#development)
53
- - [Running tests](#running-tests)
54
- - [Running linting](#running-linting)
55
- - [Generate graphql codegen typings](#generate-graphql-codegen-typings)
56
-
57
- <br>
58
-
59
21
  ## Getting Started
60
22
 
61
23
  ### Installation
@@ -84,806 +46,9 @@ Full example app implementation [here](https://github.com/quiknode-labs/qn-oss/t
84
46
 
85
47
  <br>
86
48
 
87
- ## API functions
88
-
89
- These functions return data from the powerful [QuickNode Graph API](https://www.quicknode.com/graph-api), making it even easier to use.
90
-
91
- <br>
92
-
93
- ### Configuration
94
-
95
- Sign up for a [QuickNode](https://www.quicknode.com/) account to use the multi-chain [QuickNode Graph API](https://www.quicknode.com/graph-api) API key in the SDK. The API functions in the SDK (and the underlying Graph API) can be used without an API key, but its usage will be heavily rate limited, intended for trial and development purposes only. For more information, please see [QuickNode's Graph API documentation](https://docs.quicknode.com/docs/graphql/getting-started/)
96
-
97
- ```ts
98
- import QuickNode from '@quicknode/sdk';
99
-
100
- const qn = new QuickNode.API({
101
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
102
- defaultChain: 'ethereum',
103
- });
104
- ```
105
-
106
- A `defaultChain` can be set to set the chain for all calls. Currently we support:
107
-
108
- - `ethereum` Ethereum Mainnet
109
- - `ethereumSepolia` Ethereum Sepolia
110
- - `polygon` Polygon Mainnet
111
-
112
- The `defaultChain` in the initializer can be overridden with the `chain` argument in functions.
113
-
114
- If no `defaultChain` is passed into the initializer or a `chain` argument to a function,`ethereum` is used by default.
115
-
116
- <br>
117
-
118
- ### Configuration Arguments
119
-
120
- | Property | Values | Required | Description | Example |
121
- | ------------ | ------ | -------- | ------------------------------------------------------------------- | -------- |
122
- | graphApiKey | string | ❌ | The QuickNode GraphQL API Key | abcd1234 |
123
- | defaultChain | string | ❌ | The default chain to use for all functions (defaults to `ethereum`) | polygon |
124
-
125
- <br>
126
-
127
- ### nfts.getByWallet
128
-
129
- Returns NFTs owned by a wallet
130
-
131
- | Argument | Values | Required | Description | Example |
132
- | -------- | ------ | -------- | --------------------------------------------------- | --------------------------------------------------- |
133
- | address | string | ✅ | Wallet address or ENS domain | quicknode.eth |
134
- | first | number | ❌ | Number of results to return | 10 |
135
- | before | string | ❌ | Return results before cursor | T2Zmc2V0Q29ubmVjdGlvbjow |
136
- | after | string | ❌ | Return results after cursor | T2Zmc2V0Q29ubmVjdGlvbjo2 |
137
- | chain | string | ❌ | Blockchain name | polygon |
138
- | filter | object | ❌ | An object with the optional filters for the request | { contractTokens: [{ contractAddress: "0x00..." }]} |
139
-
140
- `filter` Parameters
141
-
142
- | Argument | Values | Description | Example |
143
- | -------------- | ------ | --------------------------------------------------------------------- | ------------------------------------------------------------------- |
144
- | contractTokens | Array | An array of objects with NFT contract addresses and optional tokenIds | [{ contractAddress: "0x2106C00Ac7dA0A3430aE667879139E832307AeAa" }] |
145
-
146
- ```ts
147
- import QuickNode from '@quicknode/sdk';
148
-
149
- const qn = new QuickNode.API({
150
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
151
- });
152
-
153
- qn.nfts
154
- .getByWallet({
155
- address: '0x51ABa267A6e8e1E76B44183a73E881D73A102F26',
156
- first: 5,
157
- })
158
- .then((response) => console.log(response));
159
-
160
- // can pass in ENS domain
161
- qn.nfts
162
- .getByWallet({
163
- address: 'quicknode.eth',
164
- first: 5,
165
- })
166
- .then((response) => console.log(response));
167
- ```
168
-
169
- <br>
170
-
171
- ### nfts.getTrendingCollections
172
-
173
- Returns trending NFT Collections
174
-
175
- | Argument | Values | Required | Description | Example |
176
- | -------- | ------ | -------- | ---------------------------- | ------------------------ |
177
- | first | number | ❌ | Number of results to return | 10 |
178
- | before | string | ❌ | Return results before cursor | T2Zmc2V0Q29ubmVjdGlvbjow |
179
- | after | string | ❌ | Return results after cursor | T2Zmc2V0Q29ubmVjdGlvbjo2 |
180
- | chain | string | ❌ | Blockchain name | polygon |
181
-
182
- ```ts
183
- import QuickNode from '@quicknode/sdk';
184
-
185
- const qn = new QuickNode({
186
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
187
- });
188
-
189
- qn.nfts
190
- .getTrendingCollections({
191
- first: 5,
192
- })
193
- .then((response) => console.log(response));
194
- ```
195
-
196
- <br>
197
-
198
- ### nfts.getByContractAddress
199
-
200
- Returns NFTs by contract address. The response differs based on if they are an ERC721 or ERC1155 standard.
201
-
202
- | Argument | Values | Required | Description | Example |
203
- | --------------- | ------ | -------- | ---------------------------- | ------------------------------------------ |
204
- | contractAddress | string | ✅ | NFT contract address | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
205
- | first | number | ❌ | Number of results to return | 10 |
206
- | before | string | ❌ | Return results before cursor | T2Zmc2V0Q29ubmVjdGlvbjow |
207
- | after | string | ❌ | Return results after cursor | T2Zmc2V0Q29ubmVjdGlvbjo2 |
208
- | chain | string | ❌ | Blockchain name | polygon |
209
-
210
- ```ts
211
- import QuickNode from '@quicknode/sdk';
212
-
213
- const qn = new QuickNode.API({
214
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
215
- });
216
-
217
- qn.nfts
218
- .getByContractAddress({
219
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
220
- first: 5,
221
- })
222
- .then((response) => console.log(response));
223
- ```
224
-
225
- <br>
226
-
227
- ### nfts.getNFTDetails
228
-
229
- Returns the details for a specified NFT
230
-
231
- | Argument | Values | Required | Description | Example |
232
- | --------------- | ------ | -------- | -------------------- | ------------------------------------------ |
233
- | contractAddress | string | ✅ | NFT contract address | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
234
- | tokenId | string | ✅ | NFT Token ID | 1 |
235
- | chain | string | ❌ | Blockchain name | polygon |
236
-
237
- ```ts
238
- import QuickNode from '@quicknode/sdk';
239
-
240
- const qn = new QuickNode.API({
241
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
242
- });
243
-
244
- qn.nfts
245
- .getNFTDetails({
246
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
247
- tokenId: '1',
248
- })
249
- .then((response) => console.log(response));
250
- ```
251
-
252
- <br>
253
-
254
- ### nfts.getCollectionDetails
255
-
256
- Returns the details for an NFT Collection
257
-
258
- | Argument | Values | Required | Description | Example |
259
- | --------------- | ------ | -------- | -------------------- | ------------------------------------------ |
260
- | contractAddress | string | ✅ | NFT contract address | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
261
- | chain | string | ❌ | Blockchain name | polygon |
262
-
263
- ```ts
264
- import QuickNode from '@quicknode/sdk';
265
-
266
- const qn = new QuickNode.API({
267
- gqlApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
268
- });
269
-
270
- qn.nfts
271
- .getCollectionDetails({
272
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
273
- })
274
- .then((response) => console.log(response));
275
- ```
276
-
277
- <br>
278
-
279
- ### nfts.verifyOwnership
280
-
281
- Check if the wallet address is an owner of any of the provided NFT contract addresses. Returns a boolean if they own and NFT from _any_ of the provided contract addresses.
282
-
283
- | Argument | Values | Required | Description | Example |
284
- | -------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
285
- | address | string | ✅ | Address or ENS name of wallet to check as owner | 0x3C6aEFF92b4B35C2e1b196B57d0f8FFB56884A17 |
286
- | nfts | array | ✅ | an array of objects with `contractAddress` and optional `tokenId` to check ownership of. Ownership is verified if any of the parameters are owned by the wallet | [{ contractAddress: "0x2106C00Ac7dA0A3430aE667879139E832307AeAa" }] |
287
- | chain | string | ❌ | Blockchain name | polygon |
288
-
289
- ```typescript
290
- import QuickNode from '@quicknode/sdk';
291
-
292
- const qn = new QuickNode.API({
293
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
294
- });
295
-
296
- // returns true if wallet owns at least one NFT of 0x2106C00Ac7dA0A3430aE667879139E832307AeAa
297
- qn.nfts
298
- .verifyOwnership({
299
- address: '0xD10E24685c7CDD3cd3BaAA86b09C92Be28c834B6',
300
- nfts: [
301
- {
302
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
303
- },
304
- ],
305
- })
306
- .then((response) => console.log(response));
307
-
308
- // returns true if quicknode.eth owns the exact NFT id 123 from contract address 0x2106C00Ac7dA0A3430aE667879139E832307AeAa
309
- qn.nfts
310
- .verifyOwnership({
311
- address: 'quicknode.eth', // or wallet address
312
- nfts: [
313
- {
314
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
315
- tokenId: '123',
316
- },
317
- ],
318
- })
319
- .then((response) => console.log(response));
320
-
321
- // returns true if quicknode.eth owns an NFT from either 0x2106C00Ac7dA0A3430aE667879139E832307AeAa or 0x9D90669665607F08005CAe4A7098143f554c59EF
322
- qn.nfts
323
- .verifyOwnership({
324
- address: 'quicknode.eth', // or wallet address
325
- nfts: [
326
- {
327
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
328
- },
329
- {
330
- contractAddress: '0x9D90669665607F08005CAe4A7098143f554c59EF',
331
- },
332
- ],
333
- })
334
- .then((response) => console.log(response));
335
- ```
336
-
337
- <br>
338
-
339
- ### tokens.getBalancesByWallet
340
-
341
- Returns ERC20 token balances for a wallet
342
-
343
- | Argument | Values | Required | Description | Example |
344
- | -------- | ------ | -------- | ---------------------------- | ------------------------------------------ |
345
- | address | string | ✅ | Wallet address or ENS domain | 0x3C6aEFF92b4B35C2e1b196B57d0f8FFB56884A17 |
346
- | first | number | ❌ | Number of results to return | 10 |
347
- | before | string | ❌ | Return results before cursor | T2Zmc2V0Q29ubmVjdGlvbjow |
348
- | after | string | ❌ | Return results after cursor | T2Zmc2V0Q29ubmVjdGlvbjo2 |
349
- | chain | string | ❌ | Blockchain name | polygon |
350
-
351
- ```ts
352
- import QuickNode from '@quicknode/sdk';
353
-
354
- const qn = new QuickNode.API({
355
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
356
- });
357
-
358
- qn.tokens
359
- .getBalancesByWallet({
360
- address: '0xd10e24685c7cdd3cd3baaa86b09c92be28c834b6',
361
- first: 5,
362
- })
363
- .then((response) => console.log(response));
364
-
365
- // Can pass in ENS domain
366
- qn.tokens
367
- .getBalancesByWallet({
368
- address: 'quicknode.eth',
369
- first: 5,
370
- })
371
- .then((response) => console.log(response));
372
- ```
373
-
374
- <br>
375
-
376
- ### contracts.getDetails
377
-
378
- Get the details and ABI for a contract address
379
-
380
- | Argument | Values | Required | Description | Example |
381
- | --------------- | ------ | -------- | ---------------- | ------------------------------------------ |
382
- | contractAddress | string | ✅ | contract address | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
383
- | chain | string | ❌ | Blockchain name | polygon |
384
-
385
- ```ts
386
- import QuickNode, { gql } from '@quicknode/sdk';
387
-
388
- const qn = new QuickNode.API({
389
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
390
- });
391
-
392
- qn.contracts
393
- .getDetails({
394
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
395
- })
396
- .then((response) => console.log(response));
397
- ```
398
-
399
- <br>
400
-
401
- ### transactions.getByWallet
402
-
403
- Returns transactions for a wallet
404
-
405
- | Argument | Values | Required | Description | Example |
406
- | -------- | ------ | -------- | ---------------------------- | ------------------------------------------ |
407
- | address | string | ✅ | Wallet address or ENS domain | 0x3C6aEFF92b4B35C2e1b196B57d0f8FFB56884A17 |
408
- | first | number | ❌ | Number of results to return | 10 |
409
- | before | string | ❌ | Return results before cursor | T2Zmc2V0Q29ubmVjdGlvbjow |
410
- | after | string | ❌ | Return results after cursor | T2Zmc2V0Q29ubmVjdGlvbjo2 |
411
- | chain | string | ❌ | Blockchain name | polygon |
412
-
413
- ```ts
414
- import QuickNode from '@quicknode/sdk';
415
-
416
- const qn = new QuickNode.API({
417
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
418
- });
419
-
420
- qn.transactions
421
- .getByWallet({
422
- address: '0xd10e24685c7cdd3cd3baaa86b09c92be28c834b6',
423
- first: 5,
424
- })
425
- .then((response) => console.log(response));
426
-
427
- // Can pass in ENS domain
428
- qn.transactions
429
- .getByWallet({
430
- address: 'quicknode.eth',
431
- first: 5,
432
- })
433
- .then((response) => console.log(response));
434
- ```
435
-
436
- <br>
437
-
438
- ### transactions.getAll
439
-
440
- Returns transactions filtered by search parameters
441
-
442
- | Argument | Values | Required | Description | Example |
443
- | -------- | ------ | -------- | --------------------------------------------------- | ------------------------------- |
444
- | first | number | ❌ | Number of results to return | 10 |
445
- | before | string | ❌ | Return results before cursor | T2Zmc2V0Q29ubmVjdGlvbjow |
446
- | after | string | ❌ | Return results after cursor | T2Zmc2V0Q29ubmVjdGlvbjo2 |
447
- | chain | string | ❌ | Blockchain name | polygon |
448
- | filter | object | ✅ | An object with the optional filters for the request | { blockNumber: { eq: 123456 } } |
449
-
450
- `filter` Parameters
451
-
452
- | Argument | Values | Description | Example |
453
- | ----------- | ------ | ------------------------------------------------------------------------------------------------ | --------------------------------------------------------- |
454
- | fromAddress | string | Filter transactions sent from address | fromAddress: "0xD10E24685c7CDD3cd3BaAA86b09C92Be28c834B6" |
455
- | toAddress | string | Filter transactions sent to address | toAddress: "0xD10E24685c7CDD3cd3BaAA86b09C92Be28c834B6" |
456
- | blockNumber | object | An object with any combination of `eq`, `gt`, `gte`, `in`, `lt`, or `lte` | { lt: 17343891, gt: 17343881 } |
457
- | timestamp | object | An object with any combination of `eq`, `gt`, `gte`, `in`, `lt`, or `lte` with a valid timestamp | { lt: "2022-12-03T10:15:30Z" } |
458
-
459
- _timestamp can be a date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the date-time format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar._
460
-
461
- ```ts
462
- import QuickNode from '@quicknode/sdk';
463
-
464
- const qn = new QuickNode.API({
465
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
466
- });
467
-
468
- // Use the filters
469
- qn.transactions
470
- .getAll({
471
- filter: {
472
- blockNumber: {
473
- eq: 17372310,
474
- },
475
- fromAddress: '0x41407a3c41da7970d30a0343cda8b9db70c145fb',
476
- },
477
- })
478
- .then((response) => console.log(response));
479
-
480
- // Filters can be left blank to get the latest data
481
- qn.transactions.getAll({ filter: {}, first: 5 }).then((response) => console.log(response));
482
- ```
483
-
484
- <br>
485
-
486
- ### transactions.getByHash
487
-
488
- Returns transaction information by transaction hash
489
-
490
- | Argument | Values | Required | Description | Example |
491
- | -------- | ------ | -------- | ----------------------- | ------------------------------------------------------------------ |
492
- | hash | string | ✅ | Hash of the transaction | 0x1aa26d1d542b414dd2e2d1aa6f8d8e128e2a45bc4a04c24232207221914389bf |
493
-
494
- ```ts
495
- import QuickNode from '@quicknode/sdk';
496
-
497
- const qn = new QuickNode.API({
498
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
499
- });
500
-
501
- qn.transactions
502
- .getByHash({
503
- hash: '0x1aa26d1d542b414dd2e2d1aa6f8d8e128e2a45bc4a04c24232207221914389bf',
504
- })
505
- .then((response) => console.log(response));
506
- ```
507
-
508
- <br>
509
-
510
- ### events.getByContract
511
-
512
- Returns events by contract address
513
-
514
- | Argument | Values | Required | Description | Example |
515
- | -------- | ------ | -------- | --------------------------------------------------- | ------------------------------- |
516
- | first | number | ❌ | Number of results to return | 10 |
517
- | before | string | ❌ | Return results before cursor | T2Zmc2V0Q29ubmVjdGlvbjow |
518
- | after | string | ❌ | Return results after cursor | T2Zmc2V0Q29ubmVjdGlvbjo2 |
519
- | chain | string | ❌ | Blockchain name | polygon |
520
- | filter | object | ❌ | An object with the optional filters for the request | { blockNumber: { eq: 123456 } } |
521
-
522
- `filter` Parameters
523
-
524
- Please see the [Token Event Filters section](#token-event-filters) for all options
525
-
526
- ```typescript
527
- import QuickNode from '@quicknode/sdk';
528
-
529
- const qn = new QuickNode.API({
530
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
531
- });
532
-
533
- qn.events
534
- .getByContract({
535
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
536
- })
537
- .then((response) => console.log(response));
538
-
539
- // Using filters
540
- qn.events
541
- .getByContract({
542
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
543
- filter: {
544
- fromAddress: {
545
- eq: '0x10fa1c188eca954419a85112f975155f717ad8ea',
546
- },
547
- type: {
548
- in: ['TRANSFER'],
549
- },
550
- }
551
- })
552
- .then((response) => console.log(response));
553
- `
554
- ```
555
-
556
- <br>
557
-
558
- ### events.getByNFTCollection
559
-
560
- Returns the events for an NFT Collection
561
-
562
- | Argument | Values | Required | Description | Example |
563
- | --------------- | ------ | -------- | --------------------------------------------------- | ------------------------------------------ |
564
- | contractAddress | string | ✅ | NFT contract address | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
565
- | chain | string | ❌ | Blockchain name | polygon |
566
- | first | number | ❌ | Number of results to return | 10 |
567
- | before | string | ❌ | Return results before cursor | T2Zmc2V0Q29ubmVjdGlvbjow |
568
- | after | string | ❌ | Return results after cursor | T2Zmc2V0Q29ubmVjdGlvbjo2 |
569
- | filter | object | ❌ | An object with the optional filters for the request | { blockNumber: { eq: 123456 } } |
570
-
571
- `filter` Parameters
572
-
573
- Please see the [Token Event Filters section](#token-event-filters) for all options
574
-
575
- ```ts
576
- import QuickNode from '@quicknode/sdk';
577
-
578
- const qn = new QuickNode.API({
579
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
580
- });
581
-
582
- qn.events
583
- .getByNFTCollection({
584
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
585
- first: 5,
586
- })
587
- .then((response) => console.log(response));
588
-
589
- // Can pass in filters
590
- qn.events
591
- .getByNftCollection({
592
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
593
- first: 5,
594
- filter: {
595
- type: {
596
- eq: 'TRANSFER',
597
- },
598
- },
599
- })
600
- .then((response) => console.log(response));
601
- ```
602
-
603
- <br>
604
-
605
- ### events.getByNFT
606
-
607
- Returns the events for a specific NFT
608
-
609
- | Argument | Values | Required | Description | Example |
610
- | --------------- | ------ | -------- | --------------------------------------------------- | ------------------------------------------ |
611
- | contractAddress | string | ✅ | NFT contract address | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
612
- | tokenId | string | ✅ | NFT Token ID | 1 |
613
- | chain | string | ❌ | Blockchain name | polygon |
614
- | first | number | ❌ | Number of results to return | 10 |
615
- | before | string | ❌ | Return results before cursor | T2Zmc2V0Q29ubmVjdGlvbjow |
616
- | after | string | ❌ | Return results after cursor | T2Zmc2V0Q29ubmVjdGlvbjo2 |
617
- | filter | object | ❌ | An object with the optional filters for the request | { blockNumber: { eq: 123456 } } |
618
-
619
- `filter` Parameters
620
-
621
- Please see the [Token Event Filters section](#token-event-filters) for all options
622
-
623
- ```ts
624
- import QuickNode from '@quicknode/sdk';
625
-
626
- const qn = new QuickNode.API({
627
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
628
- });
629
-
630
- qn.events
631
- .getByNFT({
632
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
633
- tokenId: '1',
634
- })
635
- .then((response) => console.log(response));
636
-
637
- qn.events
638
- .getByNFT({
639
- contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
640
- tokenId: '1',
641
- filter: {
642
- type: {
643
- eq: 'TRANSFER',
644
- },
645
- },
646
- })
647
- .then((response) => console.log(response));
648
- ```
649
-
650
- <br>
651
-
652
- ### events.getAll
653
-
654
- Returns events filtered by search parameters
655
-
656
- | Argument | Values | Required | Description | Example |
657
- | -------- | ------ | -------- | --------------------------------------------------- | ------------------------------- |
658
- | chain | string | ❌ | Blockchain name | polygon |
659
- | first | number | ❌ | Number of results to return | 10 |
660
- | before | string | ❌ | Return results before cursor | T2Zmc2V0Q29ubmVjdGlvbjow |
661
- | after | string | ❌ | Return results after cursor | T2Zmc2V0Q29ubmVjdGlvbjo2 |
662
- | filter | object | ❌ | An object with the optional filters for the request | { blockNumber: { eq: 123456 } } |
663
-
664
- `filter` Parameters
665
-
666
- Please see the [Token Event Filters section](#token-event-filters) for all options
667
-
668
- ```ts
669
- import QuickNode from '@quicknode/sdk';
670
-
671
- const qn = new QuickNode.API({
672
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
673
- });
674
-
675
- // Use filters to get specific events
676
- qn.events
677
- .getAll({
678
- first: 2,
679
- filter: {
680
- blockNumber: {
681
- eq: 17414768,
682
- },
683
- toAddress: {
684
- eq: '0xef1c6e67703c7bd7107eed8303fbe6ec2554bf6b',
685
- },
686
- },
687
- })
688
- .then((response) => console.log(response));
689
-
690
- // Filters can be left blank to get the latest data
691
- qn.events.getAll({}).then((response) => console.log(response));
692
- ```
693
-
694
- <br>
695
-
696
- ### utils.getGasPrices
697
-
698
- Returns historical gas prices by block number. Defaults to returning values in wei.
699
-
700
- | Argument | Values | Required | Description | Example |
701
- | ------------ | ------- | -------- | --------------------------------------------------- | --------------------------------- |
702
- | chain | string | ❌ | Blockchain name | polygon |
703
- | returnInGwei | boolean | ❌ | Return gas values in Gwei | true |
704
- | filter | object | ❌ | An object with the optional filters for the request | { blockNumber: { eq: 17343891 } } |
705
-
706
- `filter` Parameters
707
-
708
- | Argument | Values | Description | Example |
709
- | ----------- | ------ | ------------------------------------------------------------------------- | ------------------------------ |
710
- | blockNumber | object | An object with any combination of `eq`, `gt`, `gte`, `in`, `lt`, or `lte` | { lt: 17343891, gt: 17343881 } |
711
-
712
- ```ts
713
- import QuickNode from '@quicknode/sdk';
714
-
715
- const qn = new QuickNode.API({
716
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
717
- });
718
-
719
- // Get the latest data
720
- qn.utils.getGasPrices({}).then((response) => console.log(response));
721
-
722
- // Get filtered data
723
- qn.utils
724
- .getGasPrices({
725
- filter: {
726
- blockNumber: {
727
- eq: 17343891,
728
- },
729
- },
730
- })
731
- .then((response) => console.log(response));
732
- ```
733
-
734
- <br>
735
-
736
- ### graphApiClient.query
737
-
738
- A way to send GraphQL queries directly to the [QuickNode GraphQL API](https://www.quicknode.com/graph-api). `graphApiClient` is an [Urql client](https://formidable.com/open-source/urql/docs/api/core/#client) instance configured to use QuickNode's Graph API. For more information about the query structure, see the [Graph API documentation](https://docs.quicknode.com/docs/graphql/getting-started/)
739
-
740
- ```ts
741
- import QuickNode, { gql } from '@quicknode/sdk';
742
-
743
- const qn = new QuickNode.API({
744
- graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
745
- });
746
-
747
- const query = gql`
748
- query ($contractAddress: String!) {
749
- ethereum {
750
- collection(contractAddress: $contractAddress) {
751
- address
752
- name
753
- symbol
754
- totalSupply
755
- }
756
- }
757
- }
758
- `;
759
- const variables = {
760
- contractAddress: '0x2106c00ac7da0a3430ae667879139e832307aeaa',
761
- };
762
-
763
- qn.graphApiClient.query({ query, variables }).then(({ data }) => console.log(data));
764
- ```
49
+ ## Documentation
765
50
 
766
- <br>
767
-
768
- ### Error handling
769
-
770
- The input to API functions is validated at runtime in order to handle both untyped JavaScript input and user input in end user applications. In short, this will help prevent you sending invalid Graph API queries because of bad input. The validation is done by [zod](https://www.npmjs.com/package/zod) under the hood and we expose the errors to you in a `QNInputValidationError` instance.
771
-
772
- For example, you can handle these errors:
773
-
774
- ```typescript
775
- import QuickNode from '@quicknode/sdk';
776
-
777
- const qn = new QuickNode.API({ graphApiKey: 'my-api-key' });
778
-
779
- // Inside async function
780
- try {
781
- const eventsByContract = await events.getByContract({
782
- contractAddress: userInput, // Input comes from the user, we don't know what will be here
783
- });
784
- return eventsByContract;
785
- } catch (error) {
786
- if (error instanceof QNInputValidationError) {
787
- console.error(error.stack);
788
- return { errors: error.issues }; // Return formatted issues to handle as needed by UI or user
789
- } else {
790
- // handle unexpected errors here
791
- }
792
- }
793
- ```
794
-
795
- The `QNInputValidationError` instance has the following properties:
796
-
797
- | Property | Type | Description |
798
- | -------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
799
- | messages | string[] | An array of concise error messages |
800
- | zodError | ZodError | The full `ZodError` instance, see [the Zod error handling docs](https://github.com/colinhacks/zod/blob/master/ERROR_HANDLING.md) for more information |
801
- | issues | ZodIssue[] | An array of [Zod Issue](https://github.com/colinhacks/zod/blob/master/ERROR_HANDLING.md#zodissue) instances, which is a formatted error data structure |
802
-
803
- <br>
804
-
805
- ## Filters
806
-
807
- Some filters are shared between queries
808
-
809
- <br>
810
-
811
- ### Token Event Filters
812
-
813
- | Argument | Values | Description | Example |
814
- | ---------------- | ------ | --------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
815
- | blockNumber | object | An object with any combination of `eq`, `gt`, `gte`, `in`, `lt`, or `lte` | { lt: 17343891, gt: 17343881 } |
816
- | contractAddress | object | A contract address with `eq`, `in`, or `notIn` | { eq: "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984" } |
817
- | contractStandard | object | A valid contract standard `ERC20`, `ERC721`, `ERC1155` with `eq`, `in`, or `notIn` | { eq: "ERC20" } |
818
- | fromAddress | object | Filter events sent from address with `eq`, `in`, or `notIn` | { eq: "0xD10E24685c7CDD3cd3BaAA86b09C92Be28c834B6" } |
819
- | marketplace | object | `BLUR`, `CRYPTOPUNKS`, `LOOKSRARE`, `NIFTY_GATEWAY`, `OPENSEA`, `SEAPORT`, `X2Y2`, `ZEROX` with with `eq`, `in`, or `notIn` | { eq: "OPENSEA" } |
820
- | timestamp | object | An object with any combination of `eq`, `gt`, `gte`, `in`, `lt`, or `lte` with a valid timestamp | { lt: "2022-12-03T10:15:30Z" } |
821
- | toAddress | object | Filter events sent to address with `eq`, `in`, or `notIn` | { eq: "0xD10E24685c7CDD3cd3BaAA86b09C92Be28c834B6" } |
822
- | transactionHash | object | A transaction hash with with `eq`, `in`, or `notIn` | { eq: "0xdd652cfd936f7a22ab217a69c1f4356a6d15a4c8d61e30d87a4cd8abca30046f" } |
823
- | type | object | `TRANSFER`, `MINT`, `SALE`, `SWAP`, or `BURN` with `eq`, `in`, or `notIn` | { in: ["TRANSFER", "MINT"] } |
824
- | walletAddress | object | A valid wallet address with `eq`, `in`, or `notIn` | { eq: "0xD10E24685c7CDD3cd3BaAA86b09C92Be28c834B6" } |
825
-
826
- _timestamp can be a date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the date-time format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar._
827
-
828
- <br>
829
-
830
- ## Pagination
831
-
832
- For functions that support pagination, use the `first` property to specify the amount of results to return.
833
-
834
- The returned `data.tokensPageInfo.endCursor` property in the response can be used to access subsequent results. This value can be passed in to the `after` property and will return the results after that `endCursor`.
835
-
836
- `hasNextPage` can be used to determine the end of the results, where it will be `false`.
837
-
838
- For example, if a response contains:
839
-
840
- ```json
841
- {
842
- "results": [...],
843
- "pageInfo": {
844
- "endCursor": "T2Zmc2V0Q29ubmVjdGlvbjox",
845
- "hasNextPage": true,
846
- "hasPreviousPage": false,
847
- "startCursor": "T2Zmc2V0Q29ubmVjdGlvbjow"
848
- }
849
- }
850
- ```
851
-
852
- calling the following will get the next page of results
853
-
854
- ```typescript
855
- qn.nfts.getByWallet({
856
- address: 'quicknode.eth',
857
- after: 'T2Zmc2V0Q29ubmVjdGlvbjox', // Using the endCursor
858
- });
859
- ```
860
-
861
- You can do the same with `before` and return the results before the specified cursor if `hasPreviousPage` is true
862
-
863
- For example, if the response contains the following:
864
-
865
- ```json
866
- {
867
- "results": [...],
868
- "pageInfo": {
869
- "endCursor": "T2Zmc2V0Q29ubmVjdGlvbjo2",
870
- "hasNextPage": true,
871
- "hasPreviousPage": true,
872
- "startCursor": "T2Zmc2V0Q29ubmVjdGlvbjoy"
873
- }
874
- }
875
- ```
876
-
877
- calling the following will get the previous page of results
878
-
879
- ```typescript
880
- qn.nfts.getByWallet({
881
- address: 'quicknode.eth',
882
- before: 'T2Zmc2V0Q29ubmVjdGlvbjoy', // Using the startCursor
883
- });
884
- ```
885
-
886
- <br>
51
+ Please see [the official QuickNode SDK documentation](https://www.quicknode.com/docs/quicknode-sdk/getting-started) for the full documentation of SDK functions.
887
52
 
888
53
  ## Contributing corner
889
54