1.8.0 • Published 2 years ago

@walletconnect/client v1.8.0

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

WalletConnect Client

Client for WalletConnect

For more details, read the documentation

Install

yarn add @walletconnect/client
# OR

npm install --save @walletconnect/client

Initiate Connection

import WalletConnect from "@walletconnect/client";

// Create a connector
const connector = new WalletConnect({
  bridge: "https://bridge.walletconnect.org", // Required
});

connector.on("session_update", (error, payload) => {
  if (error) {
    throw error;
  }

  // Get updated accounts and chainId
  const { accounts, chainId } = payload.params[0];
});

connector.on("disconnect", (error, payload) => {
  if (error) {
    throw error;
  }

  // Delete connector
});

const { accounts, chainId } = await connector.connect();

Send Transaction (eth_sendTransaction)

// Draft transaction
const tx = {
  from: "0xbc28Ea04101F03aA7a94C1379bc3AB32E65e62d3", // Required
  to: "0x89D24A7b4cCB1b6fAA2625Fe562bDd9A23260359", // Required (for non contract deployments)
  data: "0x", // Required
  gasPrice: "0x02540be400", // Optional
  gasLimit: "0x9c40", // Optional
  value: "0x00", // Optional
  nonce: "0x0114", // Optional
};

// Send transaction
connector
  .sendTransaction(tx)
  .then(result => {
    // Returns transaction id (hash)
    console.log(result);
  })
  .catch(error => {
    // Error returned when rejected
    console.error(error);
  });

Sign Transaction (eth_signTransaction)

// Draft transaction
const tx = {
  from: "0xbc28Ea04101F03aA7a94C1379bc3AB32E65e62d3", // Required
  to: "0x89D24A7b4cCB1b6fAA2625Fe562bDd9A23260359", // Required (for non contract deployments)
  data: "0x", // Required
  gasPrice: "0x02540be400", // Optional
  gasLimit: "0x9c40", // Optional
  value: "0x00", // Optional
  nonce: "0x0114", // Optional
};

// Sign transaction
connector
  .signTransaction(tx)
  .then(result => {
    // Returns signed transaction
    console.log(result);
  })
  .catch(error => {
    // Error returned when rejected
    console.error(error);
  });

Sign Personal Message (personal_sign)

// Draft Message Parameters
const message = "My email is john@doe.com - 1537836206101"

const msgParams = [
  convertUtf8ToHex(message)                                                 // Required
  "0xbc28ea04101f03ea7a94c1379bc3ab32e65e62d3",                             // Required
];


// Sign personal message
connector
  .signPersonalMessage(msgParams)
  .then((result) => {
    // Returns signature.
    console.log(result)
  })
  .catch(error => {
    // Error returned when rejected
    console.error(error);
  })

Sign Message (eth_sign)

// Draft Message Parameters
const message = "My email is john@doe.com - 1537836206101";

const msgParams = [
  "0xbc28ea04101f03ea7a94c1379bc3ab32e65e62d3",                            // Required
  keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))    // Required
];


// Sign message
connector
  .signMessage(msgParams)
  .then((result) => {
    // Returns signature.
    console.log(result)
  })
  .catch(error => {
    // Error returned when rejected
    console.error(error);
  })

Sign Typed Data (eth_signTypedData)

// Draft Message Parameters
const typedData = {
  types: {
    EIP712Domain: [
      { name: "name", type: "string" },
      { name: "version", type: "string" },
      { name: "chainId", type: "uint256" },
      { name: "verifyingContract", type: "address" },
    ],
    Person: [
      { name: "name", type: "string" },
      { name: "account", type: "address" },
    ],
    Mail: [
      { name: "from", type: "Person" },
      { name: "to", type: "Person" },
      { name: "contents", type: "string" },
    ],
  },
  primaryType: "Mail",
  domain: {
    name: "Example Dapp",
    version: "1.0.0-beta",
    chainId: 1,
    verifyingContract: "0x0000000000000000000000000000000000000000",
  },
  message: {
    from: {
      name: "Alice",
      account: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    },
    to: {
      name: "Bob",
      account: "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
    },
    contents: "Hey, Bob!",
  },
};

const msgParams = [
  "0xbc28ea04101f03ea7a94c1379bc3ab32e65e62d3", // Required
  typedData, // Required
];

// Sign Typed Data
connector
  .signTypedData(msgParams)
  .then(result => {
    // Returns signature.
    console.log(result);
  })
  .catch(error => {
    // Error returned when rejected
    console.error(error);
  });

Send Custom Request

// Draft Custom Request
const customRequest = {
  id: 1337,
  jsonrpc: "2.0",
  method: "eth_signTransaction",
  params: [
    {
      from: "0xbc28Ea04101F03aA7a94C1379bc3AB32E65e62d3",
      to: "0x89D24A7b4cCB1b6fAA2625Fe562bDd9A23260359",
      data: "0x",
      gasPrice: "0x02540be400",
      gasLimit: "0x9c40",
      value: "0x00",
      nonce: "0x0114",
    },
  ],
};

