PERS SDK - v2.3.26 / Exports / WalletEventsManager
Wallet Events Manager - Manages real-time blockchain event subscriptions
Low-level WS client wrapper. For auto-subscription based on auth type, use sdk.connectWalletEvents() which handles subscription automatically.
- connect
- disconnect
- destroy
- subscribeWallets
- subscribeChains
- unsubscribeWallets
- unsubscribeChains
- getSubscriptionState
- bindNotificationChannel
- updateNotificationChannel
- getNotificationContext
- onNotificationPending
- on
- onStateChange
- getState
- isConnected
- hasReconnectGivenUp
- retryAfterTokenRefresh
- getConnectionInfo
• new WalletEventsManager(apiClient, eventEmitter, config?): WalletEventsManager
| Name | Type |
|---|---|
apiClient | PersApiClient |
eventEmitter | PersEventEmitter |
config? | WalletEventsConfig |
▸ connect(): Promise<void>
Connect to real-time wallet events
Establishes WebSocket connection to the WS relay server. After connecting, call subscribeWallets() or subscribeChains() to start receiving events.
For auto-subscription, use sdk.connectWalletEvents() instead.
Promise<void>
managers/events-manager.ts:118
▸ disconnect(): void
Disconnect from real-time events
void
managers/events-manager.ts:236
▸ destroy(): void
Full cleanup - disconnect and remove all subscriptions including auth listener Call this when completely done with the manager (e.g., SDK disposal)
void
managers/events-manager.ts:251
▸ subscribeWallets(wallets): Promise<SubscribedPayload>
Subscribe to wallet events
Receives events only for the specified wallet addresses. Use this for user-facing SDK where you want to monitor specific wallets.
| Name | Type | Description |
|---|---|---|
wallets | WalletInfo[] | Array of wallet info (address + chainId) |
Promise<SubscribedPayload>
Promise that resolves when subscription is confirmed
Example
await sdk.walletEvents.connect();
await sdk.walletEvents.subscribeWallets([
{ address: '0x123...', chainId: 39123 }
]);managers/events-manager.ts:282
▸ subscribeChains(chains): Promise<SubscribedPayload>
Subscribe to chain events (Admin Dashboard)
Receives ALL events on the specified chains. Use for admin dashboards that need to monitor all activity.
| Name | Type | Description |
|---|---|---|
chains | number[] | Array of chain IDs to subscribe to |
Promise<SubscribedPayload>
Promise that resolves when subscription is confirmed
Example
await sdk.walletEvents.connect();
await sdk.walletEvents.subscribeChains([39123, 137]);managers/events-manager.ts:307
▸ unsubscribeWallets(wallets): Promise<SubscribedPayload>
Unsubscribe from wallet events
| Name | Type | Description |
|---|---|---|
wallets | WalletInfo[] | Array of wallet info to unsubscribe from |
Promise<SubscribedPayload>
Promise that resolves when unsubscription is confirmed
managers/events-manager.ts:323
▸ unsubscribeChains(chains): Promise<SubscribedPayload>
Unsubscribe from chain events
| Name | Type | Description |
|---|---|---|
chains | number[] | Array of chain IDs to unsubscribe from |
Promise<SubscribedPayload>
Promise that resolves when unsubscription is confirmed
managers/events-manager.ts:336
▸ getSubscriptionState(): SubscribedPayload
Get current subscription state
SubscribedPayload
managers/events-manager.ts:346
▸ bindNotificationChannel(channelId, topicIds?): void
Bind this socket to a personal notification channelId (from sdk.notifications.getChannelId()). Safe to call before or after connect() — queued and sent once the socket is open.
| Name | Type |
|---|---|
channelId | string |
topicIds? | string[] |
void
managers/events-manager.ts:358
▸ updateNotificationChannel(channelId): void
Rebind the personal notification channelId on an already-connected socket.
| Name | Type |
|---|---|
channelId | string |
void
managers/events-manager.ts:366
▸ getNotificationContext(): NotificationContext
Get the notification routing context (channelId + topicIds) resolved for this socket.
managers/events-manager.ts:374
▸ onNotificationPending(handler): BlockchainEventUnsubscribe
Subscribe to real-time notification wake signals (notification.pending). The signal carries no content — always follow up with sdk.notifications.list().
| Name | Type |
|---|---|
handler | NotificationPendingHandler |
BlockchainEventUnsubscribe
managers/events-manager.ts:382
▸ on(eventType, handler): BlockchainEventUnsubscribe
Subscribe to blockchain events
| Name | Type | Description |
|---|---|---|
eventType | string | Event type ('Transfer', 'Approval', etc.) or '*' for all |
handler | BlockchainEventHandler | Callback function when event is received |
BlockchainEventUnsubscribe
Unsubscribe function
Example
const unsub = sdk.walletEvents.on('Transfer', (event) => {
console.log(`Transfer: ${event.data.from} -> ${event.data.to}`);
});
// Later: stop listening
unsub();managers/events-manager.ts:416
▸ onStateChange(handler): BlockchainEventUnsubscribe
Subscribe to connection state changes
| Name | Type |
|---|---|
handler | (state: EventConnectionState) => void |
BlockchainEventUnsubscribe
managers/events-manager.ts:434
▸ getState(): EventConnectionState
Get current connection state
EventConnectionState
managers/events-manager.ts:444
▸ isConnected(): boolean
Check if connected
boolean
managers/events-manager.ts:451
▸ hasReconnectGivenUp(): boolean
Check if WS reconnection gave up (exhausted all attempts) Used to determine if we should retry on token refresh
boolean
managers/events-manager.ts:459
▸ retryAfterTokenRefresh(): Promise<void>
Retry connection after token refresh Called when auth tokens are refreshed and WS had previously given up Automatically resubscribes to previous subscriptions
Promise<void>
managers/events-manager.ts:468
▸ getConnectionInfo(): undefined | null | { userId: string ; wallets: WalletInfo[] ; activeChains: number[] }
Get connection info (wallets, active chains)
undefined | null | { userId: string ; wallets: WalletInfo[] ; activeChains: number[] }