Web3 Wallet Connect
Easily Integrate web3 wallets in your Dapp
See package visit
Installation
Install web3-wallet connect with npm
npm i web3-wallet-connect
Example Usage
Import Wallet
import { useMetamask, useWalletConnect } from "web3-wallet-connect";
Create wallet Object
// for Metamask object
const connect = new useMetamask();
// for WalletConnect Object
// pass rpc url object.
const connect = new useWalletConnect({ rpc: rpcUrlObject });
Connect to Wallet
//for Metamask
const wallet = await connect._connectMM();
//for WalletConnect
const wallet = await connect._connectWC();
Network Change
// This fn accepts a callback function
connect.onNetworkChange(cb);
const cb = (chainId) => {
console.log(parseInt(chainId));
};
Account Change
// This fn accepts a callback function
connect.onAccountChange(cb);
const cb = (walletAddress) => {
console.log(walletAddress);
};
Switch Network
//chainId should be integer eg 1,137,56,etc
const _result = await connect._switchNetwork(chainId);
Disconnect
//FOR WALLETCONNECT
await connect._disconnectWC();
Provider
// for metamask
const provider = connect.getProviderMM();
//for WalletConnect
const provider = connect.getProviderWC();
Sign Message
// For signing the message]
const result = await connect._signMessage(message);
Conncet Smart Contract
import { useContract } from "web3-wallet-connect";
const contract = useContract(CONTRACT_ADDRESS, ABI, PROVIDER);
import ethers
import { ethers } from "web3-wallet-connect";
🍰 Contributing
Before Contributing please read Contribute
💻 Built with
- Javascript
- Ether.js
🙏 Support
License
Developed with