@quicknode/sdk 0.5.1 → 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,230 +1,724 @@
1
- ![npm](https://img.shields.io/npm/dm/@quicknode/sdk)
2
- ![npm](https://img.shields.io/npm/v/@quicknode/sdk?color=g)
3
- ![Maintenance](https://img.shields.io/maintenance/yes/2022?color=g)
4
- ![NPM](https://img.shields.io/npm/l/@quicknode/sdk?color=g)
5
- ![GitHub issues](https://img.shields.io/github/issues-raw/quiknode-labs/qn-oss?color=g)
6
- ![Discord](https://img.shields.io/discord/880505845090250794?color=g)
7
-
8
1
  # QuickNode SDK
9
2
 
10
- Currently has support for getting started with [Icy Tools GraphQL API](https://developers.icy.tools/) in a blink!
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
+ A SDK from [QuickNode](https://www.quicknode.com/) making it easy for developers to interact with QuickNode's services.
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)
14
+ [![npm](https://img.shields.io/npm/dm/@quicknode/sdk)](https://www.npmjs.com/package/@quicknode/sdk)
15
+ [![npm](https://img.shields.io/npm/v/@quicknode/sdk?color=g)](https://www.npmjs.com/package/@quicknode/sdk)
16
+ ![Maintenance](https://img.shields.io/maintenance/yes/2023?color=g)
17
+ [![License](https://img.shields.io/npm/l/@quicknode/sdk?color=g)](https://github.com/quiknode-labs/qn-oss/blob/main/LICENSE.txt)
18
+ [![GitHub issues](https://img.shields.io/github/issues-raw/quiknode-labs/qn-oss?color=g)](https://github.com/quiknode-labs/qn-oss/issues)
19
+ [![Discord](https://img.shields.io/discord/880505845090250794?color=g)](https://discord.gg/DkdgEqE)
20
+
21
+ <br>
11
22
 
12
- ## Quick Start
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
13
68
 
14
69
  ```ts
15
- import { QuickNodeSDK } from '@quicknode/sdk';
70
+ import QuickNode from '@quicknode/sdk';
16
71
 
17
- const client = new QuickNodeSDK();
72
+ const qn = new QuickNode.API({ graphApiKey: 'my-api-key' });
18
73
 
19
- client.nft
20
- .getNFTsByWalletENS({
21
- ensName: 'vitalik.eth',
74
+ qn.nfts
75
+ .getByWallet({
76
+ address: 'quicknode.eth',
22
77
  first: 5,
23
78
  })
24
79
  .then((response) => console.log(response));
25
80
  ```
26
81
 
27
- 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)
83
+
84
+ <br>
85
+
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>
28
91
 
29
- ## Providing a config object to the client
92
+ ### Configuration
30
93
 
31
- > :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.
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.
32
95
 
33
96
  ```ts
34
- import { QuickNodeSDK } from '@quicknode/sdk';
97
+ import QuickNode from '@quicknode/sdk';
35
98
 
36
- const client = new QuickNodeSDK({
37
- 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',
38
102
  });
39
103
  ```
40
104
 
41
- ### 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 |
42
123
 
43
- | Property | Values | Example |
44
- | --------- | ------ | ---------------------------------- |
45
- | icyApiKey | string | 1c1t00ls-4p10-k3y0-lu21-43405e3310 |
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';
146
+
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
+ ```
46
166
 
47
167
  <br>
48
168
 
49
- ## Methods
169
+ ### nfts.getTrendingCollections
50
170
 
51
- ### nft.getNFTsByWalletENS
171
+ Returns trending NFT Collections
52
172
 
53
- | Argument | Values | Optional | Description | Example |
173
+ | Argument | Values | Required | Description | Example |
54
174
  | -------- | ------ | -------- | ------------------------------- | --------------------------- |
55
- | ensName | string | ❌ | Wallet ENS address | vitalik.eth |
56
- | first | number | | Number of results to return | 10 |
57
- | 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 |
58
205
 
59
206
  ```ts
60
- import { QuickNodeSDK } from '@quicknode/sdk';
207
+ import QuickNode from '@quicknode/sdk';
61
208
 
62
- 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
+ });
63
212
 
64
- client.nft
65
- .getNFTsByWalletENS({
66
- ensName: 'vitalik.eth',
213
+ qn.nfts
214
+ .getByContractAddress({
215
+ contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
67
216
  first: 5,
68
217
  })
69
218
  .then((response) => console.log(response));
70
219
  ```
71
220
 
72
- ### 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
73
276
 
74
- | Argument | Values | Optional | Description | Example |
277
+ Returns ERC20 token balances for a wallet
278
+
279
+ | Argument | Values | Required | Description | Example |
75
280
  | -------- | ------ | -------- | ------------------------------- | ------------------------------------------ |
76
- | address | string | | Wallet address | 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 |
77
- | first | number | | Number of results to return | 10 |
78
- | 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 |
79
285
 
80
286
  ```ts
81
- import { QuickNodeSDK } from '@quicknode/sdk';
287
+ import QuickNode from '@quicknode/sdk';
82
288
 
83
- 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
+ });
84
292
 
85
- client.nft
86
- .getNFTsByWalletAddress({
87
- address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
293
+ qn.tokens
294
+ .getBalancesByWallet({
295
+ address: '0xd10e24685c7cdd3cd3baaa86b09c92be28c834b6',
296
+ first: 5,
297
+ })
298
+ .then((response) => console.log(response));
299
+
300
+ // Can pass in ENS domain
301
+ qn.tokens
302
+ .getBalancesByWallet({
303
+ address: 'quicknode.eth',
88
304
  first: 5,
89
305
  })
90
306
  .then((response) => console.log(response));
91
307
  ```
92
308
 
93
- ### nft.getNFTsByContractAddress
309
+ <br>
310
+
311
+ ### contracts.getDetails
312
+
313
+ Get the details and ABI for a contract address
94
314
 
95
- | Argument | Values | Optional | Description | Example |
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));
332
+ ```
333
+
334
+ <br>
335
+
336
+ ### transactions.getByWallet
337
+
338
+ Returns transactions for a wallet
339
+
340
+ | Argument | Values | Required | Description | Example |
96
341
  | -------- | ------ | -------- | ------------------------------- | ------------------------------------------ |
97
- | address | string | | Contract address of NFT | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
98
- | first | number | | Number of results to return | 10 |
99
- | 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 |
100
346
 
101
347
  ```ts
102
- import { QuickNodeSDK } from '@quicknode/sdk';
348
+ import QuickNode from '@quicknode/sdk';
349
+
350
+ const qn = new QuickNode.API({
351
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
352
+ });
103
353
 
104
- const client = new QuickNodeSDK();
354
+ qn.transactions
355
+ .getByWallet({
356
+ address: '0xd10e24685c7cdd3cd3baaa86b09c92be28c834b6',
357
+ first: 5,
358
+ })
359
+ .then((response) => console.log(response));
105
360
 
106
- client.nft
107
- .getNFTsByContractAddress({
108
- address: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
361
+ // Can pass in ENS domain
362
+ qn.transactions
363
+ .getByWallet({
364
+ address: 'quicknode.eth',
109
365
  first: 5,
110
366
  })
111
367
  .then((response) => console.log(response));
112
368
  ```
113
369
 
114
- ### 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 } } |
115
382
 
116
- | Argument | Values | Optional | Description | Example |
117
- | -------- | ------ | -------- | ----------------------- | ------------------------------------------ |
118
- | address | string | | Contract address of NFT | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
383
+ `filter` Parameters
384
+
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._
119
393
 
120
394
  ```ts
121
- import { QuickNodeSDK } from '@quicknode/sdk';
395
+ import QuickNode from '@quicknode/sdk';
122
396
 
123
- 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
+ });
124
400
 
125
- client.nft
126
- .getCollectionDetails({
127
- address: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
401
+ // Use the filters
402
+ qn.transactions
403
+ .getAll({
404
+ filter: {
405
+ blockNumber: {
406
+ eq: 17372310,
407
+ },
408
+ fromAddress: '0x41407a3c41da7970d30a0343cda8b9db70c145fb',
409
+ },
128
410
  })
129
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));
130
415
  ```
131
416
 
132
- ### nft.getNFTEventLogs
417
+ <br>
418
+
419
+ ### transactions.getByHash
133
420
 
134
- | Argument | Values | Optional | Description | Example |
135
- | -------- | ------ | -------- | --------------------------------------------------------------------------------- | ------------------------------------------ |
136
- | address | string | | Contract address of NFT | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
137
- | tokenId | string | | NFT ID | 100 |
138
- | types | array | ✅ | An array of event types 'TRANSFER', 'ORDER', and/or 'MINT'. Defaults to all types | ['TRANSFER', 'ORDER', 'MINT] |
139
- | first | number | ✅ | Number of results to return | 10 |
140
- | after | string | ✅ | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
421
+ Returns transaction information by transaction hash
422
+
423
+ | Argument | Values | Required | Description | Example |
424
+ | -------- | ------ | -------- | ----------------------- | ------------------------------------------------------------------ |
425
+ | hash | string | ✅ | Hash of the transaction | 0x1aa26d1d542b414dd2e2d1aa6f8d8e128e2a45bc4a04c24232207221914389bf |
141
426
 
142
427
  ```ts
143
- 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
+ ```
440
+
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
144
457
 
145
- const client = new QuickNodeSDK();
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
+ });
464
+
465
+ qn.events
466
+ .getByContract({
467
+ contractAddress: '0x2106C00Ac7dA0A3430aE667879139E832307AeAa',
468
+ })
469
+ .then((response) => console.log(response));
146
470
 
147
- client.nft
148
- .getNFTEventLogs({
149
- address: '0x60E4d786628Fea6478F785A6d7e704777c86a7c6',
150
- tokenId: '100',
151
- types: ['TRANSFER', 'ORDER'],
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
+ }
152
483
  })
153
484
  .then((response) => console.log(response));
485
+ `
154
486
  ```
155
487
 
156
- ### nft.getNFTDetails
488
+ <br>
489
+
490
+ ### events.getByNFTCollection
157
491
 
158
- Returns the details for a single NFT
159
- | Argument | Values | Optional | Description | Example |
160
- | --------------- | ------ | -------- | --------------------------------- | ------------------------------------------ |
161
- | contractAddress | string | | Contract address of NFT Collection | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
162
- | tokenId | string | | NFT ID | 5020 |
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
163
505
 
164
506
  ```ts
165
- import { QuickNodeSDK } from '@quicknode/sdk';
507
+ import QuickNode from '@quicknode/sdk';
166
508
 
167
- 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
+ });
168
512
 
169
- client.nft
170
- .getNFTDetails({
171
- contractAddress: '0x23581767a106ae21c074b2276D25e5C3e136a68b',
172
- 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
+ },
530
+ })
531
+ .then((response) => console.log(response));
532
+ ```
533
+
534
+ <br>
535
+
536
+ ### events.getByNFT
537
+
538
+ Returns the events for a specific NFT
539
+
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
552
+
553
+ ```ts
554
+ import QuickNode from '@quicknode/sdk';
555
+
556
+ const qn = new QuickNode.API({
557
+ graphApiKey: 'my-api-key', // which is obtained by signing up on https://www.quicknode.com/signup
558
+ });
559
+
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
+ },
173
576
  })
174
577
  .then((response) => console.log(response));
175
578
  ```
176
579
 
177
- ### nft.getContractEventLogs
580
+ <br>
178
581
 
179
- Returns the log events for a NFT contract
582
+ ### events.getAll
180
583
 
181
- | Argument | Values | Optional | Description | Example |
182
- | -------- | ------ | -------- | --------------------------------------------------------------------------------- | ------------------------------------------ |
183
- | address | string | | Contract address of NFT | 0x2106C00Ac7dA0A3430aE667879139E832307AeAa |
184
- | types | array | | An array of event types 'TRANSFER', 'ORDER', and/or 'MINT'. Defaults to all types | ['TRANSFER', 'ORDER', 'MINT] |
185
- | first | number | | Number of results to return | 10 |
186
- | after | string | | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
584
+ Returns events filtered by search parameters
585
+
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 } } |
592
+
593
+ `filter` Parameters
594
+
595
+ Please see the [Token Event Filters section](#token-event-filters) for all options
187
596
 
188
597
  ```ts
189
- import { QuickNodeSDK } from '@quicknode/sdk';
598
+ import QuickNode from '@quicknode/sdk';
190
599
 
191
- 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
+ });
192
603
 
193
- client.nft
194
- .getContractEventLogs({
195
- address: '0x60E4d786628Fea6478F785A6d7e704777c86a7c6',
196
- types: ['TRANSFER', 'ORDER'],
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
+ },
197
616
  })
198
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));
199
621
  ```
200
622
 
201
- ### nft.getNFTsByWalletAndContracts
623
+ <br>
624
+
625
+ ### utils.getGasPrices
202
626
 
203
- Gets NFTs from specified collections held by a wallet
627
+ Returns historical gas prices by block number. Defaults to returning values in wei.
204
628
 
205
- | Argument | Values | Optional | Description | Example |
206
- | --------- | ---------------- | -------- | ------------------------------- | ---------------------------------------------- |
207
- | address | string | ❌ | Wallet address | 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 |
208
- | contracts | array of strings | ❌ | NFT contract addresses | ['0xba30e5f9bb24caa003e9f2f0497ad287fdf95623'] |
209
- | first | number | | Number of results to return | 10 |
210
- | after | string | ✅ | Return results after end cursor | YXJyYXljb25uZWN0aW9uOjUwNQ= |
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 } |
211
640
 
212
641
  ```ts
213
- import { QuickNodeSDK } from '@quicknode/sdk';
642
+ import QuickNode from '@quicknode/sdk';
214
643
 
215
- 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
+ });
216
647
 
217
- client.nft
218
- .getNFTsByWalletAndContracts({
219
- address: '0x13928eb9a86c8278a45b6ff2935c7730b58ac675',
220
- contracts: [
221
- '0xba30e5f9bb24caa003e9f2f0497ad287fdf95623',
222
- '0xbce3781ae7ca1a5e050bd9c4c77369867ebc307e',
223
- ],
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
+ },
224
659
  })
225
660
  .then((response) => console.log(response));
226
661
  ```
227
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
+
228
722
  ## Pagination
229
723
 
230
724
  For functions that support pagination, use the `first` property to specify the amount of results to return.
@@ -236,10 +730,13 @@ The returned `data.tokensPageInfo.endCursor` property in the response can be use
236
730
  For example, if a response contains:
237
731
 
238
732
  ```json
239
- "data": {
240
- "tokensPageInfo": {
733
+ {
734
+ "results": [],
735
+ "pageInfo": {
736
+ "endCursor": "T2Zmc2V0Q29ubmVjdGlvbjox",
241
737
  "hasNextPage": true,
242
- "endCursor": 'YXJyYXljb25uZWN0aW9uOlk='
738
+ "hasPreviousPage": false,
739
+ "startCursor": "T2Zmc2V0Q29ubmVjdGlvbjow"
243
740
  }
244
741
  }
245
742
  ```
@@ -247,23 +744,53 @@ For example, if a response contains:
247
744
  calling the following will get the next page of results
248
745
 
249
746
  ```typescript
250
- client.nft.getNFTsByWalletENS({
251
- ensName: 'vitalik.eth',
747
+ qn.nfts.getByWallet({
748
+ address: 'quicknode.eth',
252
749
  first: 5,
253
- after: 'YXJyYXljb25uZWN0aW9uOlk=', // from data.tokensPageInfo.endCursor in response
750
+ after: 'T2Zmc2V0Q29ubmVjdGlvbjox',
254
751
  });
255
752
  ```
256
753
 
257
- # Contributing corner
754
+ <br>
755
+
756
+ ## Contributing corner
258
757
 
259
- ## Building
758
+ ### Issues
260
759
 
261
- Run `nx build libs-api-sdk` to build the library.
760
+ Please submit any issues or feature requests as an [issue in Github](https://github.com/quiknode-labs/qn-oss/issues).
262
761
 
263
- ## Running unit tests
762
+ <br>
763
+
764
+ ### Development
765
+
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>
775
+
776
+ ### Running tests
777
+
778
+ Run `nx test libs-sdk` to execute the tests via [Jest](https://jestjs.io).
779
+
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>
264
789
 
265
- Run `nx test libs-api-sdk` to execute the unit tests via [Jest](https://jestjs.io).
790
+ ### Generate graphql codegen typings
266
791
 
267
- ## Running lint
792
+ Generate graphql typings via [Codegen](https://www.the-guild.dev/graphql/codegen).
268
793
 
269
- Run `nx lint libs-api-sdk` to execute the lint via [ESLint](https://eslint.org/).
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`