@quicknode/sdk 0.5.2 → 1.0.0-beta.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,255 +1,724 @@
1
1
  # QuickNode SDK
2
2
 
3
- An SDK from [QuickNode](https://www.quicknode.com/) making it easy for developers to interact with the blockchain.
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
4
 
5
- Currently supports getting started with [Icy Tools GraphQL API](https://developers.icy.tools/) in a blink!
5
+ A SDK from [QuickNode](https://www.quicknode.com/) making it easy for developers to interact with QuickNode's services.
6
6
 
7
+ QuickNode's SDK is a JavaScript and TypeScript framework-agnostic library that supports both CommonJS and ES module systems.
8
+
9
+ Currently the SDK makes it even easier to use the [QuickNode Graph API](https://www.quicknode.com/graph-api) to query market insights, trading data, transactions by wallets and contracts, cached NFT images, and more!
10
+
11
+ > :grey_question: We want to hear from you! Please take a few minutes to fill out our [QuickNode SDK feedback form](https://forms.gle/vWFXDDjEUySjWUof6) and let us know what you currently think about the SDK. This helps us further improve the SDK.
12
+
13
+ [![Coverage Status](https://coveralls.io/repos/github/quiknode-labs/qn-oss/badge.svg?branch=main)](https://coveralls.io/github/quiknode-labs/qn-oss?branch=main)
7
14
  [![npm](https://img.shields.io/npm/dm/@quicknode/sdk)](https://www.npmjs.com/package/@quicknode/sdk)
8
15
  [![npm](https://img.shields.io/npm/v/@quicknode/sdk?color=g)](https://www.npmjs.com/package/@quicknode/sdk)
9
- ![Maintenance](https://img.shields.io/maintenance/yes/2022?color=g)
16
+ ![Maintenance](https://img.shields.io/maintenance/yes/2023?color=g)
10
17
  [![License](https://img.shields.io/npm/l/@quicknode/sdk?color=g)](https://github.com/quiknode-labs/qn-oss/blob/main/LICENSE.txt)
11
18
  [![GitHub issues](https://img.shields.io/github/issues-raw/quiknode-labs/qn-oss?color=g)](https://github.com/quiknode-labs/qn-oss/issues)
12
19
  [![Discord](https://img.shields.io/discord/880505845090250794?color=g)](https://discord.gg/DkdgEqE)
13
20
 
14
- ## Quick Start
21
+ <br>
22
+
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
+ - [Filters](#filters)
47
+ - [Token Event Filters](#token-event-filters)
48
+ - [Pagination](#pagination)
49
+ - [Contributing corner](#contributing-corner)
50
+ - [Issues](#issues)
51
+ - [Development](#development)
52
+ - [Running tests](#running-tests)
53
+ - [Running linting](#running-linting)
54
+ - [Generate graphql codegen typings](#generate-graphql-codegen-typings)
55
+
56
+ <br>
57
+
58
+ ## Getting Started
59
+
60
+ ### Installation
61
+
62
+ - Requires Node.js v16 or higher
63
+ - `npm install @quicknode/sdk` or `yarn add @quicknode/sdk`
64
+
65
+ <br>
66
+
67
+ ### Quickstart
15
68
 
16
69
  ```ts
17
- import { QuickNodeSDK } from '@quicknode/sdk';
70
+ import QuickNode from '@quicknode/sdk';
18
71
 
19
- const client = new QuickNodeSDK();
72
+ const qn = new QuickNode.API({ graphApiKey: 'my-api-key' });
20
73
 
21
- client.nft
22
- .getNFTsByWalletENS({
23
- ensName: 'vitalik.eth',
74
+ qn.nfts
75
+ .getByWallet({
76
+ address: 'quicknode.eth',
24
77
  first: 5,
25
78
  })
26
79
  .then((response) => console.log(response));
27
80
  ```
28
81
 
29
- Full example implementation [here](https://github.com/quiknode-labs/qn-oss/tree/main/packages/apps/examples/nft-sdk)
82
+ Full example app implementation [here](https://github.com/quiknode-labs/qn-oss/tree/main/packages/apps/examples/sdk-api)
30
83
 
31
- ## Providing a config object to the client
84
+ <br>
32
85
 
33
- > :warning: This client (and the underlying API) can be used without an icyApiKey, but its usage will be heavily rate limited, intended for trial and development purposes only.
86
+ ## API functions
87
+
88
+ These functions return data from the powerful [QuickNode Graph API](https://www.quicknode.com/graph-api), making it even easier to use.
89
+
90
+ <br>
91
+
92
+ ### Configuration
93
+
94
+ Sign up for a [QuickNode](https://www.quicknode.com/) account to use the multi-chain [QuickNode GraphQL API](https://www.quicknode.com/graph-api) API key in the SDK.
34
95
 
35
96
  ```ts
36
- import { QuickNodeSDK } from '@quicknode/sdk';
97
+ import QuickNode from '@quicknode/sdk';
37
98
 
38
- const client = new QuickNodeSDK({
39
- icyApiKey: 'my-api-key', // which is obtained by signing up on https://developers.icy.tools/
99
+ const qn = new QuickNode.API({
100
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
101
+ defaultChain: 'ethereum',
40
102
  });
41
103
  ```
42
104
 
43
- ### Client config API
105
+ A `defaultChain` can be set to set the chain for all calls. Currently we support:
106
+
107
+ - `ethereum` Ethereum Mainnet
108
+ - `ethereumSepolia` Ethereum Sepolia
109
+ - `polygon` Polygon Mainnet
110
+
111
+ The `defaultChain` in the initializer can be overridden with the `chain` argument in functions.
112
+
113
+ If no `defaultChain` is passed into the initializer or a `chain` argument to a function,`ethereum` is used by default.
114
+
115
+ <br>
116
+
117
+ ### Configuration Arguments
118
+
119
+ | Property | Values | Required | Description | Example |
120
+ | ------------ | ------ | -------- | ------------------------------------------------------------------- | -------- |
121
+ | graphApiKey | string | ❌ | The QuickNode GraphQL API Key | abcd1234 |
122
+ | defaultChain | string | ❌ | The default chain to use for all functions (defaults to `ethereum`) | polygon |
123
+
124
+ <br>
125
+
126
+ ### nfts.getByWallet
127
+
128
+ Returns NFTs owned by a wallet
129
+
130
+ | Argument | Values | Required | Description | Example |
131
+ | -------- | ------ | -------- | --------------------------------------------------- | ---------------------------------- |
132
+ | address | string | ✅ | Wallet address or ENS domain | quicknode.eth |
133
+ | first | number | ❌ | Number of results to return | 10 |
134
+ | after | string | ❌ | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
135
+ | chain | string | ❌ | Blockchain name | polygon |
136
+ | filter | object | ❌ | An object with the optional filters for the request | { contractAddressIn: ["0x00..."] } |
137
+
138
+ `filter` Parameters
139
+
140
+ | Argument | Values | Description | Example |
141
+ | ----------------- | ------ | ---------------------------------- | ---------------------------------------------- |
142
+ | contractAddressIn | Array | An array of NFT contract addresses | ["0x2106C00Ac7dA0A3430aE667879139E832307AeAa"] |
143
+
144
+ ```ts
145
+ import QuickNode from '@quicknode/sdk';
44
146
 
45
- | Property | Values | Example |
46
- | --------- | ------ | ---------------------------------- |
47
- | icyApiKey | string | 1c1t00ls-4p10-k3y0-lu21-43405e3310 |
147
+ const qn = new QuickNode.API({
148
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
149
+ });
150
+
151
+ qn.nfts
152
+ .getByWallet({
153
+ address: '0x51ABa267A6e8e1E76B44183a73E881D73A102F26',
154
+ first: 5,
155
+ })
156
+ .then((response) => console.log(response));
157
+
158
+ // can pass in ENS domain
159
+ qn.nfts
160
+ .getByWallet({
161
+ address: 'quicknode.eth',
162
+ first: 5,
163
+ })
164
+ .then((response) => console.log(response));
165
+ ```
48
166
 
49
167
  <br>
50
168
 
51
- ## Methods
169
+ ### nfts.getTrendingCollections
52
170
 
53
- ### nft.getNFTsByWalletENS
171
+ Returns trending NFT Collections
54
172
 
55
- | Argument | Values | Optional | Description | Example |
173
+ | Argument | Values | Required | Description | Example |
56
174
  | -------- | ------ | -------- | ------------------------------- | --------------------------- |
57
- | ensName | string | ❌ | Wallet ENS address | vitalik.eth |
58
- | first | number | | Number of results to return | 10 |
59
- | after | string | | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
175
+ | first | number | ❌ | Number of results to return | 10 |
176
+ | after | string | | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
177
+ | chain | string | | Blockchain name | polygon |
178
+
179
+ ```ts
180
+ import QuickNode from '@quicknode/sdk';
181
+
182
+ const qn = new QuickNode({
183
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
184
+ });
185
+
186
+ qn.nfts
187
+ .getTrendingCollections({
188
+ first: 5,
189
+ })
190
+ .then((response) => console.log(response));
191
+ ```
192
+
193
+ <br>
194
+
195
+ ### nfts.getByContractAddress
196
+
197
+ Returns NFTs by contract address. The response differs based on if they are an ERC721 or ERC1155 standard.
198
+
199
+ | Argument | Values | Required | Description | Example |
200
+ | --------------- | ------ | -------- | ------------------------------- | ------------------------------------------ |
201
+ | contractAddress | string | ✅ | NFT contract address | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
202
+ | first | number | ❌ | Number of results to return | 10 |
203
+ | after | string | ❌ | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
204
+ | chain | string | ❌ | Blockchain name | polygon |
60
205
 
61
206
  ```ts
62
- import { QuickNodeSDK } from '@quicknode/sdk';
207
+ import QuickNode from '@quicknode/sdk';
63
208
 
64
- const client = new QuickNodeSDK();
209
+ const qn = new QuickNode.API({
210
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
211
+ });
65
212
 
66
- client.nft
67
- .getNFTsByWalletENS({
68
- ensName: 'vitalik.eth',
213
+ qn.nfts
214
+ .getByContractAddress({
215
+ contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
69
216
  first: 5,
70
217
  })
71
218
  .then((response) => console.log(response));
72
219
  ```
73
220
 
74
- ### nft.getNFTsByWalletAddress
221
+ <br>
222
+
223
+ ### nfts.getNFTDetails
224
+
225
+ Returns the details for a specified NFT
226
+
227
+ | Argument | Values | Required | Description | Example |
228
+ | --------------- | ------ | -------- | -------------------- | ------------------------------------------ |
229
+ | contractAddress | string | ✅ | NFT contract address | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
230
+ | tokenId | string | ✅ | NFT Token ID | 1 |
231
+ | chain | string | ❌ | Blockchain name | polygon |
232
+
233
+ ```ts
234
+ import QuickNode from '@quicknode/sdk';
235
+
236
+ const qn = new QuickNode.API({
237
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
238
+ });
239
+
240
+ qn.nfts
241
+ .getNFTDetails({
242
+ contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
243
+ tokenId: '1',
244
+ })
245
+ .then((response) => console.log(response));
246
+ ```
247
+
248
+ <br>
249
+
250
+ ### nfts.getCollectionDetails
251
+
252
+ Returns the details for an NFT Collection
253
+
254
+ | Argument | Values | Required | Description | Example |
255
+ | --------------- | ------ | -------- | -------------------- | ------------------------------------------ |
256
+ | contractAddress | string | ✅ | NFT contract address | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
257
+ | chain | string | ❌ | Blockchain name | polygon |
258
+
259
+ ```ts
260
+ import QuickNode from '@quicknode/sdk';
261
+
262
+ const qn = new QuickNode.API({
263
+ gqlApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
264
+ });
265
+
266
+ qn.nfts
267
+ .getCollectionDetails({
268
+ contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
269
+ })
270
+ .then((response) => console.log(response));
271
+ ```
272
+
273
+ <br>
274
+
275
+ ### tokens.getBalancesByWallet
75
276
 
76
- | Argument | Values | Optional | Description | Example |
277
+ Returns ERC20 token balances for a wallet
278
+
279
+ | Argument | Values | Required | Description | Example |
77
280
  | -------- | ------ | -------- | ------------------------------- | ------------------------------------------ |
78
- | address | string | | Wallet address | 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 |
79
- | first | number | | Number of results to return | 10 |
80
- | after | string | | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
281
+ | address | string | | Wallet address or ENS domain | 0x3C6aEFF92b4B35C2e1b196B57d0f8FFB56884A17 |
282
+ | first | number | | Number of results to return | 10 |
283
+ | after | string | | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
284
+ | chain | string | ❌ | Blockchain name | polygon |
81
285
 
82
286
  ```ts
83
- import { QuickNodeSDK } from '@quicknode/sdk';
287
+ import QuickNode from '@quicknode/sdk';
84
288
 
85
- const client = new QuickNodeSDK();
289
+ const qn = new QuickNode.API({
290
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
291
+ });
86
292
 
87
- client.nft
88
- .getNFTsByWalletAddress({
89
- address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
293
+ qn.tokens
294
+ .getBalancesByWallet({
295
+ address: '0xd10e24685c7cdd3cd3baaa86b09c92be28c834b6',
90
296
  first: 5,
91
297
  })
92
298
  .then((response) => console.log(response));
299
+
300
+ // Can pass in ENS domain
301
+ qn.tokens
302
+ .getBalancesByWallet({
303
+ address: 'quicknode.eth',
304
+ first: 5,
305
+ })
306
+ .then((response) => console.log(response));
307
+ ```
308
+
309
+ <br>
310
+
311
+ ### contracts.getDetails
312
+
313
+ Get the details and ABI for a contract address
314
+
315
+ | Argument | Values | Required | Description | Example |
316
+ | --------------- | ------ | -------- | ---------------- | ------------------------------------------ |
317
+ | contractAddress | string | ✅ | contract address | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
318
+ | chain | string | ❌ | Blockchain name | polygon |
319
+
320
+ ```ts
321
+ import QuickNode, { gql } from '@quicknode/sdk';
322
+
323
+ const qn = new QuickNode.API({
324
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
325
+ });
326
+
327
+ qn.contracts
328
+ .getDetails({
329
+ contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
330
+ })
331
+ .then((response) => console.log(response));
93
332
  ```
94
333
 
95
- ### nft.getNFTsByContractAddress
334
+ <br>
335
+
336
+ ### transactions.getByWallet
337
+
338
+ Returns transactions for a wallet
96
339
 
97
- | Argument | Values | Optional | Description | Example |
340
+ | Argument | Values | Required | Description | Example |
98
341
  | -------- | ------ | -------- | ------------------------------- | ------------------------------------------ |
99
- | address | string | | Contract address of NFT | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
100
- | first | number | | Number of results to return | 10 |
101
- | after | string | | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
342
+ | address | string | | Wallet address or ENS domain | 0x3C6aEFF92b4B35C2e1b196B57d0f8FFB56884A17 |
343
+ | first | number | | Number of results to return | 10 |
344
+ | after | string | | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
345
+ | chain | string | ❌ | Blockchain name | polygon |
102
346
 
103
347
  ```ts
104
- import { QuickNodeSDK } from '@quicknode/sdk';
348
+ import QuickNode from '@quicknode/sdk';
105
349
 
106
- const client = new QuickNodeSDK();
350
+ const qn = new QuickNode.API({
351
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
352
+ });
353
+
354
+ qn.transactions
355
+ .getByWallet({
356
+ address: '0xd10e24685c7cdd3cd3baaa86b09c92be28c834b6',
357
+ first: 5,
358
+ })
359
+ .then((response) => console.log(response));
107
360
 
108
- client.nft
109
- .getNFTsByContractAddress({
110
- address: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
361
+ // Can pass in ENS domain
362
+ qn.transactions
363
+ .getByWallet({
364
+ address: 'quicknode.eth',
111
365
  first: 5,
112
366
  })
113
367
  .then((response) => console.log(response));
114
368
  ```
115
369
 
116
- ### nft.getCollectionDetails
370
+ <br>
371
+
372
+ ### transactions.getAll
373
+
374
+ Returns transactions filtered by search parameters
375
+
376
+ | Argument | Values | Required | Description | Example |
377
+ | -------- | ------ | -------- | --------------------------------------------------- | ------------------------------- |
378
+ | first | number | ❌ | Number of results to return | 10 |
379
+ | after | string | ❌ | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
380
+ | chain | string | ❌ | Blockchain name | polygon |
381
+ | filter | object | ✅ | An object with the optional filters for the request | { blockNumber: { eq: 123456 } } |
382
+
383
+ `filter` Parameters
117
384
 
118
- | Argument | Values | Optional | Description | Example |
119
- | -------- | ------ | -------- | ----------------------- | ------------------------------------------ |
120
- | address | string | ❌ | Contract address of NFT | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
385
+ | Argument | Values | Description | Example |
386
+ | ----------- | ------ | ------------------------------------------------------------------------------------------------ | --------------------------------------------------------- |
387
+ | fromAddress | string | Filter transactions sent from address | fromAddress: "0xD10E24685c7CDD3cd3BaAA86b09C92Be28c834B6" |
388
+ | toAddress | string | Filter transactions sent to address | toAddress: "0xD10E24685c7CDD3cd3BaAA86b09C92Be28c834B6" |
389
+ | blockNumber | object | An object with any combination of `eq`, `gt`, `gte`, `in`, `lt`, or `lte` | { lt: 17343891, gt: 17343881 } |
390
+ | 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" } |
391
+
392
+ _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._
121
393
 
122
394
  ```ts
123
- import { QuickNodeSDK } from '@quicknode/sdk';
395
+ import QuickNode from '@quicknode/sdk';
124
396
 
125
- const client = new QuickNodeSDK();
397
+ const qn = new QuickNode.API({
398
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
399
+ });
126
400
 
127
- client.nft
128
- .getCollectionDetails({
129
- address: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
401
+ // Use the filters
402
+ qn.transactions
403
+ .getAll({
404
+ filter: {
405
+ blockNumber: {
406
+ eq: 17372310,
407
+ },
408
+ fromAddress: '0x41407a3c41da7970d30a0343cda8b9db70c145fb',
409
+ },
130
410
  })
131
411
  .then((response) => console.log(response));
412
+
413
+ // Filters can be left blank to get the latest data
414
+ qn.transactions.getAll({ filter: {}, first: 5 }).then((response) => console.log(response));
132
415
  ```
133
416
 
134
- ### nft.getNFTEventLogs
417
+ <br>
418
+
419
+ ### transactions.getByHash
420
+
421
+ Returns transaction information by transaction hash
135
422
 
136
- | Argument | Values | Optional | Description | Example |
137
- | -------- | ------ | -------- | --------------------------------------------------------------------------------- | ------------------------------------------ |
138
- | address | string | | Contract address of NFT | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
139
- | tokenId | string | ❌ | NFT ID | 100 |
140
- | types | array | ✅ | An array of event types 'TRANSFER', 'ORDER', and/or 'MINT'. Defaults to all types | ['TRANSFER', 'ORDER', 'MINT] |
141
- | first | number | ✅ | Number of results to return | 10 |
142
- | after | string | ✅ | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
423
+ | Argument | Values | Required | Description | Example |
424
+ | -------- | ------ | -------- | ----------------------- | ------------------------------------------------------------------ |
425
+ | hash | string | | Hash of the transaction | 0x1aa26d1d542b414dd2e2d1aa6f8d8e128e2a45bc4a04c24232207221914389bf |
143
426
 
144
427
  ```ts
145
- import { QuickNodeSDK } from '@quicknode/sdk';
428
+ import QuickNode from '@quicknode/sdk';
429
+
430
+ const qn = new QuickNode.API({
431
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
432
+ });
433
+
434
+ qn.transactions
435
+ .getByHash({
436
+ hash: '0x1aa26d1d542b414dd2e2d1aa6f8d8e128e2a45bc4a04c24232207221914389bf',
437
+ })
438
+ .then((response) => console.log(response));
439
+ ```
146
440
 
147
- const client = new QuickNodeSDK();
441
+ <br>
442
+
443
+ ### events.getByContract
444
+
445
+ Returns events by contract address
446
+
447
+ | Argument | Values | Required | Description | Example |
448
+ | -------- | ------ | -------- | --------------------------------------------------- | ------------------------------- |
449
+ | first | number | ❌ | Number of results to return | 10 |
450
+ | after | string | ❌ | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
451
+ | chain | string | ❌ | Blockchain name | polygon |
452
+ | filter | object | ❌ | An object with the optional filters for the request | { blockNumber: { eq: 123456 } } |
453
+
454
+ `filter` Parameters
455
+
456
+ Please see the [Token Event Filters section](#token-event-filters) for all options
457
+
458
+ ```typescript
459
+ import QuickNode from '@quicknode/sdk';
460
+
461
+ const qn = new QuickNode.API({
462
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
463
+ });
148
464
 
149
- client.nft
150
- .getNFTEventLogs({
151
- address: '0x60E4d786628Fea6478F785A6d7e704777c86a7c6',
152
- tokenId: '100',
153
- types: ['TRANSFER', 'ORDER'],
465
+ qn.events
466
+ .getByContract({
467
+ contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
154
468
  })
155
469
  .then((response) => console.log(response));
470
+
471
+ // Using filters
472
+ qn.events
473
+ .getByContract({
474
+ contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
475
+ filter: {
476
+ fromAddress: {
477
+ eq: '0x10fa1c188eca954419a85112f975155f717ad8ea',
478
+ },
479
+ type: {
480
+ in: ['TRANSFER'],
481
+ },
482
+ }
483
+ })
484
+ .then((response) => console.log(response));
485
+ `
156
486
  ```
157
487
 
158
- ### nft.getNFTDetails
488
+ <br>
159
489
 
160
- Returns the details for a single NFT
161
- | Argument | Values | Optional | Description | Example |
162
- | --------------- | ------ | -------- | --------------------------------- | ------------------------------------------ |
163
- | contractAddress | string | ❌ | Contract address of NFT Collection | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
164
- | tokenId | string | | NFT ID | 5020 |
490
+ ### events.getByNFTCollection
491
+
492
+ Returns the events for an NFT Collection
493
+
494
+ | Argument | Values | Required | Description | Example |
495
+ | --------------- | ------ | -------- | --------------------------------------------------- | ------------------------------------------ |
496
+ | contractAddress | string | ✅ | NFT contract address | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
497
+ | chain | string | ❌ | Blockchain name | polygon |
498
+ | first | number | ❌ | Number of results to return | 10 |
499
+ | after | string | ❌ | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
500
+ | filter | object | ❌ | An object with the optional filters for the request | { blockNumber: { eq: 123456 } } |
501
+
502
+ `filter` Parameters
503
+
504
+ Please see the [Token Event Filters section](#token-event-filters) for all options
165
505
 
166
506
  ```ts
167
- import { QuickNodeSDK } from '@quicknode/sdk';
507
+ import QuickNode from '@quicknode/sdk';
168
508
 
169
- const client = new QuickNodeSDK();
509
+ const qn = new QuickNode.API({
510
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
511
+ });
170
512
 
171
- client.nft
172
- .getNFTDetails({
173
- contractAddress: '0x23581767a106ae21c074b2276D25e5C3e136a68b',
174
- tokenId: '400',
513
+ qn.events
514
+ .getByNFTCollection({
515
+ contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
516
+ first: 5,
517
+ })
518
+ .then((response) => console.log(response));
519
+
520
+ // Can pass in filters
521
+ qn.events
522
+ .getByNftCollection({
523
+ contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
524
+ first: 5,
525
+ filter: {
526
+ type: {
527
+ eq: 'TRANSFER',
528
+ },
529
+ },
175
530
  })
176
531
  .then((response) => console.log(response));
177
532
  ```
178
533
 
179
- ### nft.getContractEventLogs
534
+ <br>
535
+
536
+ ### events.getByNFT
180
537
 
181
- Returns the log events for a NFT contract
538
+ Returns the events for a specific NFT
182
539
 
183
- | Argument | Values | Optional | Description | Example |
184
- | -------- | ------ | -------- | --------------------------------------------------------------------------------- | ------------------------------------------ |
185
- | address | string | | Contract address of NFT | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
186
- | types | array | ✅ | An array of event types 'TRANSFER', 'ORDER', and/or 'MINT'. Defaults to all types | ['TRANSFER', 'ORDER', 'MINT] |
187
- | first | number | | Number of results to return | 10 |
188
- | after | string | | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
540
+ | Argument | Values | Required | Description | Example |
541
+ | --------------- | ------ | -------- | --------------------------------------------------- | ------------------------------------------ |
542
+ | contractAddress | string | | NFT contract address | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
543
+ | tokenId | string | ✅ | NFT Token ID | 1 |
544
+ | chain | string | | Blockchain name | polygon |
545
+ | first | number | | Number of results to return | 10 |
546
+ | after | string | ❌ | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
547
+ | filter | object | ❌ | An object with the optional filters for the request | { blockNumber: { eq: 123456 } } |
548
+
549
+ `filter` Parameters
550
+
551
+ Please see the [Token Event Filters section](#token-event-filters) for all options
189
552
 
190
553
  ```ts
191
- import { QuickNodeSDK } from '@quicknode/sdk';
554
+ import QuickNode from '@quicknode/sdk';
192
555
 
193
- const client = new QuickNodeSDK();
556
+ const qn = new QuickNode.API({
557
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
558
+ });
194
559
 
195
- client.nft
196
- .getContractEventLogs({
197
- address: '0x60E4d786628Fea6478F785A6d7e704777c86a7c6',
198
- types: ['TRANSFER', 'ORDER'],
560
+ qn.events
561
+ .getByNFT({
562
+ contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
563
+ tokenId: '1',
564
+ })
565
+ .then((response) => console.log(response));
566
+
567
+ qn.events
568
+ .getByNFT({
569
+ contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
570
+ tokenId: '1',
571
+ filter: {
572
+ type: {
573
+ eq: 'TRANSFER',
574
+ },
575
+ },
199
576
  })
200
577
  .then((response) => console.log(response));
201
578
  ```
202
579
 
203
- ### nft.getNFTsByWalletAndContracts
580
+ <br>
581
+
582
+ ### events.getAll
583
+
584
+ Returns events filtered by search parameters
204
585
 
205
- Gets NFTs from specified collections held by a wallet
586
+ | Argument | Values | Required | Description | Example |
587
+ | -------- | ------ | -------- | --------------------------------------------------- | ------------------------------- |
588
+ | chain | string | ❌ | Blockchain name | polygon |
589
+ | first | number | ❌ | Number of results to return | 10 |
590
+ | after | string | ❌ | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
591
+ | filter | object | ❌ | An object with the optional filters for the request | { blockNumber: { eq: 123456 } } |
206
592
 
207
- | Argument | Values | Optional | Description | Example |
208
- | --------- | ---------------- | -------- | ------------------------------- | ---------------------------------------------- |
209
- | address | string | ❌ | Wallet address | 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 |
210
- | contracts | array of strings | ❌ | NFT contract addresses | ['0xba30e5f9bb24caa003e9f2f0497ad287fdf95623'] |
211
- | first | number | ✅ | Number of results to return | 10 |
212
- | after | string | ✅ | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
593
+ `filter` Parameters
594
+
595
+ Please see the [Token Event Filters section](#token-event-filters) for all options
213
596
 
214
597
  ```ts
215
- import { QuickNodeSDK } from '@quicknode/sdk';
598
+ import QuickNode from '@quicknode/sdk';
216
599
 
217
- const client = new QuickNodeSDK();
600
+ const qn = new QuickNode.API({
601
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
602
+ });
218
603
 
219
- client.nft
220
- .getNFTsByWalletAndContracts({
221
- address: '0x13928eb9a86c8278a45b6ff2935c7730b58ac675',
222
- contracts: [
223
- '0xba30e5f9bb24caa003e9f2f0497ad287fdf95623',
224
- '0xbce3781ae7ca1a5e050bd9c4c77369867ebc307e',
225
- ],
604
+ // Use filters to get specific events
605
+ qn.events
606
+ .getAll({
607
+ first: 2,
608
+ filter: {
609
+ blockNumber: {
610
+ eq: 17414768,
611
+ },
612
+ toAddress: {
613
+ eq: '0xef1c6e67703c7bd7107eed8303fbe6ec2554bf6b',
614
+ },
615
+ },
226
616
  })
227
617
  .then((response) => console.log(response));
618
+
619
+ // Filters can be left blank to get the latest data
620
+ qn.events.getAll({}).then((response) => console.log(response));
228
621
  ```
229
622
 
230
- ### nft.getTrendingNFTCollections
623
+ <br>
624
+
625
+ ### utils.getGasPrices
231
626
 
232
- | Argument | Values | Optional | Description | Example |
233
- | -------------- | --------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
234
- | first | number | | Number of results to return | 10 |
235
- | after | string | | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
236
- | orderBy | TrendingCollectionsOrderByEnum | | Sort contracts by average sale price ('AVERAGE'), number of sales ('SALES') or volume ('VOLUME') | 'AVERAGE' |
237
- | orderDirection | OrderDirectionEnum | | Sort results ascending ('ASC') or descending ('DESC') | 'ASC' |
238
- | timePeriod | TrendingCollectionsTimePeriodEnum | | Get results from last hour ('ONE_HOUR'), last 12 hours ('TWELVE_HOURS') results, last day ('ONE_DAY') or last 7 days ('SEVEN_DAYS') | 'ONE_HOUR' |
239
- | timeRange | DateInputType | ✅ | Define the modifier in which `timePeriod` will take action to. It can be equal to ('eq'), greater than ('gt'), greater than or equal to ('gte'), less than ('lt') or less than or equal to ('lte') | 'gt' |
627
+ Returns historical gas prices by block number. Defaults to returning values in wei.
628
+
629
+ | Argument | Values | Required | Description | Example |
630
+ | ------------ | ------- | -------- | --------------------------------------------------- | --------------------------------- |
631
+ | chain | string | | Blockchain name | polygon |
632
+ | returnInGwei | boolean | | Return gas values in Gwei | true |
633
+ | filter | object | | An object with the optional filters for the request | { blockNumber: { eq: 17343891 } } |
634
+
635
+ `filter` Parameters
636
+
637
+ | Argument | Values | Description | Example |
638
+ | ----------- | ------ | ------------------------------------------------------------------------- | ------------------------------ |
639
+ | blockNumber | object | An object with any combination of `eq`, `gt`, `gte`, `in`, `lt`, or `lte` | { lt: 17343891, gt: 17343881 } |
240
640
 
241
641
  ```ts
242
- import { QuickNodeSDK } from '@quicknode/sdk';
642
+ import QuickNode from '@quicknode/sdk';
243
643
 
244
- const client = new QuickNodeSDK();
644
+ const qn = new QuickNode.API({
645
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
646
+ });
245
647
 
246
- client.nft
247
- .getTrendingNFTCollections({
248
- first: 10,
648
+ // Get the latest data
649
+ qn.utils.getGasPrices({}).then((response) => console.log(response));
650
+
651
+ // Get filtered data
652
+ qn.utils
653
+ .getGasPrices({
654
+ filter: {
655
+ blockNumber: {
656
+ eq: 17343891,
657
+ },
658
+ },
249
659
  })
250
660
  .then((response) => console.log(response));
251
661
  ```
252
662
 
663
+ <br>
664
+
665
+ ### graphApiClient.query
666
+
667
+ 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/)
668
+
669
+ ```ts
670
+ import QuickNode, { gql } from '@quicknode/sdk';
671
+
672
+ const qn = new QuickNode.API({
673
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
674
+ });
675
+
676
+ const query = gql`
677
+ query ($contractAddress: String!) {
678
+ ethereum {
679
+ collection(contractAddress: $contractAddress) {
680
+ address
681
+ name
682
+ symbol
683
+ totalSupply
684
+ }
685
+ }
686
+ }
687
+ `;
688
+ const variables = {
689
+ contractAddress: '0x2106c00ac7da0a3430ae667879139e832307aeaa',
690
+ };
691
+
692
+ qn.graphApiClient.query({ query, variables }).then(({ data }) => console.log(data));
693
+ ```
694
+
695
+ <br>
696
+
697
+ ## Filters
698
+
699
+ Some filters are shared between queries
700
+
701
+ <br>
702
+
703
+ ### Token Event Filters
704
+
705
+ | Argument | Values | Description | Example |
706
+ | ---------------- | ------ | --------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
707
+ | blockNumber | object | An object with any combination of `eq`, `gt`, `gte`, `in`, `lt`, or `lte` | { lt: 17343891, gt: 17343881 } |
708
+ | contractAddress | object | A contract address with `eq`, `in`, or `notIn` | { eq: "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984" } |
709
+ | contractStandard | object | A valid contract standard `ERC20`, `ERC721`, `ERC1155` with `eq`, `in`, or `notIn` | { eq: "ERC20" } |
710
+ | fromAddress | object | Filter events sent from address with `eq`, `in`, or `notIn` | { eq: "0xD10E24685c7CDD3cd3BaAA86b09C92Be28c834B6" } |
711
+ | marketplace | object | `BLUR`, `CRYPTOPUNKS`, `LOOKSRARE`, `NIFTY_GATEWAY`, `OPENSEA`, `SEAPORT`, `X2Y2`, `ZEROX` with with `eq`, `in`, or `notIn` | { eq: "OPENSEA" } |
712
+ | 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" } |
713
+ | toAddress | object | Filter events sent to address with `eq`, `in`, or `notIn` | { eq: "0xD10E24685c7CDD3cd3BaAA86b09C92Be28c834B6" } |
714
+ | transactionHash | object | A transaction hash with with `eq`, `in`, or `notIn` | { eq: "0xdd652cfd936f7a22ab217a69c1f4356a6d15a4c8d61e30d87a4cd8abca30046f" } |
715
+ | type | object | `TRANSFER`, `MINT`, `SALE`, `SWAP`, or `BURN` with `eq`, `in`, or `notIn` | { in: ["TRANSFER", "MINT"] } |
716
+ | walletAddress | object | A valid wallet address with `eq`, `in`, or `notIn` | { eq: "0xD10E24685c7CDD3cd3BaAA86b09C92Be28c834B6" } |
717
+
718
+ _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._
719
+
720
+ <br>
721
+
253
722
  ## Pagination
254
723
 
255
724
  For functions that support pagination, use the `first` property to specify the amount of results to return.
@@ -261,10 +730,13 @@ The returned `data.tokensPageInfo.endCursor` property in the response can be use
261
730
  For example, if a response contains:
262
731
 
263
732
  ```json
264
- "data": {
265
- "tokensPageInfo": {
733
+ {
734
+ "results": [],
735
+ "pageInfo": {
736
+ "endCursor": "T2Zmc2V0Q29ubmVjdGlvbjox",
266
737
  "hasNextPage": true,
267
- "endCursor": 'YXJyYXljb25uZWN0aW9uOlk='
738
+ "hasPreviousPage": false,
739
+ "startCursor": "T2Zmc2V0Q29ubmVjdGlvbjow"
268
740
  }
269
741
  }
270
742
  ```
@@ -272,31 +744,53 @@ For example, if a response contains:
272
744
  calling the following will get the next page of results
273
745
 
274
746
  ```typescript
275
- client.nft.getNFTsByWalletENS({
276
- ensName: 'vitalik.eth',
747
+ qn.nfts.getByWallet({
748
+ address: 'quicknode.eth',
277
749
  first: 5,
278
- after: 'YXJyYXljb25uZWN0aW9uOlk=', // from data.tokensPageInfo.endCursor in response
750
+ after: 'T2Zmc2V0Q29ubmVjdGlvbjox',
279
751
  });
280
752
  ```
281
753
 
282
- # Contributing corner
754
+ <br>
755
+
756
+ ## Contributing corner
283
757
 
284
- ## Issues
758
+ ### Issues
285
759
 
286
- Please submit any questions, issues, or feedback as an [issue in Github](https://github.com/quiknode-labs/qn-oss/issues).
760
+ Please submit any issues or feature requests as an [issue in Github](https://github.com/quiknode-labs/qn-oss/issues).
761
+
762
+ <br>
287
763
 
288
- ## Building
764
+ ### Development
289
765
 
290
- Run `nx build libs-api-sdk` to build the library.
766
+ We recommend using the example application to develop
767
+
768
+ 1. In `qn-oss` monorepo root directory, run `yarn install`
769
+ 1. cd `packages/apps/examples/sdk-api` from `qn-oss` monorepo root
770
+ 1. `cp .env.example .env` and add api key
771
+ 1. `nx serve apps-examples-sdk-api`
772
+ 1. Then you can send requests to the API, for example: `curl http://localhost:3333/api/nftsByAddress/0xbc08dadccc79c00587d7e6a75bb68ff5fd30f9e0`
773
+
774
+ <br>
291
775
 
292
- ## Running unit tests
776
+ ### Running tests
293
777
 
294
- Run `nx test libs-api-sdk` to execute the unit tests via [Jest](https://jestjs.io).
778
+ Run `nx test libs-sdk` to execute the tests via [Jest](https://jestjs.io).
295
779
 
296
- ## Running lint
780
+ API responses are recorded using [polly.js](https://github.com/Netflix/pollyjs). You can re-record live requests by passing in an API key, copy `.env.test.example` to `.env.test` and fill out with your API key.
781
+
782
+ <br>
783
+
784
+ ### Running linting
785
+
786
+ Run `nx lint libs-sdk` to execute the lint via [ESLint](https://eslint.org/).
787
+
788
+ <br>
297
789
 
298
- Run `nx lint libs-api-sdk` to execute the lint via [ESLint](https://eslint.org/).
790
+ ### Generate graphql codegen typings
299
791
 
300
- ## Generate graphql
792
+ Generate graphql typings via [Codegen](https://www.the-guild.dev/graphql/codegen).
301
793
 
302
- Run `yarn codegen` to generate graphql typings via [Codegen](https://www.the-guild.dev/graphql/codegen).
794
+ 1. navigate to `packages/libs/sdk` from `qn-oss` monorepo root
795
+ 1. `cp .env.example .env` and add api key
796
+ 1. run `yarn run codegen`