@codex-data/sdk 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +370 -172
- package/dist/sdk/Subscribe.js +5 -5
- package/dist/sdk/Subscribe.mjs +5 -5
- package/dist/sdk/generated/gql.d.ts +40 -40
- package/dist/sdk/generated/gql.js +20 -20
- package/dist/sdk/generated/gql.mjs +20 -20
- package/dist/sdk/generated/graphql.d.ts +63 -5
- package/dist/sdk/generated/graphql.js +25 -20
- package/dist/sdk/generated/graphql.mjs +25 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,261 +1,459 @@
|
|
|
1
1
|
# Codex SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The TypeScript SDK for the [Codex API](https://www.codex.io) — real-time blockchain data, token prices, OHLCV charts, wallet balances, and holder analytics for 60M+ tokens across 80+ networks including Ethereum, Solana, Base, Arbitrum, BSC, and Polygon.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Codex is a GraphQL API used by teams like Coinbase, TradingView, Uniswap, Rainbow, FOMO, Farcaster, and hundreds of others.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
> You will see references to our previous company name, Defined, while we make the switch to Codex.
|
|
7
|
+
- **[Documentation](https://docs.codex.io)**
|
|
8
|
+
- **[Get an API Key](https://dashboard.codex.io)**
|
|
9
|
+
- **[GraphQL Explorer](https://explorer.codex.io)**
|
|
11
10
|
|
|
12
|
-
##
|
|
11
|
+
## Installation
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- 🛠 **Developer Friendly**: Comprehensive examples and documentation
|
|
13
|
+
```bash
|
|
14
|
+
npm install @codex-data/sdk
|
|
15
|
+
```
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
```bash
|
|
18
|
+
yarn add @codex-data/sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add @codex-data/sdk
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Codex } from "@codex-data/sdk";
|
|
20
29
|
|
|
21
|
-
|
|
22
|
-
| ----------------------------- | ----------------------------- |
|
|
23
|
-
| [npm](https://www.npmjs.com/) | `npm install @codex-data/sdk` |
|
|
24
|
-
| [yarn](https://yarnpkg.com/) | `yarn add @codex-data/sdk` |
|
|
25
|
-
| [pnpm](https://pnpm.io/) | `pnpm add @codex-data/sdk` |
|
|
30
|
+
const sdk = new Codex(process.env.CODEX_API_KEY!);
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
const networks = await sdk.queries.getNetworks({});
|
|
33
|
+
console.log(networks.getNetworks); // [{ id: 1, name: "ethereum" }, { id: 1399811149, name: "solana" }, ...]
|
|
34
|
+
```
|
|
28
35
|
|
|
29
|
-
|
|
36
|
+
## Get Token Prices
|
|
30
37
|
|
|
31
|
-
|
|
38
|
+
Get the current USD price of any token. Supports up to 25 tokens per request. Prices are liquidity-weighted across all valid pools.
|
|
32
39
|
|
|
33
40
|
```typescript
|
|
34
41
|
import { Codex } from "@codex-data/sdk";
|
|
35
42
|
|
|
36
|
-
const sdk = new Codex(
|
|
43
|
+
const sdk = new Codex(process.env.CODEX_API_KEY!);
|
|
44
|
+
|
|
45
|
+
const prices = await sdk.queries.getTokenPrices({
|
|
46
|
+
inputs: [
|
|
47
|
+
{ address: "So11111111111111111111111111111111111111112", networkId: 1399811149 }, // SOL
|
|
48
|
+
{ address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", networkId: 1 }, // WETH
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
prices.getTokenPrices?.forEach((price) => {
|
|
53
|
+
console.log(`${price?.address}: $${price?.priceUsd}`);
|
|
54
|
+
});
|
|
55
|
+
```
|
|
37
56
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
57
|
+
To get a historical price, pass a `timestamp`:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
const historicalPrice = await sdk.queries.getTokenPrices({
|
|
61
|
+
inputs: [
|
|
62
|
+
{
|
|
63
|
+
address: "So11111111111111111111111111111111111111112",
|
|
64
|
+
networkId: 1399811149,
|
|
65
|
+
timestamp: 1704067200, // Unix timestamp
|
|
43
66
|
},
|
|
44
|
-
|
|
45
|
-
|
|
67
|
+
],
|
|
68
|
+
});
|
|
46
69
|
```
|
|
47
70
|
|
|
48
|
-
|
|
71
|
+
## Get OHLCV Chart Data
|
|
72
|
+
|
|
73
|
+
Get candlestick data for any token or trading pair. Supports resolutions from 1-second to 7-day.
|
|
49
74
|
|
|
50
75
|
```typescript
|
|
51
76
|
import { Codex } from "@codex-data/sdk";
|
|
52
77
|
|
|
53
|
-
const sdk = new Codex(process.env.CODEX_API_KEY
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
78
|
+
const sdk = new Codex(process.env.CODEX_API_KEY!);
|
|
79
|
+
|
|
80
|
+
const bars = await sdk.queries.getBars({
|
|
81
|
+
symbol: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2:1", // WETH on Ethereum
|
|
82
|
+
from: 1704067200,
|
|
83
|
+
to: 1704153600,
|
|
84
|
+
resolution: "60", // 1-hour candles
|
|
85
|
+
removeEmptyBars: true,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
bars.getBars?.o?.forEach((open, i) => {
|
|
89
|
+
console.log({
|
|
90
|
+
open,
|
|
91
|
+
high: bars.getBars?.h?.[i],
|
|
92
|
+
low: bars.getBars?.l?.[i],
|
|
93
|
+
close: bars.getBars?.c?.[i],
|
|
94
|
+
volume: bars.getBars?.volume?.[i],
|
|
95
|
+
timestamp: bars.getBars?.t?.[i],
|
|
67
96
|
});
|
|
97
|
+
});
|
|
68
98
|
```
|
|
69
99
|
|
|
70
|
-
|
|
100
|
+
Available resolutions: `1S`, `5S`, `15S`, `30S`, `1`, `5`, `15`, `30`, `60`, `240`, `720`, `1D`, `7D`
|
|
101
|
+
|
|
102
|
+
## Discover and Filter Tokens
|
|
103
|
+
|
|
104
|
+
Search and filter tokens by price, volume, market cap, liquidity, holder count, trading activity, and more.
|
|
71
105
|
|
|
72
106
|
```typescript
|
|
73
|
-
import { Codex } from "@codex-data/sdk";
|
|
107
|
+
import { Codex, TokenRankingAttribute, RankingDirection } from "@codex-data/sdk";
|
|
74
108
|
|
|
75
|
-
const sdk = new Codex(process.env.CODEX_API_KEY
|
|
109
|
+
const sdk = new Codex(process.env.CODEX_API_KEY!);
|
|
76
110
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
(result) => {
|
|
84
|
-
if (result.data) {
|
|
85
|
-
console.log("Price updated:", result.data.onPriceUpdated);
|
|
86
|
-
}
|
|
111
|
+
const result = await sdk.queries.filterTokens({
|
|
112
|
+
filters: {
|
|
113
|
+
network: [1], // Ethereum
|
|
114
|
+
liquidity: { gte: "100000" }, // $100k+ liquidity
|
|
115
|
+
marketCap: { gte: "1000000" }, // $1M+ market cap
|
|
116
|
+
txnCount24: { gte: "500" }, // 500+ transactions in 24h
|
|
87
117
|
},
|
|
88
|
-
|
|
118
|
+
rankings: [
|
|
119
|
+
{
|
|
120
|
+
attribute: TokenRankingAttribute.TrendingScore24,
|
|
121
|
+
direction: RankingDirection.Desc,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
limit: 20,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
result.filterTokens?.results?.forEach((token) => {
|
|
128
|
+
console.log(`${token?.token?.name} (${token?.token?.symbol}): $${token?.priceUSD}`);
|
|
129
|
+
});
|
|
89
130
|
```
|
|
90
131
|
|
|
91
|
-
##
|
|
132
|
+
## Get Wallet Balances
|
|
92
133
|
|
|
93
|
-
|
|
134
|
+
Get all token balances for a wallet address with USD values.
|
|
94
135
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
- [`curl`](https://curl.se/) for fetching the GraphQL schema
|
|
136
|
+
```typescript
|
|
137
|
+
import { Codex } from "@codex-data/sdk";
|
|
98
138
|
|
|
99
|
-
|
|
139
|
+
const sdk = new Codex(process.env.CODEX_API_KEY!);
|
|
100
140
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
141
|
+
const balances = await sdk.queries.balances({
|
|
142
|
+
input: {
|
|
143
|
+
walletAddress: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", // vitalik.eth
|
|
144
|
+
networks: [1],
|
|
145
|
+
includeNative: true,
|
|
146
|
+
removeScams: true,
|
|
147
|
+
limit: 50,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
104
150
|
|
|
105
|
-
|
|
106
|
-
|
|
151
|
+
balances.balances?.items?.forEach((item) => {
|
|
152
|
+
console.log(`${item?.token?.symbol}: ${item?.shiftedBalance} ($${item?.balanceUsd})`);
|
|
153
|
+
});
|
|
107
154
|
```
|
|
108
155
|
|
|
109
|
-
|
|
156
|
+
## Get Token Holders
|
|
110
157
|
|
|
111
|
-
|
|
158
|
+
Get the list of wallets holding a specific token, sorted by balance.
|
|
112
159
|
|
|
113
|
-
|
|
160
|
+
```typescript
|
|
161
|
+
import { Codex } from "@codex-data/sdk";
|
|
114
162
|
|
|
115
|
-
|
|
163
|
+
const sdk = new Codex(process.env.CODEX_API_KEY!);
|
|
116
164
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
165
|
+
const holders = await sdk.queries.holders({
|
|
166
|
+
input: {
|
|
167
|
+
tokenId: "So11111111111111111111111111111111111111112:1399811149", // SOL
|
|
168
|
+
limit: 50,
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
console.log(`Total holders: ${holders.holders?.count}`);
|
|
173
|
+
console.log(`Top 10 hold: ${holders.holders?.top10HoldersPercent}%`);
|
|
174
|
+
|
|
175
|
+
holders.holders?.items?.forEach((holder) => {
|
|
176
|
+
console.log(`${holder?.address}: ${holder?.shiftedBalance} ($${holder?.balanceUsd})`);
|
|
177
|
+
});
|
|
121
178
|
```
|
|
122
179
|
|
|
123
|
-
|
|
180
|
+
## Get Token Trade History
|
|
124
181
|
|
|
125
|
-
|
|
182
|
+
Get buy, sell, mint, and burn events for any token or pair.
|
|
126
183
|
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
pnpm install
|
|
130
|
-
pnpm run codegen
|
|
131
|
-
CODEX_API_KEY=your_api_key pnpm run dev
|
|
132
|
-
```
|
|
184
|
+
```typescript
|
|
185
|
+
import { Codex } from "@codex-data/sdk";
|
|
133
186
|
|
|
134
|
-
|
|
187
|
+
const sdk = new Codex(process.env.CODEX_API_KEY!);
|
|
135
188
|
|
|
136
|
-
|
|
189
|
+
const events = await sdk.queries.getTokenEvents({
|
|
190
|
+
query: {
|
|
191
|
+
address: "So11111111111111111111111111111111111111112",
|
|
192
|
+
networkId: 1399811149,
|
|
193
|
+
eventDisplayType: ["Buy", "Sell"],
|
|
194
|
+
},
|
|
195
|
+
limit: 25,
|
|
196
|
+
});
|
|
137
197
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
NEXT_PUBLIC_CODEX_API_KEY=your_api_key pnpm run dev
|
|
198
|
+
events.getTokenEvents?.items?.forEach((event) => {
|
|
199
|
+
console.log(`${event?.eventDisplayType} by ${event?.maker} — $${event?.token0SwapValueUsd}`);
|
|
200
|
+
});
|
|
142
201
|
```
|
|
143
202
|
|
|
144
|
-
##
|
|
203
|
+
## Stream Real-Time Prices
|
|
145
204
|
|
|
146
|
-
|
|
205
|
+
> **Note:** WebSocket subscriptions require a [paid plan](https://dashboard.codex.io/dashboard/billing).
|
|
147
206
|
|
|
148
|
-
|
|
149
|
-
@codex-data/sdk/
|
|
150
|
-
├── dist/
|
|
151
|
-
│ ├── index.js # CommonJS entry point
|
|
152
|
-
│ ├── index.mjs # ESM entry point
|
|
153
|
-
│ ├── index.d.ts # TypeScript definitions
|
|
154
|
-
│ └── sdk/ # SDK implementation
|
|
155
|
-
├── README.md
|
|
156
|
-
└── package.json
|
|
157
|
-
```
|
|
207
|
+
Subscribe to live price updates via WebSocket. Fires on every on-chain swap.
|
|
158
208
|
|
|
159
|
-
|
|
209
|
+
```typescript
|
|
210
|
+
import { Codex } from "@codex-data/sdk";
|
|
160
211
|
|
|
161
|
-
|
|
212
|
+
const sdk = new Codex(process.env.CODEX_API_KEY!);
|
|
162
213
|
|
|
163
|
-
|
|
214
|
+
const unsubscribe = sdk.subscriptions.onPriceUpdated(
|
|
215
|
+
{
|
|
216
|
+
address: "So11111111111111111111111111111111111111112",
|
|
217
|
+
networkId: 1399811149,
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
next: (result) => {
|
|
221
|
+
console.log("Price:", result.data?.onPriceUpdated?.priceUsd);
|
|
222
|
+
},
|
|
223
|
+
error: (err) => console.error(err),
|
|
224
|
+
complete: () => console.log("Stream ended"),
|
|
225
|
+
},
|
|
226
|
+
);
|
|
164
227
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
- `pnpm run lint` - Lint the codebase
|
|
168
|
-
- `pnpm run clean` - Clean build artifacts
|
|
228
|
+
// Call unsubscribe() to clean up
|
|
229
|
+
```
|
|
169
230
|
|
|
170
|
-
##
|
|
231
|
+
## Stream Real-Time OHLCV Bars
|
|
171
232
|
|
|
172
|
-
|
|
233
|
+
> **Note:** WebSocket subscriptions require a [paid plan](https://dashboard.codex.io/dashboard/billing).
|
|
173
234
|
|
|
174
|
-
|
|
235
|
+
Get live candlestick updates across all resolutions simultaneously.
|
|
175
236
|
|
|
176
|
-
|
|
237
|
+
```typescript
|
|
238
|
+
import { Codex, QuoteToken } from "@codex-data/sdk";
|
|
177
239
|
|
|
178
|
-
|
|
179
|
-
"version": "2.0.0-beta.0"
|
|
180
|
-
```
|
|
240
|
+
const sdk = new Codex(process.env.CODEX_API_KEY!);
|
|
181
241
|
|
|
182
|
-
|
|
242
|
+
const unsubscribe = sdk.subscriptions.onBarsUpdated(
|
|
243
|
+
{
|
|
244
|
+
pairId: "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640:1", // USDC/WETH on Ethereum
|
|
245
|
+
quoteToken: QuoteToken.Token1,
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
next: (result) => {
|
|
249
|
+
const bar = result.data?.onBarsUpdated;
|
|
250
|
+
const oneMin = bar?.aggregates?.r1?.usd;
|
|
251
|
+
console.log(`1min candle — O: ${oneMin?.o} H: ${oneMin?.h} L: ${oneMin?.l} C: ${oneMin?.c}`);
|
|
252
|
+
},
|
|
253
|
+
error: (err) => console.error(err),
|
|
254
|
+
complete: () => console.log("Stream ended"),
|
|
255
|
+
},
|
|
256
|
+
);
|
|
257
|
+
```
|
|
183
258
|
|
|
184
|
-
|
|
185
|
-
pnpm run publish:beta
|
|
186
|
-
```
|
|
259
|
+
## Stream Live Trades
|
|
187
260
|
|
|
188
|
-
|
|
189
|
-
```bash
|
|
190
|
-
npm install @codex-data/sdk@beta
|
|
191
|
-
```
|
|
261
|
+
> **Note:** WebSocket subscriptions require a [paid plan](https://dashboard.codex.io/dashboard/billing).
|
|
192
262
|
|
|
193
|
-
|
|
263
|
+
Watch buy/sell events as they happen on any trading pair.
|
|
194
264
|
|
|
195
|
-
|
|
265
|
+
```typescript
|
|
266
|
+
import { Codex, QuoteToken } from "@codex-data/sdk";
|
|
196
267
|
|
|
197
|
-
|
|
268
|
+
const sdk = new Codex(process.env.CODEX_API_KEY!);
|
|
198
269
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
270
|
+
const unsubscribe = sdk.subscriptions.onEventsCreated(
|
|
271
|
+
{
|
|
272
|
+
id: "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640:1",
|
|
273
|
+
quoteToken: QuoteToken.Token0,
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
next: (result) => {
|
|
277
|
+
result.data?.onEventsCreated?.events?.forEach((event) => {
|
|
278
|
+
console.log(`${event?.eventDisplayType} by ${event?.maker} — $${event?.token0SwapValueUsd}`);
|
|
279
|
+
});
|
|
280
|
+
},
|
|
281
|
+
error: (err) => console.error(err),
|
|
282
|
+
complete: () => console.log("Stream ended"),
|
|
283
|
+
},
|
|
284
|
+
);
|
|
285
|
+
```
|
|
202
286
|
|
|
203
|
-
|
|
204
|
-
```bash
|
|
205
|
-
pnpm run publish:latest
|
|
206
|
-
```
|
|
287
|
+
## Raw GraphQL Queries
|
|
207
288
|
|
|
208
|
-
|
|
289
|
+
Use `sdk.send()` to execute any GraphQL query directly.
|
|
209
290
|
|
|
210
|
-
|
|
291
|
+
```typescript
|
|
292
|
+
import { Codex } from "@codex-data/sdk";
|
|
211
293
|
|
|
212
|
-
|
|
294
|
+
const sdk = new Codex(process.env.CODEX_API_KEY!);
|
|
213
295
|
|
|
214
|
-
|
|
296
|
+
const result = await sdk.send<{
|
|
297
|
+
getNetworks: Array<{ id: number; name: string }>;
|
|
298
|
+
}>(
|
|
299
|
+
`query GetNetworks {
|
|
300
|
+
getNetworks { id name }
|
|
301
|
+
}`,
|
|
302
|
+
{},
|
|
303
|
+
);
|
|
215
304
|
|
|
216
|
-
|
|
305
|
+
console.log("Networks:", result.getNetworks);
|
|
217
306
|
```
|
|
307
|
+
|
|
308
|
+
## Common Network IDs
|
|
309
|
+
|
|
310
|
+
| Network | ID |
|
|
311
|
+
| --- | --- |
|
|
312
|
+
| Ethereum | `1` |
|
|
313
|
+
| BSC | `56` |
|
|
314
|
+
| Polygon | `137` |
|
|
315
|
+
| Arbitrum | `42161` |
|
|
316
|
+
| Base | `8453` |
|
|
317
|
+
| Avalanche | `43114` |
|
|
318
|
+
| Solana | `1399811149` |
|
|
319
|
+
|
|
320
|
+
Use `sdk.queries.getNetworks({})` for the full list of 80+ supported networks.
|
|
321
|
+
|
|
322
|
+
## ID Format Convention
|
|
323
|
+
|
|
324
|
+
IDs in the Codex API follow the pattern `address:networkId`:
|
|
325
|
+
|
|
326
|
+
- **Token ID:** `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2:1` (WETH on Ethereum)
|
|
327
|
+
- **Pair ID:** `0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640:1` (USDC/WETH on Ethereum)
|
|
328
|
+
- **Wallet ID:** `0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045:1`
|
|
329
|
+
|
|
330
|
+
## All Available Methods
|
|
331
|
+
|
|
332
|
+
### Queries (`sdk.queries.*`)
|
|
333
|
+
|
|
334
|
+
| Method | Description |
|
|
335
|
+
| --- | --- |
|
|
336
|
+
| [`filterTokens`](https://docs.codex.io/api-reference/queries/filtertokens) | Search and filter tokens by price, volume, market cap, liquidity |
|
|
337
|
+
| [`getTokenPrices`](https://docs.codex.io/api-reference/queries/gettokenprices) | Get current or historical USD prices for up to 25 tokens |
|
|
338
|
+
| [`getBars`](https://docs.codex.io/api-reference/queries/getbars) | Get OHLCV candlestick data for a trading pair |
|
|
339
|
+
| [`holders`](https://docs.codex.io/api-reference/queries/holders) | Get token holder list sorted by balance ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
340
|
+
| [`filterPairs`](https://docs.codex.io/api-reference/queries/filterpairs) | Search and filter trading pairs |
|
|
341
|
+
| [`balances`](https://docs.codex.io/api-reference/queries/balances) | Get wallet token balances with USD values ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
342
|
+
| [`getTokenEvents`](https://docs.codex.io/api-reference/queries/gettokenevents) | Get buy/sell/mint/burn trade events |
|
|
343
|
+
| [`pairMetadata`](https://docs.codex.io/api-reference/queries/pairmetadata) | Get trading pair stats and metadata |
|
|
344
|
+
| [`token`](https://docs.codex.io/api-reference/queries/token) | Get metadata for a single token |
|
|
345
|
+
| [`listPairsWithMetadataForToken`](https://docs.codex.io/api-reference/queries/listpairswithmetadatafortoken) | List pairs with full metadata |
|
|
346
|
+
| [`getTokenEventsForMaker`](https://docs.codex.io/api-reference/queries/gettokeneventsformaker) | Get trade events for a specific wallet |
|
|
347
|
+
| [`getDetailedPairStats`](https://docs.codex.io/api-reference/queries/getdetailedpairstats) | Get detailed bucketed stats for a pair |
|
|
348
|
+
| [`listPairsForToken`](https://docs.codex.io/api-reference/queries/listpairsfortoken) | List all trading pairs for a token |
|
|
349
|
+
| [`tokenTopTraders`](https://docs.codex.io/api-reference/queries/tokentoptraders) | Get top traders for a token |
|
|
350
|
+
| [`tokens`](https://docs.codex.io/api-reference/queries/tokens) | Get metadata for multiple tokens |
|
|
351
|
+
| [`top10HoldersPercent`](https://docs.codex.io/api-reference/queries/top10holderspercent) | Get percentage held by top 10 wallets |
|
|
352
|
+
| [`getDetailedPairsStats`](https://docs.codex.io/api-reference/queries/getdetailedpairsstats) | Get detailed stats for multiple pairs |
|
|
353
|
+
| [`filterTokenWallets`](https://docs.codex.io/api-reference/queries/filtertokenwallets) | Get per-wallet trading stats (profit/loss, buy/sell counts) ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
354
|
+
| [`liquidityMetadata`](https://docs.codex.io/api-reference/queries/liquiditymetadata) | Get liquidity pool metadata ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
355
|
+
| [`tokenSparklines`](https://docs.codex.io/api-reference/queries/tokensparklines) | Get sparkline price data for tokens |
|
|
356
|
+
| [`filterWallets`](https://docs.codex.io/api-reference/queries/filterwallets) | Filter wallets by trading statistics ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
357
|
+
| [`detailedWalletStats`](https://docs.codex.io/api-reference/queries/detailedwalletstats) | Get comprehensive wallet analytics ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
358
|
+
| [`getExchanges`](https://docs.codex.io/api-reference/queries/getexchanges) | Get DEX information |
|
|
359
|
+
| [`getNetworks`](https://docs.codex.io/api-reference/queries/getnetworks) | List all 80+ supported networks |
|
|
360
|
+
| [`getTokenBars`](https://docs.codex.io/api-reference/queries/gettokenbars) | Get OHLCV data for a token across all pairs |
|
|
361
|
+
| [`chartUrls`](https://docs.codex.io/api-reference/queries/charturls) | Get pre-rendered chart image URLs ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
362
|
+
| [`walletChart`](https://docs.codex.io/api-reference/queries/walletchart) | Get wallet portfolio chart data ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
363
|
+
| [`filterExchanges`](https://docs.codex.io/api-reference/queries/filterexchanges) | Filter decentralized exchanges |
|
|
364
|
+
| [`liquidityLocks`](https://docs.codex.io/api-reference/queries/liquiditylocks) | Get liquidity lock information ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
365
|
+
| [`getNetworkConfigs`](https://docs.codex.io/api-reference/queries/getnetworkconfigs) | Get network configuration details |
|
|
366
|
+
| [`getNetworkStats`](https://docs.codex.io/api-reference/queries/getnetworkstats) | Get network-level statistics |
|
|
367
|
+
| [`getNetworkStatus`](https://docs.codex.io/api-reference/queries/getnetworkstatus) | Get network sync status |
|
|
368
|
+
| [`tokenLifecycleEvents`](https://docs.codex.io/api-reference/queries/tokenlifecycleevents) | Get token creation and migration events |
|
|
369
|
+
| [`blocks`](https://docs.codex.io/api-reference/queries/blocks) | Get block data by number or timestamp |
|
|
370
|
+
|
|
371
|
+
### Subscriptions (`sdk.subscriptions.*`) — [paid plan](https://dashboard.codex.io/dashboard/billing) required
|
|
372
|
+
|
|
373
|
+
| Method | Description |
|
|
374
|
+
| --- | --- |
|
|
375
|
+
| [`onPairMetadataUpdated`](https://docs.codex.io/api-reference/subscriptions/onpairmetadataupdated) | Live pair stat updates |
|
|
376
|
+
| [`onLaunchpadTokenEventBatch`](https://docs.codex.io/api-reference/subscriptions/onlaunchpadtokeneventbatch) | Batched launchpad events |
|
|
377
|
+
| [`onBarsUpdated`](https://docs.codex.io/api-reference/subscriptions/onbarsupdated) | Real-time OHLCV bars for a trading pair |
|
|
378
|
+
| [`onPriceUpdated`](https://docs.codex.io/api-reference/subscriptions/onpriceupdated) | Real-time price for a single token |
|
|
379
|
+
| [`onHoldersUpdated`](https://docs.codex.io/api-reference/subscriptions/onholdersupdated) | Live holder count and balance changes |
|
|
380
|
+
| [`onDetailedStatsUpdated`](https://docs.codex.io/api-reference/subscriptions/ondetailedstatsupdated) | Live detailed stats updates |
|
|
381
|
+
| [`onEventsCreated`](https://docs.codex.io/api-reference/subscriptions/oneventscreated) | Live buy/sell events for a pair |
|
|
382
|
+
| [`onPricesUpdated`](https://docs.codex.io/api-reference/subscriptions/onpricesupdated) | Real-time prices for multiple tokens |
|
|
383
|
+
| [`onUnconfirmedEventsCreated`](https://docs.codex.io/api-reference/subscriptions/onunconfirmedeventscreated) | Unconfirmed (mempool) trade events |
|
|
384
|
+
| [`onTokenEventsCreated`](https://docs.codex.io/api-reference/subscriptions/ontokeneventscreated) | Live events across all pools for a token |
|
|
385
|
+
| [`onLaunchpadTokenEvent`](https://docs.codex.io/api-reference/subscriptions/onlaunchpadtokenevent) | Individual launchpad events (Pump.fun, etc.) |
|
|
386
|
+
| [`onTokenBarsUpdated`](https://docs.codex.io/api-reference/subscriptions/ontokenbarsupdated) | Real-time OHLCV bars for a token |
|
|
387
|
+
| [`onLatestPairUpdated`](https://docs.codex.io/api-reference/subscriptions/onlatestpairupdated) | New trading pair creation events |
|
|
388
|
+
| [`onUnconfirmedBarsUpdated`](https://docs.codex.io/api-reference/subscriptions/onunconfirmedbarsupdated) | Unconfirmed bar updates |
|
|
389
|
+
| [`onEventsCreatedByMaker`](https://docs.codex.io/api-reference/subscriptions/oneventscreatedbymaker) | Live events for a specific wallet |
|
|
390
|
+
| [`onBalanceUpdated`](https://docs.codex.io/api-reference/subscriptions/onbalanceupdated) | Live wallet balance updates |
|
|
391
|
+
| [`onTokenLifecycleEventsCreated`](https://docs.codex.io/api-reference/subscriptions/ontokenlifecycleeventscreated) | Token lifecycle events |
|
|
392
|
+
| [`onLatestTokens`](https://docs.codex.io/api-reference/subscriptions/onlatesttokens) | New token creation events |
|
|
393
|
+
| [`onNftEventsCreated`](https://docs.codex.io/api-reference/subscriptions/onnfteventscreated) | NFT trade events |
|
|
394
|
+
|
|
395
|
+
### Mutations (`sdk.mutations.*`)
|
|
396
|
+
|
|
397
|
+
| Method | Description |
|
|
398
|
+
| --- | --- |
|
|
399
|
+
| [`createWebhooks`](https://docs.codex.io/api-reference/mutations/createwebhooks) | Create webhook alerts ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
400
|
+
| [`deleteWebhooks`](https://docs.codex.io/api-reference/mutations/deletewebhooks) | Delete webhook alerts ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
401
|
+
| [`backfillWalletAggregates`](https://docs.codex.io/api-reference/mutations/backfillwalletaggregates) | Trigger wallet data backfill ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
402
|
+
| [`createApiTokens`](https://docs.codex.io/api-reference/mutations/createapitokens) | Create short-lived API tokens for client-side use ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
403
|
+
| [`deleteApiToken`](https://docs.codex.io/api-reference/mutations/deleteapitoken) | Delete an API token ([paid](https://dashboard.codex.io/dashboard/billing)) |
|
|
404
|
+
| [`refreshBalances`](https://docs.codex.io/api-reference/mutations/refreshbalances) | Refresh wallet balances |
|
|
405
|
+
|
|
406
|
+
## Configuration
|
|
407
|
+
|
|
408
|
+
```typescript
|
|
218
409
|
import { Codex } from "@codex-data/sdk";
|
|
219
|
-
import { TokenRankingAttribute, RankingDirection } from "@codex-data/sdk/dist/sdk/generated/graphql";
|
|
220
|
-
```
|
|
221
410
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
411
|
+
const sdk = new Codex("YOUR_API_KEY", {
|
|
412
|
+
apiUrl: "https://graph.codex.io/graphql", // default
|
|
413
|
+
apiRealtimeUrl: "wss://graph.codex.io/graphql", // default
|
|
414
|
+
ws: true, // enable WebSocket (default: true)
|
|
415
|
+
});
|
|
226
416
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
import { Codex, GraphQL } from "@codex-data/sdk";
|
|
417
|
+
// Update config at runtime
|
|
418
|
+
sdk.updateConfig({ ws: false });
|
|
230
419
|
|
|
231
|
-
|
|
420
|
+
// Clean up WebSocket connection
|
|
421
|
+
sdk.dispose();
|
|
232
422
|
```
|
|
233
423
|
|
|
234
|
-
|
|
235
|
-
```tsx
|
|
236
|
-
import { Codex, QuoteToken } from "@codex-data/sdk";
|
|
424
|
+
## Examples
|
|
237
425
|
|
|
238
|
-
|
|
239
|
-
```
|
|
426
|
+
See the [examples](./examples) directory for full working projects:
|
|
240
427
|
|
|
241
|
-
|
|
428
|
+
- **[Simple](./examples/simple)** — Basic queries, filtering, and subscriptions
|
|
429
|
+
- **[Codegen](./examples/codegen)** — Using GraphQL Code Generator for fully typed custom queries
|
|
430
|
+
- **[Next.js](./examples/next)** — Full-stack web application
|
|
242
431
|
|
|
243
|
-
|
|
244
|
-
```tsx
|
|
245
|
-
const unsubscribeFn = codex.subscriptions.onLaunchpadTokenEventBatch(
|
|
246
|
-
{
|
|
247
|
-
networkId: networkId
|
|
248
|
-
}
|
|
249
|
-
)
|
|
250
|
-
```
|
|
432
|
+
## Contributing
|
|
251
433
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
)
|
|
434
|
+
We welcome contributions! Please feel free to submit a Pull Request.
|
|
435
|
+
|
|
436
|
+
```bash
|
|
437
|
+
pnpm install # Install dependencies
|
|
438
|
+
pnpm run build # Build the SDK
|
|
439
|
+
pnpm run test # Run tests
|
|
440
|
+
pnpm run lint # Lint the codebase
|
|
261
441
|
```
|
|
442
|
+
|
|
443
|
+
## Upgrading to v2
|
|
444
|
+
|
|
445
|
+
See [UPGRADING.md](./UPGRADING.md) for migration instructions from v1 to v2.
|
|
446
|
+
|
|
447
|
+
## Links
|
|
448
|
+
|
|
449
|
+
- [Codex API Documentation](https://docs.codex.io)
|
|
450
|
+
- [Popular Endpoints](https://docs.codex.io/api-reference/popular-endpoints)
|
|
451
|
+
- [GraphQL Explorer](https://explorer.codex.io)
|
|
452
|
+
- [Get an API Key](https://dashboard.codex.io)
|
|
453
|
+
- [Codex MCP Server](https://github.com/Codex-Data/codex-mcp)
|
|
454
|
+
- [Discord](https://discord.com/invite/mFpUhT3vAq)
|
|
455
|
+
- [Twitter](https://x.com/trycodex)
|
|
456
|
+
|
|
457
|
+
## License
|
|
458
|
+
|
|
459
|
+
MIT
|