multi-wallet-connector
v1.2.0
Published
A multi-wallet-connector class for managing wallet connection states
Downloads
844
Maintainers
Readme
MultiWalletConnector
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 MultiWalletConnector from 'multi-wallet-connector';
API Documentation
Checking Wallet Installation
const isMetamaskInstalled = MultiWalletConnector.isWalletInstalled("Metamask");
const isPhantomInstalled = MultiWalletConnector.isWalletInstalled("Phantom");
const isXWalletInstalled = MultiWalletConnector.isWalletInstalled("XWallet");
Checking Wallet Connection Status
const isAnyWalletConnected = MultiWalletConnector.isAnyWalletConnected();
const isMetamaskActive = MultiWalletConnector.isMetamaskActive();
const isPhantomActive = MultiWalletConnector.isPhantomActive();
const isXwalletActive = MultiWalletConnector.isXwalletActive();
Get Active Address
const address = MultiWalletConnector.getActiveAddress();
Setting and Getting RPC Endpoints
MultiWalletConnector.setL1xRpc(rpc);
MultiWalletConnector.setSolanaRpc(rpc);
const l1xRpc = MultiWalletConnector.getL1xRpc();
const solanaRpc = MultiWalletConnector.getSolanaRpc();
Connecting to Wallets
const connectionResult = await MultiWalletConnector.connectWallet(walletName, message);
Getting Balances for Connected Wallets
const balance = await MultiWalletConnector.getBalance(functionName, tokenAddress, walletAddress, rpc);
const evmBalance = await MultiWalletConnector.getBalance("getEVMNativeBalance", "", walletAddress, rpc);
const solanaTokenBalance = await MultiWalletConnector.getBalance("getSolanaTokenBalance", tokenAddress, walletAddress, rpc);
const l1xBalance = await MultiWalletConnector.getBalance("getL1xNativeBalance", "", walletAddress, rpc);
const solanaTokenBalance = await MultiWalletConnector.getBalance("getSolanaTokenBalance", tokenAddress, walletAddress, rpc);
EXAMPLE
Check if MetaMask is Installed
import MultiWalletConnector from 'multi-wallet-connector';
const isMetamaskInstalled = MultiWalletConnector.isWalletInstalled("Metamask");
console.log('MetaMask installed:', isMetamaskInstalled);
Connect to Phantom Wallet
import MultiWalletConnector from 'multi-wallet-connector';
async function connectToPhantom() {
const result = await MultiWalletConnector.connectWallet("Phantom", "Please sign this message.");
if (result.status) {
console.log('Connected to Phantom with address:', result.walletAddress);
} else {
console.log('Failed to connect to Phantom.');
}
}
Get Balances
import MultiWalletConnector from 'multi-wallet-connector';
async function getBalances() {
const evmNativeBalance = await MultiWalletConnector.getBalance("getEVMNativeBalance", "", walletAddress, rpc);
const tokenBalance = await MultiWalletConnector.getBalance("getEVMTokenBalance", tokenAddress, walletAddress, rpc);
const l1xNativeBalance = await MultiWalletConnector.getBalance("getL1xNativeBalance", "", walletAddress, rpc);
const solanaNativeBalance = await MultiWalletConnector.getBalance("getSolanaNativeBalance", "", walletAddress, rpc);
const solanaTokenBalance = await MultiWalletConnector.getBalance("getSolanaTokenBalance", tokenAddress, walletAddress, rpc);
console.log('EVM