JSPM

@walletconnect/ethereum-provider

2.3.2-2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 479221
  • Score
    100M100P100Q196471F
  • License Apache-2.0

Ethereum Provider for WalletConnect Protocol

Package Exports

  • @walletconnect/ethereum-provider
  • @walletconnect/ethereum-provider/dist/index.cjs.js
  • @walletconnect/ethereum-provider/dist/index.es.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@walletconnect/ethereum-provider) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@walletconnect/ethereum-provider

Ethereum Provider for WalletConnect Protocol.

Installation

npm i @walletconnect/ethereum-provider

Initialization

import { EthereumProvider } from "@walletconnect/ethereum-provider";

const provider = await EthereumProvider.init({
  projectId, // REQUIRED your projectId
  chains, // REQUIRED chain ids
  methods, // OPTIONAL ethereum methods
  events, // OPTIONAL ethereum events
  rpcMap, // OPTIONAL rpc urls for each chain
  metadata, // OPTIONAL metadata of your app
  showQrModal, // OPTIONAL - `true` by default
});

Display Web3Modal with QR code / Handle connection URI

// Web3Modal is enabled by default and will display a QR code modal
await provider.connect({
  chains, // OPTIONAL chain ids
  rpcMap, // OPTIONAL rpc urls
  pairingTopic, // OPTIONAL pairing topic
});
// or
await provider.enable();
// If you wish to disable the built-in modal via `showQrModal`, you can subscribe to
provider.on("display_uri", (uri: string) => {
  // ... custom logic
});

await provider.connect();
// or
await provider.enable();

Sending Requests

const result = await provider.request({ method: "eth_requestAccounts" });

// OR

provider.sendAsync({ method: "eth_requestAccounts" }, CallBackFunction);

Events

// chain changed
provider.on("chainChanged", handler);
// accounts changed
provider.on("accountsChanged", handler);
// session established
provider.on("connect", handler);
// session event - chainChanged/accountsChanged/custom events
provider.on("session_event", handler);
// connection uri
provider.on("display_uri", handler);
// session disconnect
provider.on("disconnect", handler);