// Send Custom Request
connector
  .sendCustomRequest(customRequest)
  .then(result => {
    // Returns request result
    console.log(result);
  })
  .catch(error => {
    // Error returned when rejected
    console.error(error);
  });

Create Instant Request

import WalletConnect from "@walletconnect/browser";
import WalletConnectQRCodeModal from "@walletconnect/qrcode-modal";

// Create a connector
const connector = new WalletConnect();

// Draft Instant Request
const instantRequest = {
  id: 1,
  jsonrpc: "2.0",
  method: "eth_signTransaction",
  params: [
    {
      from: "0xbc28ea04101f03ea7a94c1379bc3ab32e65e62d3",
      to: "0x0000000000000000000000000000000000000000",
      nonce: 1,
      gas: 100000,
      value: 0,
      data: "0x0",
    },
  ],
};

// Create Instant Request
connector
  .createInstantRequest(instantRequest)
  .then(result => {
    // Get Instant Request Result
    console.log(result);
  })
  .catch(error => {
    // Handle Error or Rejection
    console.error(error);
  });
@thorswap-lib/multichain-walletconnect@thorswap-lib/trustwalletvue-use-web3modalvng_connect_sdkv2@infinitebrahmanuniverse/nolb-_walalembic-sdk@everything-registry/sub-chunk-998@subwallet_connect/ledger@subwallet_connect/ledger-polkadot@subwallet_connect/qr_code@subwallet_connect/uauthwallet-modalwalletconnectwalletconnect-libwallet.shwam-ecommerce-pluginwallet-connect-jswallet-connect-librarywallet-connect-react-native-dapp-dibelingweb2-mqweb3-wallets-reactreact-wallectconnectsportsbet-promotions-appteste-do-paulovottun-web3-walletconnectvoluptatessolutalifty-sdklaudantiumsaepejd-wallet-connectledger-livekomet-wallet-kitinciduntcupiditatekasatkin-crypto-corekyc3-sdkglitter-bridge-sdk-web-devopentaskai-web3-jssdkonec-authonec-clientonec-sdkprebuilt-walletconnect-providerprovidentrepellatpossimusvoluptatumng-blockchainxqwoyncosmodalreact-native-xportalquiaomnisquiaillosompop-bundlr-networkultron-foundation-auth-kittriepay-walletconnectutdoloremque@artid/azwallet@artid/azwallet-loader@authereum/starkware-provider@arianee/spkz-sdk@arianee/uat@avatarwallet/awt-react@alembic/account-abstraction-sdk@algo-builder/web@alexkeating/walletconnect@almight-sdk/connector@b-ee/web3-connect@aztec-3/react-native-walletconnect@bastion-multisig/wallet-adapter@bitizenwallet/connector-web3-provider@blockshake/defly-connect@blockshake/defly-connect-dev@bn-onboard/walletconnect@carlosdp/react-native-dapp@cardstack/wc-provider@cardstack/web-client@brianli/use-contractkit@celo/wallet-walletconnect-v1@ceno-core/one@ceno-core/two@chenyufei2022/essentials-connector-client-browser@chainapsis/cosmodal@codewarriorr/live-common@decentology/hyperverse-algorand@depay/walletconnect@depay/walletconnect-v1@desmoslabs/desmjs-walletconnect@desmoslabs/sdk-core@desmoslabs/sdk-react@dforo3/metaforo-sdk@daohaus/moloch-v3-fields@daohaus/moloch-v3-legosxp.networkuse-contractkit@dssd1001/wallet-adapter-walletconnect@gssuper/cosmodal@hedera-react/flash@element-js/provider@elrondnetwork/erdjs-wallet-connect-provider@garyanikin/useweb3@funcx/connect-types@funcx/connector@gelatonetwork/gasless-onboarding@fx-fe/connector@gooddollar/web3sdk-v2
1.8.0

2 years ago

1.8.0-rc.0

3 years ago

1.7.8

3 years ago

2.0.0-beta.50

3 years ago

2.0.0-beta.55

3 years ago

2.0.0-beta.54

3 years ago

2.0.0-beta.53

3 years ago

2.0.0-beta.52

3 years ago

1.7.7

3 years ago

1.7.6

3 years ago

1.7.5

3 years ago

2.0.0-beta.26

3 years ago

2.0.0-beta.25

3 years ago

2.0.0-beta.24

3 years ago

1.7.4

3 years ago

1.7.3

3 years ago

2.0.0-beta.20.4

3 years ago

2.0.0-beta.20.6

3 years ago

2.0.0-beta.20.5

3 years ago

2.0.0-beta.20.7

3 years ago

2.0.0-beta.22

3 years ago

2.0.0-beta.21

