Class: Events
Service for handling real-time event streaming and socket connections. Manages the global socket connection for transaction status updates.
Constructors
Constructor
new Events(): Events;
Returns
Events
Properties
instance
readonly static instance: Events;
tradeEventEmitterConstructor()
static tradeEventEmitterConstructor: (url) => TradeEventEmitter = EventSocketClient;
Parameters
| Parameter | Type |
|---|---|
url | string |
Returns
TradeEventEmitter
Methods
connectEventSocket()
connectEventSocket(bundlerBaseUrl?): Promise<TradeEventEmitter>;
Establishes a global socket connection for real-time event streaming. This connection is shared across all service instances.
Parameters
| Parameter | Type | Description |
|---|---|---|
bundlerBaseUrl? | string | Optional bundler base URL. If not provided, uses default. |
Returns
Promise<TradeEventEmitter>
The connected EventSocketClient.
Example
await eventsService.connectEventSocket();
// Socket is now available for transaction updates
disconnectEventSocket()
disconnectEventSocket(): void;
Disconnects the global socket connection and cleans up resources.
Returns
void
eventSocketConnected()
eventSocketConnected(): boolean;
Checks if the global socket connection is active.
Returns
boolean
True if connected, false otherwise.
registerTxId()
registerTxId(txId, timeoutMs): void;
Registers a transaction ID for waiting and timeout handling.
Parameters
| Parameter | Type | Description |
|---|---|---|
txId | string | The transaction ID to register. |
timeoutMs | number | Timeout in milliseconds. |
Returns
void
wait()
wait(txId): Promise<{
Data: Record<string, unknown>;
transactionHash: string;
txId: string;
}>;
Waits for a transaction to complete.
Parameters
| Parameter | Type | Description |
|---|---|---|
txId | string | The transaction ID to wait for. |
Returns
Promise<{
Data: Record<string, unknown>;
transactionHash: string;
txId: string;
}>
Promise that resolves when the transaction completes.