Skip to main content
Version: 11.x

Interface: RpcTransport

Defined in: src/channel/transport/types.ts:26

Carries JSON-RPC envelopes to a node and back, without knowing what the methods mean.

The seam sits at the envelope rather than at HTTP, so an implementation is free to use fetch, a WebSocket, or anything else. Everything above it — the versioned RpcChannel, RpcProvider, Account, Contract — is unaware of which one is in use.

Resolution versus rejection. request resolves with whatever the node answered, error envelopes included: a { error: { code, message } } reply is a completed round trip as far as the transport is concerned, and it is the channel's errorHandler that turns it into a typed RpcError. request rejects only when no answer could be obtained — unreachable node, closed connection, timeout. Application code must see the same errors on every transport.

Id transparency. A transport may rewrite ids on the wire — a connection shared by several channels needs its own counter, since each channel starts numbering at 0 and two of them would otherwise both emit 1 — but the envelope it resolves with MUST carry the id the caller sent. BatchClient correlates its replies on that id. Note that request ids and subscription ids are two different spaces: subscription ids come from the node as decimal strings that routinely exceed Number.MAX_SAFE_INTEGER, and must never be coerced to a number.

Batches. An array in yields an array out. The node may answer in any order, so callers correlate on the id rather than on position.

Methods

request()

Call Signature

request(body): Promise<ResponseBody>

Defined in: src/channel/transport/types.ts:42

Sends one JSON-RPC envelope, or a batch of them, and resolves with the node's answer.

Parameters
body

RequestBody

A request envelope, or an array of them for a batch.

Returns

Promise<ResponseBody>

The matching response envelope, or an array of them — error envelopes included, see the resolution-versus-rejection rule above.

Example
const answer = await transport.request({
jsonrpc: '2.0',
id: 1,
method: 'starknet_blockNumber',
params: [],
});

Call Signature

request(body): Promise<ResponseBody[]>

Defined in: src/channel/transport/types.ts:43

Parameters
body

RequestBody[]

Returns

Promise<ResponseBody[]>