npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

multi-wallet-connector

v1.2.0

Published

A multi-wallet-connector class for managing wallet connection states

Downloads

844

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

THANK YOU