You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@walletconnect/ethereum-provider

Package Overview
Dependencies
Maintainers
10
Versions
432
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@walletconnect/ethereum-provider

Ethereum Provider for WalletConnect Protocol


Version published
Weekly downloads
314K
decreased by-0.13%
Maintainers
10
Created
Weekly downloads
 

Package description

What is @walletconnect/ethereum-provider?

@walletconnect/ethereum-provider is an npm package that allows developers to integrate WalletConnect functionality into their Ethereum-based applications. It provides a bridge between decentralized applications (dApps) and mobile wallets, enabling users to interact with dApps using their mobile wallets.

What are @walletconnect/ethereum-provider's main functionalities?

Initialize WalletConnect Provider

This feature allows you to initialize the WalletConnect provider with your Infura ID. The provider can then be enabled to start connecting with mobile wallets.

const WalletConnectProvider = require('@walletconnect/ethereum-provider');
const provider = new WalletConnectProvider({
  infuraId: 'YOUR_INFURA_ID' // Required
});
await provider.enable();

Send Transaction

This feature allows you to send a transaction using the WalletConnect provider. You need to specify the transaction parameters such as from, to, value, gas, and gasPrice.

const tx = await provider.request({
  method: 'eth_sendTransaction',
  params: [{
    from: '0xYourAddress',
    to: '0xRecipientAddress',
    value: '0xAmountInWei',
    gas: '0xGasLimit',
    gasPrice: '0xGasPrice'
  }]
});

Sign Message

This feature allows you to sign a message using the WalletConnect provider. You need to provide the message and the address of the signer.

const message = 'Hello, WalletConnect!';
const signedMessage = await provider.request({
  method: 'personal_sign',
  params: [message, '0xYourAddress']
});

Switch Ethereum Chain

This feature allows you to switch the Ethereum chain using the WalletConnect provider. You need to specify the chain ID of the desired network.

await provider.request({
  method: 'wallet_switchEthereumChain',
  params: [{ chainId: '0x1' }] // Chain ID for Ethereum Mainnet
});

Other packages similar to @walletconnect/ethereum-provider

Readme

Source

@walletconnect/ethereum-provider

Ethereum Provider for WalletConnect Protocol.

Installation

npm i @walletconnect/ethereum-provider @walletconnect/modal

Initialization

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

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

Display WalletConnectModal with QR code / Handle connection URI

// WalletConnectModal is disabled by default, enable it during init() to 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 are not using WalletConnectModal,
// you can subscribe to the `display_uri` event and handle the URI yourself.
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);

Supported WalletConnectModal options (qrModalOptions)

Please reference up to date documentation for WalletConnectModal

Keywords

FAQs

Package last updated on 17 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc