Skip to content

Provider

An EIP-1193-compatible provider backed by a WalletConnect v2 session.

Application code should call Provider.init; tests that need an isolated or injected instance should call Provider.create.

import { Provider } from "konekt";
import { ethereumMainnet } from "konekt/eip155";
const provider = await Provider.init({
projectId,
metadata,
chains: [ethereumMainnet],
});
provider.on("display_uri", showPairingUri);
await provider.connect();

new Provider(opts, deps?): Provider

Constructs a provider synchronously.

Prefer Provider.init in applications and Provider.create in tests because those methods perform asynchronous seed loading and session restoration.

CreateProviderOptions

ProviderDeps = {}

Provider

readonly isWalletConnect: true

Allows provider consumers to identify this as a WalletConnect-backed provider.


readonly projectId: string

The WalletConnect Cloud project ID this provider was configured with.

get accountsByChain(): Record<string, string[]>

Approved addresses grouped by CAIP-2 chain ID across all namespaces in the current session.

{ "eip155:1": ["0x…"], "cosmos:cosmoshub-4": ["cosmos1…"] }

Record<string, string[]>


get chains(): readonly Chain[]

The configured chains this provider proposes, flattened into one list.

This is configuration, not proof that the wallet approved every chain. Read session to inspect the approved namespaces.

readonly Chain[]


get connected(): boolean

Whether the provider currently has an approved session.

boolean


get session(): Session | undefined

The approved session, or undefined before connection and after disconnection.

Session | undefined


get uri(): string | undefined

The temporary pairing URI for the current proposal, when one exists.

string | undefined

connect(__namedParameters?): Promise<Session>

Proposes a WalletConnect session and waits for the wallet to approve or reject it.

Listen for display_uri before calling this method. Pass an AbortSignal so closing the pairing UI can cancel the attempt. If a feature rejects the settled session, this method disconnects it before rejecting.

AbortSignal

Promise<Session>

The approved WalletConnect session.


disconnect(): Promise<void>

Ends the current session, clears adapter and feature state, and emits disconnect.

Promise<void>


enable(): Promise<string[]>

Legacy EIP-1193 shortcut that connects if needed and returns the approved EVM accounts.

New code can call connect and then read the EVM adapter’s accounts property.

Promise<string[]>


off<K>(e, fn): void

Removes a listener previously passed to on or once.

K extends keyof ProviderEvents

K

(p) => void

void


on<K>(e, fn): void

Adds an event listener that runs every time the event is emitted.

K extends keyof ProviderEvents

K

(p) => void

void


once<K>(e, fn): void

Adds an event listener that removes itself after its first call.

K extends keyof ProviderEvents

K

(p) => void

void


removeListener<K>(e, fn): void

Alias for off, provided for EIP-1193 and Node-style event compatibility.

K extends keyof ProviderEvents

K

(p) => void

void


request(__namedParameters, chainId?): Promise<{ } | null>

Sends an EIP-1193 request through the adapter that supports its method.

The optional chainId is a configured CAIP-2 ID such as "eip155:8453". It targets this call only and does not change the active chain. Wallet methods require a connected session; EVM JSON-RPC reads require a read transport on the selected chain.

RequestArguments

string

Promise<{ } | null>

ProviderRpcError with code 4100 when a wallet method has no session, 4200 when the method or read transport is unsupported, or -32602 for malformed parameters.


static create<C>(opts, deps?): Promise<Provider & ChainExtensions<C>>

Creates an independent provider, primarily for tests.

Pass deps to replace the relay, session, seed, or storage. Supplying deps.session keeps the provider offline and does not open a real relay socket.

C extends readonly ChainInput[]

CreateProviderOptions<C>

ProviderDeps = {}

Promise<Provider & ChainExtensions<C>>

A new provider, extended with properties supplied by the configured adapters.


static init<C>(opts): Promise<Provider & ChainExtensions<C>>

Creates or returns the application-wide provider.

The first call fixes the provider options; later calls return the same promise. Konekt uses the default relay and persistent browser storage unless the options override them. Register display_uri and request_sent listeners before starting work that emits those events.

C extends readonly ChainInput[]

CreateProviderOptions<C>

Promise<Provider & ChainExtensions<C>>

The shared provider, extended with properties supplied by the configured adapters.