注意: このページはまだ日本語に翻訳されていません。以下は英語の原文です。A JSON-RPC provider which is backed by a WebSocket. WebSockets are often preferred because they retain a live connection to a server, which permits more instant access to events. However, this incurs higher server infrastructure costs, so additional resources may be required to host your own WebSocket nodes and many third-party services charge additional fees for WebSocket endpoints.
Extends
Constructors
new WebSocketProvider()
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | string[] | WebSocketLike | WebSocketCreator | The URL(s) or WebSocket object or creator. |
network? | Networkish | The network to connect to. |
options? | JsonRpcApiProviderOptions | The options for the JSON-RPC API provider. |
Returns
WebSocketProvider
Overrides
SocketProvider.constructor
Source
providers/provider-websocket.ts:94Properties
| Property | Type | Default value | Description |
|---|---|---|---|
readyMap | Map<Shard, boolean> | ... | A map to track the readiness of each shard. |
Accessors
connect
Returns
FetchRequest[]
The list of connected FetchRequests.
Source
providers/abstract-provider.ts:1026destroyed
Returns
boolean
Source
providers/abstract-provider.ts:2545paused
paused = true is identical to calling .pause(false), which will buffer any events that occur while
paused until the provider is unpaused.
Returns
boolean
Whether the provider is paused.
Source
providers/abstract-provider.ts:2577pollingInterval
Returns
number
The polling interval.
Source
providers/abstract-provider.ts:1183provider
this, to allow an AbstractProvider to implement the Contract Runner
interface.
Returns
this
The provider instance.
Source
providers/abstract-provider.ts:1193ready
Returns
boolean
True if the provider is ready.
Source
providers/provider-jsonrpc.ts:1117websocket
Throws
If the websocket is closed.Returns
WebSocketLike[]
The array of WebSocketLike objects.
Source
providers/provider-websocket.ts:80Methods
_clearTimeout()
Parameters
| Parameter | Type | Description |
|---|---|---|
timerId | number | The ID of the timer to clear. |
Returns
void
Inherited from
SocketProvider._clearTimeout
Source
providers/abstract-provider.ts:2221destroy()
Returns
Promise<void>
A promise that resolves when the WebSocket connections are closed.
Overrides
SocketProvider.destroy
Source
providers/provider-websocket.ts:399getActiveRegions()
Returns
Promise<Shard[]>
A promise that resolves to the active shards.
Inherited from
SocketProvider.getActiveRegions
Source
providers/abstract-provider.ts:1110getActiveZones()
Returns
Promise<Zone[]>
A promise that resolves to the active zones.
Inherited from
SocketProvider.getActiveZones
Source
providers/abstract-provider.ts:1127getLatestQiToQuaiRate()
Parameters
| Parameter | Type | Description |
|---|---|---|
zone | Zone | The zone to get the rate for. |
amt? | bigint | The amount to get the rate for. Default is 1 |
Returns
Promise<bigint>
A promise that resolves to the latest Qi rate.
Inherited from
SocketProvider.getLatestQiToQuaiRate
Source
providers/abstract-provider.ts:1149getLatestQuaiToQiRate()
Parameters
| Parameter | Type | Description |
|---|---|---|
zone | Zone | The zone to get the rate for. |
amt? | bigint | The amount in quais to get the rate for. Default is 1 |
Returns
Promise<bigint>
A promise that resolves to the latest Quai -> Qi rate for the given amount.
Inherited from
SocketProvider.getLatestQuaiToQiRate
Source
providers/abstract-provider.ts:1068getProtocolExpansionNumber()
Returns
Promise<number>
A promise that resolves to the protocol expansion number.
Inherited from
SocketProvider.getProtocolExpansionNumber
Source
providers/abstract-provider.ts:1101getQiToQuaiRateAtBlock()
Parameters
| Parameter | Type | Description |
|---|---|---|
zone | Zone | The zone to get the rate for. |
blockTag | BlockTag | The block tag to get the rate at. |
amt? | bigint | The amount to get the rate for. Default is 1 |
Returns
Promise<bigint>
A promise that resolves to the Qi rate at the specified block.
Inherited from
SocketProvider.getQiToQuaiRateAtBlock
Source
providers/abstract-provider.ts:1162getQuaiToQiRateAtBlock()
Parameters
| Parameter | Type | Description |
|---|---|---|
zone | Zone | The zone to get the rate for. |
blockTag | BlockTag | The block tag to get the rate at. |
amt? | bigint | The amount to get the rate for. Default is 1 |
Returns
Promise<bigint>
A promise that resolves to the Quai rate at the specified block.
Inherited from
SocketProvider.getQuaiToQiRateAtBlock
Source
providers/abstract-provider.ts:1081getSigner()
Parameters
| Parameter | Type | Description |
|---|---|---|
address? | string | number | The address or index of the account. |
Returns
Promise<JsonRpcSigner>
A promise that resolves to the JsonRpcSigner.
Inherited from
SocketProvider.getSigner
Throws
If the account is invalid.Source
providers/provider-jsonrpc.ts:1542listAccounts()
Returns
Promise<JsonRpcSigner[]>
A promise that resolves to an array of JsonRpcSigners.
Inherited from
SocketProvider.listAccounts
Source
providers/provider-jsonrpc.ts:1579pause()
dropWhilePaused, any events that occur while paused are dropped, otherwise all events
will be emitted once the provider is unpaused.
Parameters
| Parameter | Type | Description |
|---|---|---|
dropWhilePaused? | boolean | Whether to drop events while paused. |
Returns
void
Inherited from
SocketProvider.pause
Source
providers/abstract-provider.ts:2598resume()
Returns
void
Inherited from
SocketProvider.resume
Source
providers/abstract-provider.ts:2627send()
method with params via the JSON-RPC protocol over the underlying channel. This can be used to
call methods on the backend that do not have a high-level API within the Provider API.
This method queues requests according to the batch constraints in the options, assigns the request a unique ID.
Do NOT override this method in sub-classes; instead override JsonRpcApiProvider._send | _send or
force the options values in the call to the constructor to modify this method’s behavior.
Parameters
| Parameter | Type | Description |
|---|---|---|
method | string | The method to call. |
params | any[] | Record<string, any> | The parameters to pass to the method. |
shard? | Shard | The shard to send the request to. |
now? | boolean | If true, the request will be sent immediately. |
Returns
Promise<any>
A promise that resolves to the result of the method call.
Inherited from
SocketProvider.send
Source
providers/provider-jsonrpc.ts:1500shardFromHash()
Parameters
| Parameter | Type | Description |
|---|---|---|
hash | string | The hash to get the shard from. |
Returns
Shard
The shard.
Inherited from
SocketProvider.shardFromHash
Source
providers/abstract-provider.ts:1047waitShardReady()
Parameters
| Parameter | Type | Description |
|---|---|---|
shard | Shard | The shard identifier. |
Returns
Promise<void>
A promise that resolves when the shard is ready.
Throws
If the shard is not ready within the timeout period.Source
providers/provider-websocket.ts:166zoneFromAddress()
Parameters
| Parameter | Type | Description |
|---|---|---|
_address | AddressLike | The address to get the zone from. |
Returns
Promise<Zone>
A promise that resolves to the zone.
Inherited from
SocketProvider.zoneFromAddress
Source
providers/abstract-provider.ts:1036zoneFromHash()
Parameters
| Parameter | Type | Description |
|---|---|---|
hash | string | The hash to get the zone from. |
Returns
Zone
The zone.
Inherited from
SocketProvider.zoneFromHash
