@direct.dev/sdk 1.0.1 → 1.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 +36 -12
- package/lib/index.cjs +3 -3
- package/lib/index.d.ts +6 -0
- package/lib/index.mjs +3 -3
- package/package.json +13 -14
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ import { install } from "@direct.dev/sdk";
|
|
|
47
47
|
|
|
48
48
|
install();
|
|
49
49
|
|
|
50
|
-
const res = await fetch("https://rpc.direct.dev/v1/<
|
|
50
|
+
const res = await fetch("https://rpc.direct.dev/v1/<project>.<token>/ethereum", {
|
|
51
51
|
method: "POST",
|
|
52
52
|
headers: { "Content-Type": "application/json" },
|
|
53
53
|
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "eth_blockNumber", params: [] }),
|
|
@@ -78,7 +78,7 @@ const directFetch = createFetch({
|
|
|
78
78
|
logging: { client: "info" },
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
-
const res = await directFetch("https://rpc.direct.dev/v1/<
|
|
81
|
+
const res = await directFetch("https://rpc.direct.dev/v1/<project>.<token>/ethereum", {
|
|
82
82
|
method: "POST",
|
|
83
83
|
headers: { "Content-Type": "application/json" },
|
|
84
84
|
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "eth_blockNumber", params: [] }),
|
|
@@ -102,7 +102,7 @@ install();
|
|
|
102
102
|
|
|
103
103
|
const client = createPublicClient({
|
|
104
104
|
chain: mainnet,
|
|
105
|
-
transport: http("https://rpc.direct.dev/v1/<
|
|
105
|
+
transport: http("https://rpc.direct.dev/v1/<project>.<token>/ethereum"),
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
await client.getBlockNumber();
|
|
@@ -119,7 +119,7 @@ const directFetch = createFetch({ logging: { client: "info" } });
|
|
|
119
119
|
|
|
120
120
|
const client = createPublicClient({
|
|
121
121
|
chain: mainnet,
|
|
122
|
-
transport: http("https://rpc.direct.dev/v1/<
|
|
122
|
+
transport: http("https://rpc.direct.dev/v1/<project>.<token>/ethereum", {
|
|
123
123
|
fetch: directFetch,
|
|
124
124
|
}),
|
|
125
125
|
});
|
|
@@ -136,7 +136,7 @@ In the browser, prefer an HTML preload link. It lets the browser start fetching
|
|
|
136
136
|
rel="preload"
|
|
137
137
|
as="fetch"
|
|
138
138
|
crossorigin="anonymous"
|
|
139
|
-
href="https://rpc.direct.dev/v1/<
|
|
139
|
+
href="https://rpc.direct.dev/v1/<project>.<token>/ethereum"
|
|
140
140
|
/>
|
|
141
141
|
```
|
|
142
142
|
|
|
@@ -145,8 +145,8 @@ On the server, or in environments without preload links, pass `preload` to `inst
|
|
|
145
145
|
```ts
|
|
146
146
|
install({
|
|
147
147
|
preload: [
|
|
148
|
-
"https://rpc.direct.dev/v1/<
|
|
149
|
-
"https://rpc.direct.dev/v1/<
|
|
148
|
+
"https://rpc.direct.dev/v1/<project>.<token>/ethereum",
|
|
149
|
+
"https://rpc.direct.dev/v1/<project>.<token>/sonic",
|
|
150
150
|
],
|
|
151
151
|
});
|
|
152
152
|
```
|
|
@@ -199,7 +199,7 @@ The `logging` option covers three independent concerns:
|
|
|
199
199
|
| `silent` | Nothing. |
|
|
200
200
|
| `error` | Errors only. `[direct:ERROR] Batch contains duplicate request IDs { ids: [1, 1] }` |
|
|
201
201
|
| `warn` | Errors + warnings. `[direct:WARN] Request failed { input: ..., err: ... }` |
|
|
202
|
-
| `info` |
|
|
202
|
+
| `info` | Sparse operational summaries, including live sync connection state. |
|
|
203
203
|
| `debug` | Full lifecycle: preload, sync, client phases. |
|
|
204
204
|
|
|
205
205
|
Example debug output:
|
|
@@ -215,6 +215,27 @@ Example debug output:
|
|
|
215
215
|
client_instance_id: "client_ethereum_f47ac10b_1",
|
|
216
216
|
network_id: "ethereum"
|
|
217
217
|
}
|
|
218
|
+
[direct:INFO] sync.connection {
|
|
219
|
+
client_instance_id: "client_ethereum_f47ac10b_1",
|
|
220
|
+
network_id: "ethereum",
|
|
221
|
+
connected: true,
|
|
222
|
+
transport: "wire_socket",
|
|
223
|
+
reason: "started"
|
|
224
|
+
}
|
|
225
|
+
[direct:INFO] sync.ready {
|
|
226
|
+
client_instance_id: "client_ethereum_f47ac10b_1",
|
|
227
|
+
network_id: "ethereum",
|
|
228
|
+
ready: true,
|
|
229
|
+
transport: "wire_socket",
|
|
230
|
+
reason: "block_state_available",
|
|
231
|
+
current_block_height: "0x134a1c0"
|
|
232
|
+
}
|
|
233
|
+
[direct:INFO] block.advanced {
|
|
234
|
+
client_instance_id: "client_ethereum_f47ac10b_1",
|
|
235
|
+
network_id: "ethereum",
|
|
236
|
+
source: "wire_socket",
|
|
237
|
+
current_block_height: "0x134a1c1"
|
|
238
|
+
}
|
|
218
239
|
```
|
|
219
240
|
|
|
220
241
|
### `logging.requests`
|
|
@@ -289,6 +310,9 @@ type LogEvent = {
|
|
|
289
310
|
- `preload.phase`
|
|
290
311
|
- `preload.clock_sync`
|
|
291
312
|
- `sync.rebuild`
|
|
313
|
+
- `sync.connection`
|
|
314
|
+
- `sync.ready`
|
|
315
|
+
- `block.advanced`
|
|
292
316
|
- `client.phase`
|
|
293
317
|
|
|
294
318
|
**Debug-only diagnostics** — only emitted when the relevant log level is active:
|
|
@@ -304,7 +328,7 @@ The SDK exports `LogEvent`, `LoggingOptions`, and `CreateFetchOptions` for typed
|
|
|
304
328
|
The SDK intercepts a special JSON-RPC method, `direct_client_status`, and answers it locally without touching the network. Useful for debugging your integration:
|
|
305
329
|
|
|
306
330
|
```ts
|
|
307
|
-
const res = await fetch("https://rpc.direct.dev/v1/<
|
|
331
|
+
const res = await fetch("https://rpc.direct.dev/v1/<project>.<token>/ethereum", {
|
|
308
332
|
method: "POST",
|
|
309
333
|
headers: { "Content-Type": "application/json" },
|
|
310
334
|
body: JSON.stringify({
|
|
@@ -330,9 +354,9 @@ const { result } = await res.json();
|
|
|
330
354
|
|
|
331
355
|
The SDK only takes over POST requests whose body is JSON-RPC and whose URL matches a Direct.dev RPC endpoint:
|
|
332
356
|
|
|
333
|
-
- `https://rpc.direct.dev/v1/<
|
|
334
|
-
- `https://staging.rpc.direct.dev/v1/<
|
|
335
|
-
- `https://prod.rpc.direct.dev/v1/<
|
|
357
|
+
- `https://rpc.direct.dev/v1/<project>.<token>/<network>`
|
|
358
|
+
- `https://staging.rpc.direct.dev/v1/<project>.<token>/<network>`
|
|
359
|
+
- `https://prod.rpc.direct.dev/v1/<project>.<token>/<network>`
|
|
336
360
|
|
|
337
361
|
## License
|
|
338
362
|
|