@deficonnect/ethereum-provider
TypeScript icon, indicating that this package has built-in type declarations

1.6.14-dev.2 • Public • Published

WalletConnect Ethereum Provider

Ethereum Provider for WalletConnect

For more details, read the documentation

Setup

import Web3 from "web3";
import WalletConnectProvider from "@deficonnect/ethereum-provider";

//  Create WalletConnect Provider
const provider = new WalletConnectProvider({
  infuraId: "27e484dcd9e3efcfd25a83a78777cdf1", // Required
});

//  Enable session (triggers QR Code modal)
await provider.enable();

//  Create Web3
const web3 = new Web3(provider);

Events (EIP-1193)

// Subscribe to accounts change
provider.on("accountsChanged", (accounts: string[]) => {
  console.log(accounts);
});

// Subscribe to chainId change
provider.on("chainChanged", (chainId: number) => {
  console.log(chainId);
});

// Subscribe to session connection
provider.on("connect", () => {
  console.log("connect");
});

// Subscribe to session disconnection
provider.on("disconnect", (code: number, reason: string) => {
  console.log(code, reason);
});

Provider Methods

interface RequestArguments {
  method: string;
  params?: unknown[] | object;
}

// Send JSON RPC requests
const result = await provider.request(payload: RequestArguments);

// Close provider session
await provider.disconnect()

Web3 Methods

//  Get Accounts
const accounts = await web3.eth.getAccounts();

//  Get Chain Id
const chainId = await web3.eth.chainId();

//  Get Network Id
const networkId = await web3.eth.net.getId();

// Send Transaction
const txHash = await web3.eth.sendTransaction(tx);

// Sign Transaction
const signedTx = await web3.eth.signTransaction(tx);

// Sign Message
const signedMessage = await web3.eth.sign(msg);

// Sign Typed Data
const signedTypedData = await web3.eth.signTypedData(msg);

Provider Options

Required

In order to resolve non-signing requests you need to provide one of the following:

Infura ID

The infuraId will support the following chainId's: Mainnet (1), Ropsten (3), Rinkeby(4), Goerli (5) and Kovan (42)

const provider = new WalletConnectProvider({
  infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
});

RPC URL Mapping

The RPC URL mapping should indexed by chainId and it requires at least one value.

const provider = new WalletConnectProvider({
  rpc: {
    1: "https://mainnet.mycustomnode.com",
    3: "https://ropsten.mycustomnode.com",
    100: "https://dai.poa.network",
    // ...
  },
});

Optional

You can also customize the connector through the provider using the following options

Bridge URL

Use your own hosted bridge by providing the url

const provider = new WalletConnectProvider({
  infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
  bridge: "https://bridge.myhostedserver.com",
});

Disable QR Code Modal

Use your own custom qrcode modal and disable the built-in one

const provider = new WalletConnectProvider({
  infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
  qrcode: false,
});

provider.connector.on("display_uri", (err, payload) => {
  const uri = payload.params[0];
  CustomQRCodeModal.display(uri);
});

Filter Linking Options

If you would like to reduce the number of linking options or customize its order, you can provide an array of wallet names. Providing empty whitelist disables linking.

const provider = new WalletConnectProvider({
  infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
  qrcodeModalOptions: {
    mobileLinks: [
      "rainbow",
      "metamask",
      "argent",
      "trust",
      "imtoken",
      "pillar",
    ],
    desktopLinks: [
      "encrypted ink",
    ]
  }
});

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.6.14-dev.21latest

Version History

VersionDownloads (Last 7 Days)Published
1.6.14-dev.21
1.6.14-dev.11
1.6.14-dev.01
1.6.132
1.6.122
1.6.112
1.6.102
1.6.91
1.6.81
1.6.70
1.6.7-alpha.250
1.6.7-alpha.240
1.6.7-alpha.230
1.6.7-alpha.220
1.6.7-alpha.210
1.6.7-alpha.200
1.6.7-alpha.190
1.6.7-alpha.170
1.6.7-alpha.10
1.6.7-alpha.00
1.6.60
1.6.50

Package Sidebar

Install

npm i @deficonnect/ethereum-provider

Weekly Downloads

13

Version

1.6.14-dev.2

License

LGPL-3.0

Unpacked Size

346 kB

Total Files

13

Last publish

Collaborators

  • cryptocom