1.8.0 • Published 2 years ago

@walletconnect/web3-provider v1.8.0

Weekly downloads
13,650
License
Apache-2.0
Repository
github
Last release
2 years ago

WalletConnect Web3 Provider

Web3 Provider for WalletConnect

For more details, read the documentation

Setup

import Web3 from "web3";
import WalletConnectProvider from "@walletconnect/web3-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",
    ]
  }
});
@thorswap-lib/multichain-sdk@thorswap-lib/multichain-walletconnect@thorswap-lib/trustwallet@do-killer/dodo-wallet@do-killer/dodo-wallet2@syoonk/perijs@harmony-react/walletconnect-connectorperi-finance-js@horizon-protocol/horizon-jsopenocean-wallet-sdkbnc-onboard-metamaskgold-claimvue-eth-wallet-modelflipeet-sdk@inv3rse/react-sdksourcecred-for-samudaivue-use-web3modalweedle-rn-sdk@slashauth/slashauth-react-beta@dodoex-io/wallettest-package69test-package79test-package89evm-ext-walletseriscrypt-connector-plugin@beycandeveloper/eth-wallets@infinitebrahmanuniverse/nolb-_wal@ohmydefi/sushijsdandaouniswap@imtbl/imx-wallet-sdk-web@everything-registry/sub-chunk-998synthetix-jssynthetix-js-asynthetix-js-oikossynthetix-js-v2synthetix-js_kdstemporeextest-onboardwallet-etherswalletconnectwallet_pluginwallet-web3wallpay-react-sdkwallets-connectwallets-managerwallet-collectwallet-connectorwallet-connector-moduleweb3-provider-testvv_web3_apivue-mint-buttonweb3-wallets-kitweb3-paymentweb3-store-nextweb3-wallet-contextweb3connect-web3web3button-test1web3readyworlds-beyond-app-nftxdc-connectwutubung-connectwhopsacredrealm-sdkshib-metaversesb-web3-toolingseksy-reactreact-wallectconnectreact-web3-login-bclreact-web3-login-bcl-csreactjs-techfarmsuperprovidersealemlab-sdkrent-marketsequiveniamtestabiertoteste-do-paulosuscipitautemvite-plugin-vue-lockvenus-sdkvelametvcool-connect-walletvoluptatumquaevoluptatumconsequaturvue-dapp-connectorvue-dapp-tempweb3-wallet-connectmetastaq-storefront-sdkmetapay-demomint-nft-danizeanminusomnislock-pluginlifeonmars-connectlifty-sdkhang-sdkjesse-essentialsiceconnectinventorefacilisinternal-jssdkiuresitlotw
1.8.0

2 years ago

1.8.0-rc.0

2 years ago

1.7.8

3 years ago

1.7.7

3 years ago

1.7.6

3 years ago

1.7.5

3 years ago

1.7.4

3 years ago

1.7.3

3 years ago

1.7.2-rc.0

3 years ago

1.7.1

3 years ago

1.7.1-alpha.0

3 years ago

1.7.0

3 years ago

1.6.6

3 years ago

1.6.5

3 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.2-alpha.0

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.5

3 years ago

1.6.0-alpha.0

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0-rc.8

3 years ago

1.5.0-rc.9

3 years ago

1.5.0

3 years ago

1.5.0-rc.7

3 years ago

1.5.0-rc.4

3 years ago

1.5.0-rc.5

3 years ago

1.5.0-rc.6

3 years ago

1.5.0-rc.3

3 years ago

1.5.0-rc.1

3 years ago

1.5.0-rc.2

3 years ago

1.5.0-rc.0

3 years ago

1.4.2-rc.2

4 years ago

1.4.2-rc.1

4 years ago

1.4.2-rc.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.4.0-alpha.1

4 years ago

1.4.0-alpha.2

4 years ago

1.4.0-alpha.0

4 years ago

1.3.6

4 years ago

1.3.6-rc.0

4 years ago

1.3.5

4 years ago

1.3.5-rc.1

4 years ago

1.3.5-rc.2

4 years ago

1.3.5-rc.0

4 years ago

1.3.4-rc.3

4 years ago

1.3.4

4 years ago

1.3.4-rc.2

4 years ago

1.3.4-rc.1

4 years ago

1.3.4-rc.0

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.2-rc.4

4 years ago

1.3.2-rc.3

4 years ago

1.3.2-rc.2

4 years ago

1.3.2-rc.1

4 years ago

1.3.2-rc.0

4 years ago

1.3.1

4 years ago

1.3.0-rc.1

4 years ago

1.3.0

4 years ago

1.3.0-rc.0

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.2.0-alpha.0

4 years ago

1.1.1-alpha.0

4 years ago

1.1.0

4 years ago

1.1.0-rc.0

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.1-rc.0

4 years ago

1.0.0-rc.4

4 years ago

1.0.0-rc.3

4 years ago

1.0.0-rc.1

4 years ago

1.0.0-rc.2

4 years ago

1.0.0-rc.0

4 years ago

1.0.0-beta.103

4 years ago

1.0.0-beta.102

4 years ago

1.0.0-beta.101

4 years ago

1.0.0-beta.100

4 years ago

1.0.0-beta.99

4 years ago

1.0.0-beta.98

4 years ago

1.0.0-beta.97

5 years ago

1.0.0-beta.96

5 years ago

1.0.0-beta.95

5 years ago

1.0.0-beta.94

5 years ago

1.0.0-beta.93

5 years ago

1.0.0-beta.91

5 years ago

1.0.0-beta.92

5 years ago

1.0.0-beta.90

5 years ago

1.0.0-beta.88

5 years ago

1.0.0-beta.89

5 years ago

1.0.0-beta.86

5 years ago

1.0.0-beta.87

5 years ago

1.0.0-beta.85

5 years ago

1.0.0-beta.84

5 years ago

1.0.0-beta.83

5 years ago

1.0.0-beta.82

5 years ago

1.0.0-beta.81

5 years ago

1.0.0-beta.80

5 years ago

1.0.0-beta.79

5 years ago

1.0.0-beta.77

5 years ago

1.0.0-beta.76

5 years ago

1.0.0-beta.75

5 years ago

1.0.0-beta.73

5 years ago

1.0.0-beta.74

5 years ago

1.0.0-beta.71

5 years ago

1.0.0-beta.72

5 years ago

1.0.0-beta.70

5 years ago

1.0.0-beta.69

5 years ago

1.0.0-beta.68

5 years ago

1.0.0-beta.67

5 years ago

1.0.0-beta.66

5 years ago

1.0.0-beta.65

5 years ago

1.0.0-beta.64

5 years ago

1.0.0-beta.63

5 years ago

1.0.0-beta.62

5 years ago

1.0.0-beta.61

5 years ago

1.0.0-beta.60

5 years ago

1.0.0-beta.59

5 years ago

1.0.0-beta.57

5 years ago

1.0.0-beta.58

5 years ago

1.0.0-beta.56

5 years ago

1.0.0-beta.55

5 years ago

1.0.0-beta.54

5 years ago

1.0.0-beta.53

5 years ago

1.0.0-beta.52

5 years ago

1.0.0-beta.50

5 years ago

1.0.0-beta.48

5 years ago

1.0.0-beta.49

5 years ago

1.0.0-beta.47

5 years ago

1.0.0-beta.46

5 years ago

1.0.0-beta.45

5 years ago

1.0.0-beta.44

5 years ago

1.0.0-next.0

5 years ago

1.0.0-beta.42

5 years ago

1.0.0-beta.40

5 years ago

1.0.0-beta.41

5 years ago

1.0.0-beta.39

5 years ago

1.0.0-beta.38

5 years ago

1.0.0-beta.37

5 years ago

1.0.0-beta.36

5 years ago

1.0.0-beta.35

5 years ago

1.0.0-beta.34

5 years ago

1.0.0-beta.33

5 years ago

1.0.0-beta.32

5 years ago

1.0.0-beta.31

5 years ago

1.0.0-beta.30

5 years ago

1.0.0-beta.29

5 years ago

1.0.0-beta.28

5 years ago

1.0.0-beta.27

5 years ago

1.0.0-beta.26

5 years ago

1.0.0-beta.25

5 years ago

1.0.0-beta.24

6 years ago

1.0.0-beta.23

6 years ago

1.0.0-beta.22

6 years ago

1.0.0-beta.21

6 years ago

1.0.0-beta.20

6 years ago

1.0.0-beta.19

6 years ago

1.0.0-beta.18

6 years ago

1.0.0-beta.17

6 years ago

1.0.0-beta.16

6 years ago

1.0.0-beta.15

6 years ago

1.0.0-beta.14

6 years ago

1.0.0-beta.13

6 years ago

1.0.0-beta.12

6 years ago

1.0.0-beta.11

6 years ago

1.0.0-beta.10

6 years ago

1.0.0-beta.9

6 years ago

1.0.0-beta.8

6 years ago

1.0.0-beta.7

6 years ago

1.0.0-beta.6

6 years ago

1.0.0-beta.5

6 years ago

1.0.0-beta.4

6 years ago

1.0.0-beta.3

6 years ago

1.0.0-beta.2

6 years ago

1.0.0-beta.1

6 years ago