UNPKG

@msquared/etherbase-client

Version:

React hooks for interacting with Etherbase smart contracts

57 lines (56 loc) 2 kB
import type { Address } from "viem"; import type { EtherbaseEvent, Event } from "./types/events"; import type { EtherstoreState, StateSubscriptionOptions } from "./types/state"; import type { WebSocketStateUpdateInner } from "./types/websocket"; type EventSubscription = { contractAddress?: Address; events?: Event[]; onEvent: (event: EtherbaseEvent) => void; }; type StateSubscription = { contractAddress: Address; statePath: (string | string[])[]; options: StateSubscriptionOptions; onStateUpdate: (update: WebSocketStateUpdateInner) => void; }; export declare class WebSocketManager { private static instance; static get(): WebSocketManager; private ws; private dead; /** A map from localId -> SubscriptionStatus. */ private subscriptions; private readonly privateKey?; private writerWs; private readerWs; private readonly readerUrl; private readonly writerUrl; private constructor(); /** Connect if not open or connecting */ private connectReader; private connectWriter; private handleMessage; private handleWriterMessage; private handleUpdates; addEventSubscription(localId: string, subscription: EventSubscription): Promise<void>; addStateSubscription(localId: string, subscription: StateSubscription): Promise<void>; removeSubscription(localId: string): void; private sendSubscribe; getSubscriptionError(localId: string): string | undefined; forceClose(): void; setValue({ contractAddress, state, }: { contractAddress: Address; state: EtherstoreState; }): Promise<void>; emitEvent({ sourceAddress, name, args, }: { sourceAddress: Address; name: string; args: Record<string, unknown>; }): Promise<void>; executeContractMethod({ contractAddress, methodName, args, }: { contractAddress: Address; methodName: string; args: Record<string, unknown>; }): Promise<void>; } export {};