Transport.ipc
A transport over a node’s IPC socket, for a node on the same machine. It serves calls and subscriptions on one connection and reconnects when it drops.
import { NodeSocket } from "@effect/platform-node";import { Effect, Layer } from "effect";import { Transport } from "@ethect/core";import { Eth } from "@ethect/core/rpc";
const Ipc = Transport.ipc().pipe( Layer.provide(NodeSocket.layerNet({ path: "/tmp/anvil.ipc" })),);
const block = await Eth.blockNumber().pipe(Effect.provide(Ipc), Effect.runPromise);Opening a socket is the platform’s job, so the transport takes no path: the Socket layer
does. On Node it is NodeSocket.layerNet from @effect/platform-node.
Start anvil with a socket to try it:
anvil --ipc /tmp/anvil.ipcSubscriptions
Section titled “Subscriptions”An IPC connection can push, so subscriptions work as over WebSocket.
import { NodeSocket } from "@effect/platform-node";import { Effect, Layer, Stream } from "effect";import { Transport } from "@ethect/core";import { Eth } from "@ethect/core/rpc";
const Ipc = Transport.ipc().pipe( Layer.provide(NodeSocket.layerNet({ path: "/tmp/anvil.ipc" })),);
const nextThree = await Eth.subscribe.newHeads().pipe( Stream.map((head) => head.number), Stream.take(3), Stream.runCollect, Effect.provide(Ipc), Effect.runPromise,);Returns
Section titled “Returns”Layer<Transport | Subscriptions, never, Socket>
A layer that provides Transport and
Subscriptions, and needs a Socket from
effect/socket.
Parameters
Section titled “Parameters”options (optional)
Section titled “options (optional)”- Type:
Transport.SocketOptions
| Field | Type | Default | Description |
|---|---|---|---|
reconnect |
a Schedule |
exponential backoff from 500 ms, capped at 5 s, forever | The pauses between attempts to connect, after one fails or a connection ends within 5 seconds of opening. When the schedule ends, the transport gives up. |
keepAlive |
a Duration input, or false |
off | How often net_version is called to check the connection. |
import { NodeSocket } from "@effect/platform-node";import { Layer, Schedule } from "effect";import { Transport } from "@ethect/core";
const Ipc = Transport.ipc({ reconnect: Schedule.max([Schedule.spaced("1 second"), Schedule.recurs(10)]),}).pipe(Layer.provide(NodeSocket.layerNet({ path: "/tmp/anvil.ipc" })));Behavior
Section titled “Behavior”- Same connection rules as WebSocket. Calls in flight fail with
ConnectionLostwhen the socket closes, a connection that lasted 5 seconds or more is replaced at once, calls fail at once withUnreachablewhile the node cannot be reached, and subscriptions are issued again after a reconnection. SeeTransport.webSocket. - No keep-alive by default. Set
keepAliveto add one. - Framing. Each request is one JSON text followed by a newline. Answers are split on the boundaries of JSON values, so a value cut across two chunks or several values in one chunk are both read correctly.
Errors
Section titled “Errors”The same as Transport.webSocket: Unreachable,
ConnectionLost, MalformedResponse and Unserializable.