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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@phantom/browser-injected-sdk

v1.0.2

Published

The Phantom Browser Injected SDK allows you to interact with the Phantom wallet from your web application. (Browser Extension and Mobile)

Readme

Phantom Browser Injected SDK

The Phantom Browser Injected SDK allows you to interact with the Phantom wallet from your web application. (Browser Extension and Mobile)

Installation

You can install the SDK using npm or yarn:

npm:

npm install @phantom/browser-injected-sdk

yarn:

yarn add @phantom/browser-injected-sdk

Usage

Here's an example of how to import and use the SDK with the Solana plugin:

import { createPhantom } from "@phantom/browser-injected-sdk";
import { createSolanaPlugin } from "@phantom/browser-injected-sdk/solana"; // Import the solana plugin
import { createEthereumPlugin } from "@phantom/browser-injected-sdk/ethereum";

// Create a Phantom instance with the Solana plugin
const phantom = createPhantom({
  plugins: [createSolanaPlugin(), createEthereumPlugin()],
});

// Now you can use the Solana-specific methods
async function connectAndSign() {
  try {
    // Attempt to connect to the wallet
    const connectionResult = await phantom.solana.connect();
    console.log("Connection Result:", connectionResult.address);

    // Example: Sign in (if supported by the specific provider/plugin)
    // Construct SolanaSignInData according to your needs
    const signInData = { domain: window.location.host, statement: "Please sign in to access this dApp." };
    const signInResult = await phantom.solana.signIn(signInData);
    console.log("Sign In Result:", signInResult.address);

    // Example: Sign a message
    const message = new TextEncoder().encode("Hello from Phantom Browser SDK!");
    const signedMessage = await phantom.solana.signMessage(message, "utf8");
    console.log("Signed Message:", signedMessage);
  } catch (error) {
    console.error("Error interacting with Phantom:", error);
  }
}

connectAndSign();

Available Solana Methods

Once the phantom.solana object is initialized, you can access the following methods:

  • connect(opts?: { onlyIfTrusted?: boolean }): Promise<string>
    • Connects to the Phantom wallet. Optionally, onlyIfTrusted can be set to true to only connect if the dApp is already trusted.
  • disconnect(): Promise<void>
    • Disconnects from the Phantom wallet.
  • getAccount(): Promise<string | undefined>
    • Gets the current connected address
  • signIn(): Promise<SignInResult>
    • Initiates a sign-in request to the wallet.
  • signMessage(message: Uint8Array | string, display?: 'utf8' | 'hex'): Promise<SignedMessage>
    • Prompts the user to sign a given message.
  • signAndSendTransaction(transaction: Transaction): Promise<{ signature: string; address?: string }>
    • Prompts the user to sign and send a Kit Transaction and returns the confirmed signature.

Event Handling

The SDK also allows you to listen for connect, disconnect, and accountChanged events:

  • addEventListener(event: PhantomEventType, callback: PhantomEventCallback): () => void

    • Registers a callback that will be invoked when the specified event occurs.
    • For the connect event, the callback receives the public key (as a string) of the connected account.
    • For the disconnect event, the callback receives no arguments.
    • For the accountChanged event, the callback receives the new public key (as a string).
    • Returns a function that, when called, will unregister the callback.
    • Multiple callbacks can be registered for the same event.

    Example:

    const phantom = createPhantom({ plugins: [createSolanaPlugin()] });
    
    const handleConnect = (address: string) => {
      console.log(`Wallet connected with public key: ${address}`);
    };
    
    const clearConnectListener = phantom.solana.addEventListener("connect", handleConnect);
    
    const handleAccountChanged = (newAddress: string) => {
      console.log(`Account changed to: ${newAddress}`);
    };
    
    const clearAccountChangedListener = phantom.solana.addEventListener("accountChanged", handleAccountChanged);
    
    // To stop listening for a specific event:
    // clearConnectListener();
    // clearAccountChangedListener();
  • removeEventListener(event: PhantomEventType, callback: PhantomEventCallback): void

    • Unregisters a previously registered callback for the specified event.

    Example:

    const phantom = createPhantom({ plugins: [createSolanaPlugin()] });
    
    const handleDisconnect = () => {
      console.log("Wallet disconnected");
    };
    
    phantom.solana.addEventListener("disconnect", handleDisconnect);
    
    // To stop listening for this specific disconnect event:
    // phantom.solana.removeEventListener("disconnect", handleDisconnect);

Creating a transaction

Phantom's SDK uses the @solana/kit library to create transactions. You can use the createTransactionMessage function to create a transaction message.

import {
  createSolanaRpc,
  pipe,
  createTransactionMessage,
  setTransactionMessageFeePayer,
  setTransactionMessageLifetimeUsingBlockhash,
  address,
  compileTransaction,
} from "@solana/kit";

// Example: Sign and send a transaction

const rpc = createSolanaRpc("https://my-rpc-url.com"); // Replace with your own RPC URL

const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();

const transactionMessage = pipe(
  createTransactionMessage({ version: 0 }),
  tx => setTransactionMessageFeePayer(address(userPublicKey as string), tx),
  tx => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
);

const transaction = compileTransaction(transactionMessage);

const { signature } = await phantomInstance.solana.signAndSendTransaction(transaction);