Skip to main content
Version: 11.x

Class: SubscriptionChannel

Defined in: src/channel/v0_9/index.ts:12

Verified against the installed type packages: starknet-types-09 and starknet-types-0103 expose the same five subscription method names. Params and result types differ; the method set does not. So this is a trivial extends, and the axis exists for the day a version adds one.

Extends

Constructors

Constructor

new SubscriptionChannel(options): SubscriptionChannel

Defined in: src/channel/ws/subscriptionChannel.ts:115

Parameters

options

SubscriptionChannelOptions

Returns

SubscriptionChannel

Inherited from

SubscriptionChannel.constructor

Properties

id

readonly id: "RPC0.9.0-subscriptions" = 'RPC0.9.0-subscriptions'

Defined in: src/channel/v0_9/index.ts:13

Overrides

SubscriptionChannel.id


channelSpecVersion

readonly channelSpecVersion: "0.9.0" | "0.10.0" | "0.10.2" | "0.10.3" | "0.10.4" = SupportedRpcVersion.v0_9_0

Defined in: src/channel/v0_9/index.ts:15

Overrides

SubscriptionChannel.channelSpecVersion


transport

protected readonly transport: WsTransport

Defined in: src/channel/ws/subscriptionChannel.ts:67

Inherited from

SubscriptionChannel.transport


maxBufferSize

protected readonly maxBufferSize: number

Defined in: src/channel/ws/subscriptionChannel.ts:69

Inherited from

SubscriptionChannel.maxBufferSize

Accessors

subscriptions

Get Signature

get subscriptions(): ReadonlyMap<string, Subscription<any>>

Defined in: src/channel/ws/subscriptionChannel.ts:413

Internal

The live subscriptions, keyed by the id the node issued. Exposed for the WebSocketChannel compatibility façade.

Returns

ReadonlyMap<string, Subscription<any>>

Inherited from

SubscriptionChannel.subscriptions

Methods

send()

protected send<T>(method, params?): Promise<T>

Defined in: src/channel/ws/subscriptionChannel.ts:131

Sends one JSON-RPC call and returns its result, applying the same error contract as RpcChannel: a protocol error becomes a typed RpcError.

Type Parameters

T

T

Parameters

method

string

params?

object

Returns

Promise<T>

Inherited from

SubscriptionChannel.send


openSubscription()

protected openSubscription<T>(method, rpcParams): Promise<Subscription<T>>

Defined in: src/channel/ws/subscriptionChannel.ts:147

Registers a new subscription and returns the handle the caller keeps.

Type Parameters

T

T

Parameters

method

string

rpcParams

object

Returns

Promise<Subscription<T>>

Inherited from

SubscriptionChannel.openSubscription


subscribeNewHeads()

subscribeNewHeads(params?): Promise<SubscriptionNewHeadsEvent>

Defined in: src/channel/ws/subscriptionChannel.ts:191

Subscribes to new block headers.

Parameters

params?

SubscribeNewHeadsParams = {}

Where to start from. Defaults to the latest block; a block number or hash replays from there, up to 1024 blocks back.

Returns

Promise<SubscriptionNewHeadsEvent>

A Subscription delivering one block header per new block.

Example

const sub = await channel.subscribeNewHeads();
sub.on((header) => console.log(header.block_number, header.block_hash));

Inherited from

SubscriptionChannel.subscribeNewHeads


subscribeEvents()

subscribeEvents(params?): Promise<SubscriptionStarknetEventsEvent>

Defined in: src/channel/ws/subscriptionChannel.ts:215

Subscribes to events matching a given filter.

Parameters

params?

SubscribeEventsParams = {}

Filters on the emitting address, the event keys, the starting block and the finality status. All are optional: without any, every event of the network is delivered.

Returns

Promise<SubscriptionStarknetEventsEvent>

A Subscription delivering one emitted event at a time.

Example

const sub = await channel.subscribeEvents({
fromAddress: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
finalityStatus: 'ACCEPTED_ON_L2',
});
sub.on((event) => console.log(event.from_address, event.keys, event.data));

Inherited from

