Skip to content

Commit 3cd6a41

Browse files
committed
chore: cleanup ws subscriber v2 docs
1 parent 270b888 commit 3cd6a41

File tree

1 file changed

+2
-102
lines changed

1 file changed

+2
-102
lines changed

sdk/src/accounts/README_WebSocketAccountSubscriberV2.md

Lines changed: 2 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,7 @@ This is a new implementation of the WebSocket account subscriber that utilizes t
44

55
## Overview
66

7-
The `WebSocketAccountSubscriberV2` class provides the same interface as the original `WebSocketAccountSubscriber` but uses gill's modern JavaScript/TypeScript client library for Solana blockchain interactions.
8-
9-
## Key Benefits
10-
11-
1. **Modern Library**: Uses gill, which is built on top of Anza's `@solana/kit` (formerly web3.js v2)
12-
2. **Better Performance**: Optimized RPC calls and WebSocket subscriptions
13-
3. **Type Safety**: Full TypeScript support with better type definitions
14-
4. **Compatibility**: Drop-in replacement for existing `WebSocketAccountSubscriber`
15-
16-
## Installation
17-
18-
First, install the gill dependency:
19-
20-
```bash
21-
npm install gill
22-
```
7+
The `WebSocketAccountSubscriberV2` class provides the same interface as the original `WebSocketAccountSubscriber` but uses gill's modern TypeScript client library for Solana blockchain interactions.
238

249
## Usage
2510

@@ -42,9 +27,6 @@ await subscriber.subscribe((data) => {
4227
console.log('Account updated:', data);
4328
});
4429

45-
// Fetch initial data
46-
await subscriber.fetch();
47-
4830
// Unsubscribe when done
4931
await subscriber.unsubscribe();
5032
```
@@ -69,86 +51,4 @@ const { rpc, rpcSubscriptions } = createSolanaClient({
6951
2. **WebSocket Subscriptions**: Uses gill's `rpcSubscriptions` for real-time updates
7052
3. **Address Handling**: Converts `PublicKey` to gill's `Address` type for compatibility
7153
4. **Response Formatting**: Converts gill responses to match the expected `AccountInfo<Buffer>` format
72-
73-
### Fallback Implementation
74-
75-
The current implementation includes fallback code that uses the original web3.js methods when gill is not available. This ensures backward compatibility while the gill integration is being set up.
76-
77-
## Migration Guide
78-
79-
To migrate from `WebSocketAccountSubscriber` to `WebSocketAccountSubscriberV2`:
80-
81-
1. **Install gill**: `npm install gill`
82-
2. **Update imports**: Replace the import statement
83-
3. **Uncomment gill code**: Remove the TODO comments and uncomment the gill-specific code
84-
4. **Test thoroughly**: Ensure all functionality works as expected
85-
86-
## Example with Gill Integration
87-
88-
Here's how the implementation looks when fully integrated with gill:
89-
90-
```typescript
91-
// Constructor with gill initialization
92-
const rpcUrl = (this.program.provider as AnchorProvider).connection.rpcEndpoint;
93-
const { rpc, rpcSubscriptions } = createSolanaClient({
94-
urlOrMoniker: rpcUrl,
95-
});
96-
this.rpc = rpc;
97-
this.rpcSubscriptions = rpcSubscriptions;
98-
99-
// Subscribe using gill's WebSocket
100-
const accountAddress = this.accountPublicKey.toBase58() as Address;
101-
this.listenerId = this.rpcSubscriptions
102-
.accountNotifications(accountAddress)
103-
.subscribe(
104-
{
105-
commitment: this.commitment,
106-
encoding: 'base64',
107-
},
108-
(notification) => {
109-
this.handleRpcResponse(notification.context, notification.value);
110-
}
111-
);
112-
113-
// Fetch using gill's RPC
114-
const rpcResponse = await this.rpc
115-
.getAccountInfo(accountAddress, {
116-
commitment: this.commitment,
117-
encoding: 'base64',
118-
})
119-
.send();
120-
```
121-
122-
## Benefits of Using Gill
123-
124-
1. **Performance**: Better connection management and optimized RPC calls
125-
2. **Reliability**: Improved error handling and reconnection logic
126-
3. **Modern APIs**: Uses the latest Solana JavaScript client libraries
127-
4. **Type Safety**: Better TypeScript support and type definitions
128-
5. **Future-Proof**: Built on the foundation of Solana's modern tooling
129-
130-
## Troubleshooting
131-
132-
### Common Issues
133-
134-
1. **Module not found**: Ensure gill is installed: `npm install gill`
135-
2. **Type errors**: Make sure TypeScript can find gill's type definitions
136-
3. **Connection issues**: Verify the RPC URL is accessible and supports WebSocket connections
137-
138-
### Debug Mode
139-
140-
Gill supports debug mode for troubleshooting:
141-
142-
```typescript
143-
// Enable debug mode
144-
process.env.GILL_DEBUG = 'true';
145-
146-
// Or in browser console
147-
window.__GILL_DEBUG__ = true;
148-
```
149-
150-
## References
151-
152-
- [Gill NPM Package](https://www.npmjs.com/package/gill)
153-
- [Gill GitHub Repository](https://github.com/solana-foundation/gill)
154-
- [Solana Kit Documentation](https://kit.solana.com/)
54+
5. **Abort Signal**: Utilizes AbortSignal nodejs/web class to shutdown websocket connection synchronously

0 commit comments

Comments
 (0)