Skip to main content

abstractSocketProvider <MessageEvent, CloseEvent, ErrorEvent, API>

This is an abstract class, which extends Web3BaseProvider class. This class is used to implement a provider that adheres to the EIP-1193 standard for Ethereum providers.

Hierarchy

Index

Constructors

publicconstructor

  • new SocketProvider<MessageEvent, CloseEvent, ErrorEvent, API>(socketPath: string, socketOptions?: unknown, reconnectOptions?: Partial<ReconnectOptions>): SocketProvider<MessageEvent, CloseEvent, ErrorEvent, API>
  • This is an abstract class for implementing a socket provider (e.g. WebSocket, IPC). It extends the EIP-1193 provider EIP1193Provider.


    Type parameters

    Parameters

    • socketPath: string

      The path to the socket (e.g. /ipc/path or ws://localhost:8546)

    • optionalsocketOptions: unknown

      The options for the socket connection. Its type is supposed to be specified in the inherited classes.

    • optionalreconnectOptions: Partial<ReconnectOptions>

      The options for the socket reconnection ReconnectOptions

    Returns SocketProvider<MessageEvent, CloseEvent, ErrorEvent, API>

Accessors

publicSocketConnection

  • get SocketConnection(): unknown
  • Returns unknown

[symbol]

  • get [symbol](): boolean
  • Returns boolean

Methods

asEIP1193Provider

  • Modify the return type of the request method to be fully compatible with EIP-1193

    [deprecated] In the future major releases (&gt;= v5) all providers are supposed to be fully compatible with EIP-1193. So this method will not be needed and would not be available in the future.

    @example
    const provider = new Web3HttpProvider('http://localhost:8545');
    const fullyCompatibleProvider = provider.asEIP1193Provider();
    const result = await fullyCompatibleProvider.request({ method: 'eth_getBalance' });
    console.log(result); // '0x0234c8a3397aab58' or something like that

    Returns Eip1193Compatible<API>

    A new instance of the provider with the request method fully compatible with EIP-1193

publicclearQueues

publicconnect

  • connect(): void
  • Try to establish a connection to the socket


    Returns void

publicdisconnect

  • disconnect(code?: number, data?: string): void
  • Disconnects the socket


    Parameters

    • optionalcode: number

      The code to be sent to the server

    • optionaldata: string

      The data to be sent to the server

    Returns void

publicgetPendingRequestQueueSize

  • getPendingRequestQueueSize(): number

  • Returns number

    the pendingRequestQueue size

publicgetSentRequestsQueueSize

  • getSentRequestsQueueSize(): number

  • Returns number

    the sendPendingRequests size

abstractgetStatus

publicon

  • Registers a listener for the specified event type.


    Parameters

    Returns void

publiconce

  • Registers a listener for the specified event type that will be invoked at most once.


    Parameters

    Returns void

publicremoveAllListeners

  • removeAllListeners(type: string): void
  • Removes all listeners for the specified event type.


    Parameters

    • type: string

      The event type to remove the listeners for

    Returns void

publicremoveListener

  • Removes a listener for the specified event type.


    Parameters

    Returns void

publicrequest

publicreset

  • reset(): void
  • Resets the socket, removing all listeners and pending requests


    Returns void

publicsafeDisconnect

  • safeDisconnect(code?: number, data?: string, forceDisconnect?: boolean, ms?: number): Promise<void>
  • Safely disconnects the socket, async and waits for request size to be 0 before disconnecting


    Parameters

    • optionalcode: number

      The code to be sent to the server

    • optionaldata: string

      The data to be sent to the server

    • forceDisconnect: boolean = false

      If true, will clear queue after 5 attempts of waiting for both pending and sent queue to be 0

    • ms: number = 1000

      Determines the ms of setInterval

    Returns Promise<void>

send

  • @deprecated

    Please use .request instead.


    Type parameters

    Parameters

    Returns void

sendAsync

publicsupportsSubscriptions

  • supportsSubscriptions(): boolean

  • Returns boolean

    true if the socket supports subscriptions

staticisWeb3Provider

  • isWeb3Provider(provider: unknown): boolean
  • Parameters

    • provider: unknown

    Returns boolean