Wallet SDK Overview - Phantom Developer Documentation®

The Phantom Wallet SDK provides developers with a robust framework to interact seamlessly with the Solana blockchain. It enables secure wallet integration, transaction signing, and dApp connectivity, ensuring an optimal user experience for blockchain applications.

Introduction to Phantom Wallet SDK

Phantom is a widely used cryptocurrency wallet on Solana. Its SDK allows developers to connect applications to users’ wallets without exposing private keys. Developers can leverage Phantom's features for creating secure and interactive decentralized applications.

Official SDK Documentation

Core Features of the Phantom Wallet SDK

1. Wallet Connection

The SDK allows users to connect their Phantom wallet to your application securely. This connection facilitates reading wallet addresses and balances while maintaining security standards.

Code Example for Connection


const provider = window.phantom?.solana;
if (provider) {
    await provider.connect();
    console.log("Connected to wallet:", provider.publicKey.toString());
}

2. Transaction Signing

Developers can prompt users to sign transactions directly through Phantom, ensuring secure authorization and transparent blockchain operations.

Signing Example


const transaction = new Transaction().add(
    SystemProgram.transfer({
        fromPubkey: provider.publicKey,
        toPubkey: recipient,
        lamports: amount,
    })
);
const signedTransaction = await provider.signTransaction(transaction);

3. Event Listening

The SDK supports listening to wallet events, such as changes in account or network. This feature enhances dynamic dApp responses and real-time updates.

Event Handling Example


provider.on("accountChanged", (publicKey) => {
    console.log("Account changed:", publicKey.toString());
});

Integration Steps

Step 1: Install SDK

Install Phantom SDK using npm:

npm install @phantom-wallet/sdk

Step 2: Initialize Provider

After installation, initialize the provider and check connection:


const provider = window.phantom?.solana;
if (!provider) alert("Phantom Wallet not found!");

Step 3: Connect Wallet

Request user wallet connection using:


await provider.connect();

Step 4: Transaction Signing

Sign transactions securely using the SDK's signTransaction method.

Advanced Features

Multi-Account Support

Phantom SDK supports multiple accounts, enabling developers to manage several wallet addresses simultaneously.

Network Switching

Switch between Solana networks (mainnet, testnet, devnet) to test transactions safely before deploying live.

Security Best Practices

Always avoid storing private keys. Use Phantom’s in-browser provider for signing operations to maintain maximum security.

Resources

For more detailed guides, API references, and community support, refer to the official Phantom Developer Documentation®.

Conclusion

The Phantom Wallet SDK is a powerful tool for Solana dApp development. With wallet connection, transaction signing, and event listening, developers can deliver secure and user-friendly blockchain applications. Leveraging official documentation ensures up-to-date practices and feature integration.

Quick Access Links