Skip to main content

IpcProvider <API>

The IPC Provider could be used in node.js dapps when running a local node. And it provide the most secure connection.

@example
const provider = new IpcProvider(
`path.ipc`,
{
writable: false,
},
{
delay: 500,
autoReconnect: true,
maxAttempts: 10,
},
);

The second and the third parameters are both optional. And you can for example, the second parameter could be an empty object or undefined. *

@example
const provider = new IpcProvider(
`path.ipc`,
{},
{
delay: 500,
autoReconnect: true,
maxAttempts: 10,
},
);

Hierarchy

  • SocketProvider<Uint8Array | string, CloseEvent, Error, API>
    • IpcProvider

Index

Constructors

publicconstructor

  • new IpcProvider<API>(socketPath: string, socketOptions?: SocketConstructorOpts, reconnectOptions?: Partial<ReconnectOptions>): default<API>
  • This is a class used for IPC connections. It extends the abstract class SocketProvider SocketProvider that extends the EIP-1193 provider EIP1193Provider.


    Type parameters

    Parameters

    • socketPath: string

      The path to the IPC socket.

    • optionalsocketOptions: SocketConstructorOpts

      The options for the IPC socket connection.

    • optionalreconnectOptions: Partial<ReconnectOptions>

      The options for the socket reconnection ReconnectOptions

    Returns default<API>

Accessors

SocketConnection

  • 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

clearQueues

  • Parameters

    Returns void

connect

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


    Returns void

disconnect

  • 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

getPendingRequestQueueSize

  • getPendingRequestQueueSize(): number

  • Returns number

    the pendingRequestQueue size

getSentRequestsQueueSize

  • getSentRequestsQueueSize(): number

  • Returns number

    the sendPendingRequests size

publicgetStatus

on

  • Registers a listener for the specified event type.


    Parameters

    Returns void

once

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


    Parameters

    Returns void

removeAllListeners

  • 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

removeListener

  • Removes a listener for the specified event type.


    Parameters

    Returns void

request

reset

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


    Returns void

safeDisconnect

  • 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

    • optionalforceDisconnect: boolean

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

    • optionalms: number

      Determines the ms of setInterval

    Returns Promise<void>

send

  • @deprecated

    Please use .request instead.


    Type parameters

    Parameters

    Returns void

sendAsync

supportsSubscriptions

  • supportsSubscriptions(): boolean

  • Returns boolean

    true if the socket supports subscriptions

staticisWeb3Provider

  • isWeb3Provider(provider: unknown): boolean
  • Parameters

    • provider: unknown

    Returns boolean