WalletConnect Web3 Provider
Web3 Provider for WalletConnect
For more details, read the documentation
Setup
;; // Create WalletConnect Providerconst provider = infuraId: "27e484dcd9e3efcfd25a83a78777cdf1" // Required; // Enable session (triggers QR Code modal)await provider; // Create Web3const web3 = provider;
Events (EIP-1193)
// Subscribe to accounts changeprovider; // Subscribe to chainId changeprovider; // Subscribe to networkId changeprovider; // Subscribe to session connection/openprovider; // Subscribe to session disconnection/closeprovider;
Provider Methods
// Send JSON RPC requestsconst result = await provider; // Close provider sessionawait provider
Web3 Methods
// Get Accountsconst accounts = await web3eth; // Get Chain IDconst chainId = await web3eth; // Get Network IDconst networkId = await web3ethnet; // Send Transactionconst txHash = await web3eth; // Sign Transactionconst signedTx = await web3eth; // Sign Messageconst signedMessage = await web3eth; // Sign Typed Dataconst signedTypedData = await web3eth;
Provider Options
- Required (at least one of the following) a. infuraId - the Infura app ID is used for read requests that don't require user approval like signing requests b. rpc - custom rpc url mapping with chainId keys for each url (check custom rpc url section)
- Optional a. bridge - the Bridge URL points to the bridge server used to relay WalletConnect payloads - default="https://bridge.walletconnect.org" b. chainId - preferred chain id to be provided by the wallet on session request - default=1
Custom RPC Url
WalletConnect Web3 Provider uses a HTTP connection to a remote node to make read calls instead of making unnecessary JSON-RPC requests through the WalletConnect session.
It's required to pass either the infuraId or rpc option values to make this connection remotely. If you would like to use your own custom RPC url you don't need to pass an InfuraId for the provider to work.
Example RPC mapping by chainId
const provider = rpc: 1: "https://mainnet.mycustomnode.com" 3: "https://ropsten.mycustomnode.com" 100: "https://dai.poa.network" // ... ;