abstractSocketProvider <MessageEvent, CloseEvent, ErrorEvent, API>
Hierarchy
- Eip1193Provider<API>
- SocketProvider
Index
Constructors
publicconstructor
This is an abstract class for implementing a socket provider (e.g. WebSocket, IPC). It extends the EIP-1193 provider EIP1193Provider.
Type parameters
- MessageEvent
- CloseEvent
- ErrorEvent
- API: unknown = EthExecutionAPI
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
Returns unknown
[symbol]
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 (>= 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.
Returns Eip1193Compatible<API>
A new instance of the provider with the request method fully compatible with EIP-1193
publicclearQueues
Parameters
optionalevent: ConnectionEvent
Returns void
publicconnect
Try to establish a connection to the socket
Returns void
publicdisconnect
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
Returns number
the pendingRequestQueue size
publicgetSentRequestsQueueSize
Returns number
the sendPendingRequests size
abstractgetStatus
Returns Web3ProviderStatus
publicon
Registers a listener for the specified event type.
Parameters
type: disconnect
The event type to listen for
listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>
The callback to be invoked when the event is emitted
Returns void
publiconce
Registers a listener for the specified event type that will be invoked at most once.
Parameters
type: disconnect
The event type to listen for
listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>
The callback to be invoked when the event is emitted
Returns void
publicremoveAllListeners
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
type: disconnect
The event type to remove the listener for
listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>
The callback to be executed
Returns void
publicrequest
Creates a request object to be sent to the server
Type parameters
- Method: string
- ResultType = Web3APIReturnType<API, Method>
Parameters
request: Web3APIPayload<API, Method>
Returns Promise<JsonRpcResponseWithResult<ResultType>>
publicreset
Resets the socket, removing all listeners and pending requests
Returns void
publicsafeDisconnect
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
Type parameters
- ResultType = JsonRpcResult
- P = unknown
Parameters
payload: JsonRpcPayload<P>
Request Payload
callback: (err: null | Error, response?: JsonRpcResponse<ResultType, JsonRpcResult>) => void
Callback
Returns void
sendAsync
Type parameters
- R = JsonRpcResult
- P = unknown
Parameters
payload: JsonRpcPayload<P>
Request Payload
Returns Promise<JsonRpcResponse<R, JsonRpcResult>>
publicsupportsSubscriptions
Returns boolean
true
if the socket supports subscriptions
staticisWeb3Provider
Parameters
provider: unknown
Returns boolean
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.