multi-wallet-connector
v1.2.1
Published
A multi-wallet-connector class for managing wallet connection states
Downloads
47
Maintainers
Readme
MultiWallet
A simple singleton class for managing wallet connection states in React applications.
Table of Contents
Introduction
multi-wallet-connector
is a JavaScript library that simplifies connecting to multiple cryptocurrency wallets such as MetaMask, Phantom, and XWallet. It provides an easy-to-use interface for handling wallet connections and state management, allowing developers to integrate wallet functionalities seamlessly into their applications.
Features
- Support for Multiple Wallets: Connect to MetaMask, Phantom, and XWallet effortlessly.
- State Management: Centralized management of wallet states, such as connection status and active wallet address.
- Singleton Pattern: Ensures a single instance of wallet management across the application.
- Easy Integration: Simple API for integration with existing web applications.
Installation
You can install the multi-wallet-connector
package via npm:
npm install multi-wallet-connector
import MultiWallet from 'multi-wallet-connector'
API Documentation
Checking Wallet Installation
const isMetamaskInstalled = MultiWallet.isWalletInstalled("Metamask");
const isPhantomInstalled = MultiWallet.isWalletInstalled("Phantom");
const isXWalletInstalled = MultiWallet.isWalletInstalled("XWallet");
Checking Wallet Connection Status
const isAnyWalletConnected = MultiWallet.isAnyWalletConnected();
const isMetamaskActive = MultiWallet.isMetamaskActive();
const isPhantomActive = MultiWallet.isPhantomActive();
const isXwalletActive = MultiWallet.isXwalletActive();
Get Active Address
const address = MultiWallet.getActiveAddress();
Setting and Getting RPC Endpoints
MultiWallet.setL1xRpc(rpc);
MultiWallet.setSolanaRpc(rpc);
const l1xRpc = MultiWallet.getL1xRpc();
const solanaRpc = MultiWallet.getSolanaRpc();
Connecting to Wallets
const connnection = await MultiWallet.connectWallet(walletName, message);
Getting Balances for Connected Wallets
const balance = await MultiWallet.getBalance(functionName, tokenAddress, walletAddress, rpc);
const evmBalance = await MultiWallet.getBalance("getEVMNativeBalance", "", walletAddress, rpc);
const solanaTokenBalance = await MultiWallet.getBalance("getSolanaTokenBalance", tokenAddress, walletAddress, rpc);
const l1xBalance = await MultiWallet.getBalance("getL1xNativeBalance", "", walletAddress, rpc);
const solanaTokenBalance = await MultiWallet.getBalance("getSolanaTokenBalance", tokenAddress, walletAddress, rpc);
EXAMPLE
Check if MetaMask is Installed
const isInstalled = MultiWallet.isWalletInstalled("Metamask");
Connect to Phantom Wallet
const result = await MultiWallet.connectWallet("Phantom", "Please sign this message.");
Get Balances
const balance = await MultiWallet.getBalance("getEVMNativeBalance", "", walletAddress, rpc);
const balance = await MultiWallet.getBalance("getEVMTokenBalance", tokenAddress, walletAddress, rpc);
const balance = await MultiWallet.getBalance("getL1xNativeBalance", "", walletAddress, rpc);
const balance = await MultiWallet.getBalance("getSolanaNativeBalance", "", walletAddress, rpc);
const balance = await MultiWallet.getBalance("getSolanaTokenBalance", tokenAddress, walletAddress, rpc);