gennet.js 0.2.0 → 0.2.1
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 +32 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ Client library for [GenNet](https://github.com/cryptagoEU/gennet.js) — interac
|
|
|
15
15
|
- WebSocket & HTTP providers
|
|
16
16
|
- Full TypeScript support (ESM + CJS)
|
|
17
17
|
- Subscriptions (logs, messages, mempool)
|
|
18
|
+
- Auto-reconnect with exponential backoff
|
|
19
|
+
- Connection events (connect, disconnect, error)
|
|
18
20
|
|
|
19
21
|
## Installation
|
|
20
22
|
|
|
@@ -53,12 +55,20 @@ const gennet = new GenNet('ws://localhost:18789');
|
|
|
53
55
|
const gennet = new GenNet('http://localhost:18790');
|
|
54
56
|
```
|
|
55
57
|
|
|
56
|
-
You can also pass a custom provider:
|
|
58
|
+
You can also pass a custom provider with options:
|
|
57
59
|
|
|
58
60
|
```typescript
|
|
59
61
|
import { GenNet, WebSocketProvider } from 'gennet.js';
|
|
60
62
|
|
|
61
|
-
const provider = new WebSocketProvider('ws://localhost:18789'
|
|
63
|
+
const provider = new WebSocketProvider('ws://localhost:18789', {
|
|
64
|
+
timeout: 10_000,
|
|
65
|
+
reconnect: {
|
|
66
|
+
enabled: true, // default: true
|
|
67
|
+
maxRetries: 10, // default: 5
|
|
68
|
+
delay: 2000, // default: 1000ms (doubles each attempt)
|
|
69
|
+
maxDelay: 60_000, // default: 30000ms
|
|
70
|
+
},
|
|
71
|
+
});
|
|
62
72
|
const gennet = new GenNet(provider);
|
|
63
73
|
```
|
|
64
74
|
|
|
@@ -123,6 +133,26 @@ For methods not covered by the namespaces:
|
|
|
123
133
|
const result = await gennet.request('custom_method', { key: 'value' });
|
|
124
134
|
```
|
|
125
135
|
|
|
136
|
+
## Events
|
|
137
|
+
|
|
138
|
+
The WebSocket provider emits connection lifecycle events:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
gennet.on('connect', () => {
|
|
142
|
+
console.log('Connected to GenNet node');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
gennet.on('disconnect', () => {
|
|
146
|
+
console.log('Disconnected — reconnecting...');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
gennet.on('error', (err) => {
|
|
150
|
+
console.error('Connection error:', err.message);
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Auto-reconnect is enabled by default. After a disconnect, the provider reconnects with exponential backoff. Call `gennet.disconnect()` to stop reconnecting.
|
|
155
|
+
|
|
126
156
|
## Error Handling
|
|
127
157
|
|
|
128
158
|
RPC errors throw a typed `RpcError`:
|