SubscriptionChannel.subscribeEvents


subscribeTransactionStatus()

subscribeTransactionStatus(params): Promise<SubscriptionTransactionStatusEvent>

Defined in: src/channel/ws/subscriptionChannel.ts:244

Subscribes to status updates for a specific transaction.

Parameters

params

SubscribeTransactionStatusParams

The transactionHash to follow, and optionally the block to start from.

Returns

Promise<SubscriptionTransactionStatusEvent>

A Subscription delivering the transaction's current status, then every change.

Example

const sub = await channel.subscribeTransactionStatus({ transactionHash: '0x0123...' });
sub.on((update) => console.log(update.status.finality_status));

Inherited from

SubscriptionChannel.subscribeTransactionStatus


subscribeNewTransactionReceipts()

subscribeNewTransactionReceipts(params?): Promise<SubscriptionNewTransactionReceiptsEvent>

Defined in: src/channel/ws/subscriptionChannel.ts:270

Subscribes to new transaction receipts.

Same filters as subscribeNewTransactions, but the full receipt is delivered instead of the transaction.

Parameters

params?

SubscribeNewTransactionReceiptsParams = {}

Optional filters on the finality status and on the sender addresses.

Returns

Promise<SubscriptionNewTransactionReceiptsEvent>

A Subscription delivering one receipt per matching transaction.

Example

const sub = await channel.subscribeNewTransactionReceipts({
finalityStatus: ['ACCEPTED_ON_L2'],
});
sub.on((receipt) => console.log(receipt.transaction_hash, receipt.execution_status));

Inherited from

SubscriptionChannel.subscribeNewTransactionReceipts


subscribeNewTransactions()

subscribeNewTransactions(params?): Promise<SubscriptionNewTransactionEvent>

Defined in: src/channel/ws/subscriptionChannel.ts:297

Subscribes to new transactions and to their finality status changes.

One event is fired per status update, so the same transaction can be delivered several times.

Parameters

params?

SubscribeNewTransactionsParams = {}

Optional filters on the finality status (defaults to ['ACCEPTED_ON_L2']) and on the sender addresses.

Returns

Promise<SubscriptionNewTransactionEvent>

A Subscription delivering one transaction per matching status update.

Example

const sub = await channel.subscribeNewTransactions({
finalityStatus: ['RECEIVED', 'ACCEPTED_ON_L2'],
});
sub.on((tx) => console.log(tx.transaction_hash, tx.finality_status));

Inherited from

SubscriptionChannel.subscribeNewTransactions


restore()

restore(): Promise<void>

Defined in: src/channel/ws/subscriptionChannel.ts:354

Re-issues every live subscription on a freshly reconnected socket.

A subscription that cannot be re-established is not put back in the map, and its handle is closed: otherwise it would keep reporting itself as live while nothing could ever reach its handler again.

Returns

Promise<void>

Inherited from

SubscriptionChannel.restore


unsubscribe()

unsubscribe(subscriptionId): Promise<boolean>

Defined in: src/channel/ws/subscriptionChannel.ts:380

Internal

Unsubscribes from a Starknet subscription.

Prefer subscription.unsubscribe().

Parameters

subscriptionId

string

Returns

Promise<boolean>

Inherited from

SubscriptionChannel.unsubscribe


removeSubscription()

removeSubscription(subscriptionId): void

Defined in: src/channel/ws/subscriptionChannel.ts:405

Internal

Removes a subscription from the active map.

Parameters

subscriptionId

string

Returns

void

Inherited from

SubscriptionChannel.removeSubscription


waitForUnsubscription()

waitForUnsubscription(targetId): Promise<void>

Defined in: src/channel/ws/subscriptionChannel.ts:418

Resolves when a specific subscription is successfully unsubscribed.

Parameters

targetId

string

Returns

Promise<void>

Inherited from

SubscriptionChannel.waitForUnsubscription


close()

close(): void

Defined in: src/channel/ws/subscriptionChannel.ts:448

Stops listening to the transport and settles anything still waiting.

Does not close the socket: this channel borrowed it.

Returns

void

Inherited from

SubscriptionChannel.close