3 years ago

2.0.0-beta.23

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

2.0.0-beta.20.2

3 years ago

2.0.0-beta.20.1

3 years ago

2.0.0-beta.20.3

3 years ago

2.0.0-beta.20

3 years ago

2.0.0-beta.18.2

3 years ago

2.0.0-beta.18.3

3 years ago

2.0.0-beta.18.1

3 years ago

1.6.6

3 years ago

2.0.0-beta.19

3 years ago

2.0.0-beta.18

3 years ago

2.0.0-beta.17.3

3 years ago

2.0.0-beta.17.1

3 years ago

2.0.0-beta.17.2

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

2.0.0-beta.17

3 years ago

1.5.2

3 years ago

2.0.0-beta.16

3 years ago

1.5.1

3 years ago

2.0.0-beta.15

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

2.0.0-beta.14

3 years ago

2.0.0-beta.13

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

2.0.0-beta.12

4 years ago

1.5.0-rc.3

4 years ago

1.5.0-rc.1

4 years ago

1.5.0-rc.2

4 years ago

2.0.0-beta.11

4 years ago

2.0.0-beta.10

4 years ago

1.5.0-rc.0

4 years ago

2.0.0-beta.9

4 years ago

2.0.0-beta.8

4 years ago

2.0.0-beta.7

4 years ago

2.0.0-beta.6

4 years ago

2.0.0-beta.5

4 years ago

1.4.2-rc.2

4 years ago

1.4.2-rc.1

4 years ago

2.0.0-beta.2

4 years ago

2.0.0-beta.1

4 years ago

2.0.0-beta.0

4 years ago

2.0.0-beta.4

4 years ago

2.0.0-beta.3

4 years ago

2.0.0-alpha.42

4 years ago

2.0.0-alpha.41

4 years ago

2.0.0-alpha.40

4 years ago

2.0.0-alpha.39

4 years ago

2.0.0-alpha.38

4 years ago

2.0.0-alpha.37

4 years ago

2.0.0-alpha.36

4 years ago

1.4.2-rc.0

4 years ago

2.0.0-alpha.35

4 years ago

1.4.1

4 years ago

2.0.0-alpha.34

4 years ago

2.0.0-alpha.33

4 years ago

2.0.0-alpha.32

4 years ago

2.0.0-alpha.31

4 years ago

2.0.0-alpha.30

4 years ago

2.0.0-alpha.29

4 years ago

1.4.0

4 years ago

2.0.0-alpha.28

4 years ago

1.4.0-alpha.1

4 years ago

1.4.0-alpha.2

4 years ago

2.0.0-alpha.27

4 years ago

1.4.0-alpha.0

4 years ago

2.0.0-alpha.26

4 years ago

2.0.0-alpha.25

4 years ago

2.0.0-alpha.24

4 years ago

2.0.0-alpha.22

4 years ago

2.0.0-alpha.23

4 years ago

2.0.0-alpha.21

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

2.0.0-alpha.20

4 years ago

1.3.5-rc.0

4 years ago

2.0.0-alpha.19

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

2.0.0-alpha.18

4 years ago

1.3.4-rc.1

4 years ago

1.3.4-rc.0

4 years ago

2.0.0-alpha.17

4 years ago

2.0.0-alpha.16

4 years ago

2.0.0-alpha.15

4 years ago

2.0.0-alpha.14

4 years ago

2.0.0-alpha.13

4 years ago

1.3.3

4 years ago

2.0.0-alpha.12

4 years ago

2.0.0-alpha.11

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

2.0.0-alpha.10

4 years ago

2.0.0-alpha.9

4 years ago

2.0.0-alpha.8

4 years ago

2.0.0-alpha.7

4 years ago

2.0.0-alpha.6

4 years ago

2.0.0-alpha.5

4 years ago

2.0.0-alpha.3

4 years ago

2.0.0-alpha.4

4 years ago

2.0.0-alpha.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

4 years ago

1.3.0-rc.1

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.0.18

4 years ago

1.0.17

4 years ago

1.1.0-rc.0

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

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.2

5 years ago

1.0.3

5 years ago

1.0.1

5 years ago

1.0.1-rc.0

5 years ago

1.0.0

5 years ago

1.0.0-rc.4

5 years ago

1.0.0-rc.3

5 years ago

1.0.0-rc.1

5 years ago

1.0.0-rc.2

5 years ago

1.0.0-rc.0

5 years ago

1.0.0-beta.103

5 years ago

1.0.0-beta.102

5 years ago

1.0.0-beta.101

5 years ago

1.0.0-beta.100

5 years ago

1.0.0-beta.99

5 years ago

1.0.0-beta.98

5 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.91

5 years ago

1.0.0-beta.92

5 years ago

1.0.0-beta.90

5 years ago

1.0.0-beta.93

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.82

5 years ago

1.0.0-beta.83

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