A Provider establishes a connection to the blockchain, whch can be used to query its current state, simulate execution and send transactions to update the state.Providers are one of the most fundamental components of interacting with a blockchain application, and there are many ways to connect, such as over HTTP, WebSockets or injected providers such as Pelagus.
To connect to a remote node provider, use the JsonRpcProvider or WebSocketProvider classes. This connects to a remote node using the JSON-RPC interface. Remote node providers will never have a signer bundled into them.Quais providers are configured to first ask the node which shards it is currently running, and then establish a connection to each of those chains. This is done using
Available using the Colosseum RPC endpoint with https and wss
Copy
Ask AI
import { quais } from 'quais'// configure a multi-shard JSON-RPC provider using the dev rpc and pathingconst provider = new quais.JsonRpcProvider('https://rpc.quai.network', undefined, { usePathing: true })// configure a multi-shard WebSocket provider using the dev rpc and pathingconst provider = new quais.WebSocketProvider('wss://rpc.quai.network', undefined, { usePathing: true })
There are multiple ways to configure a network provider using the Provider interface.To connect to a browser wallet provider like Pelagus, use the BrowserProvider class. Pelagus bundles a Signer into the injected provider that can be used to sign transactions.
Copy
Ask AI
import { quais } from 'quais'// configure pelagus as the providerconst provider = new quais.BrowserProvider(window.pelagus)// get the signerconst signer = provider.getSigner()