Optional
endpoint: string | string[]The endpoint url. Usually ws://ip:9944
or wss://ip:9944
, may provide an array of endpoint strings.
Optional
autoConnectMs: number | falseOptional
headers: Record<string, string>Optional
timeout: numberCustom timeout value
Private
#privatetrue
when this provider supports subscriptions
Whether the node is connected or not.
true if connected
Promise that resolves the first time we are connected and loaded
Returns the connection stats
Returns a clone of the object
Manually connect
The WsProvider connects automatically by default, however if you decided otherwise, you may connect manually using this method.
Listens on events after having subscribed using the subscribe function.
unsubscribe function
Event
Callback
Listens on events after having subscribed using the subscribe function.
unsubscribe function
Send JSON data using WebSockets to configured HTTP Endpoint or queue.
The RPC methods to execute
Encoded parameters as applicable for the method
Optional
isCacheable: booleanOptional
subscription: SubscriptionHandlerSubscription details (internally used)
subscribe
Allows subscribing to a specific event.
const provider = new WsProvider('ws://127.0.0.1:9944');
const rpc = new Rpc(provider);
rpc.state.subscribeStorage([[storage.system.account, <Address>]], (_, values) => {
console.log(values)
}).then((subscriptionId) => {
console.log('balance changes subscription id: ', subscriptionId)
})
Allows unsubscribing to subscriptions made with subscribe.
Generated using TypeDoc
@polkadot/rpc-provider/ws
Name
WsProvider
Description
The WebSocket Provider allows sending requests using WebSocket to a WebSocket RPC server TCP port. Unlike the HttpProvider, it does support subscriptions and allows listening to events such as new blocks or balance changes.
Example
See
HttpProvider