1.0.17 • Published 1 year ago

solana-active-wallet-react v1.0.17

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Solana Active Wallet React

useSolanaActiveWallet()

This is a react hook that detects a user's current active solana wallet and returns the public key on the client. It detects when a user has changed their active wallet inside a browser wallet extension and will update and return the active public key accordingly. The wallets currently supported are:

  • Phantom
  • Backpack
  • Solflare
  • TrustWallet
  • Glow

Support for other wallets will be added in the future.

Demo Website

Demo

Installation

npm install solana-active-wallet-react

Note the useSolanaActiveWallet hook relies on the "publicKey" and "wallet" returned by the useWallet hook from the @solana/wallet-adapter-react package. These values are both passed in as parameters when using the hook.

Basic Usage

import useSolanaActiveWallet from "solana-active-wallet-react";
import { useWallet } from "@solana/wallet-adapter-react";

const { publicKey, wallet } = useWallet();
const { activeWalletAddress } = useSolanaActiveWallet(publicKey, wallet);

console.log("active wallet address", activeWalletAddress);

Example Usage

import useSolanaActiveWallet from "solana-active-wallet-react";
import { useWallet } from "@solana/wallet-adapter-react";
import { useWalletModal } from "@solana/wallet-adapter-react-ui";

function ConnectButton() {
  const { publicKey, wallet, connected, disconnect } = useWallet();
  const { slicedWalletAddress } = useSolanaActiveWallet(publicKey, wallet);
  const { setVisible: setModalVisible } = useWalletModal();

  return (
    <button
      className="wallet-connect-button"
      onClick={() => !connected && setModalVisible(true)}
    >
      {connected ? slicedWalletAddress : "Connect Wallet"}
    </button>
  );
}

Returned Values

  • activePublicKey: PublicKey | undefined

The public key of the currently active wallet

  • activeWalletAddress: string | undefined

The wallet address of the currently active wallet

  • slicedWalletAddress: string | null

The wallet address of the currently active wallet sliced for a shortened format eg: 5KgT...gQdY

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago