Build with Phantom – Phantom Developer Documentation

Learn how to integrate Phantom wallet support into your Web3 applications, handle wallet connections, transactions, message signing, and follow best practices for secure development.

Introduction to Phantom for Developers

Phantom is a non-custodial Web3 wallet designed primarily for the Solana blockchain. For developers, Phantom provides an easy and secure way to connect users to decentralized applications, manage accounts, sign transactions, and interact with blockchain protocols directly from the browser. Integrating Phantom into your application enhances user experience and security by allowing users to retain full control of their private keys.

As Web3 adoption grows, having wallet integration is essential for decentralized finance (DeFi) applications, NFT platforms, blockchain games, and other Solana-based services. Phantom simplifies the onboarding process while ensuring security standards for both developers and users.

Why Build with Phantom?

Developers choose Phantom for several reasons:

By integrating Phantom, developers can offer seamless Web3 experiences while ensuring transparency and security for users.

Connecting to Phantom Wallet

The first step in integrating Phantom is enabling wallet connection. Applications can detect Phantom by checking the window.solana object in the browser. Users are then prompted to approve or reject the connection request.

if (window.solana && window.solana.isPhantom) {
  try {
    const resp = await window.solana.connect();
    console.log('Connected public key:', resp.publicKey.toString());
  } catch (err) {
    console.error('Connection rejected', err);
  }
} else {
  alert('Phantom Wallet not installed.');
}

Handling connection requests responsibly is important. Always provide clear explanations to users on why your application needs access to their wallet.

Accessing Public Keys

Once the wallet connection is established, Phantom exposes the user’s public key. The public key identifies the user on the blockchain and can be used to fetch balances, NFTs, or transaction history. Developers should never attempt to access private keys or recovery phrases, as Phantom ensures these remain securely stored on the user’s device.

Transaction Signing

Phantom allows decentralized applications to request transaction signing. When a user initiates a transaction, the app sends the transaction object to Phantom for approval. The wallet displays transaction details, including network fees and recipient information, for user verification.

Once approved, Phantom signs the transaction and submits it to the Solana network. Clear and concise transaction prompts are essential to ensure users understand each action before approval.

const transaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: sender.publicKey,
    toPubkey: recipient.publicKey,
    lamports: 1000,
  })
);
const signedTransaction = await window.solana.signTransaction(transaction);
await connection.sendRawTransaction(signedTransaction.serialize());

Message Signing and Authentication

In addition to transactions, Phantom supports message signing. This allows developers to authenticate users or verify wallet ownership without performing on-chain operations. It is commonly used for login systems, off-chain approvals, or decentralized access control.

const message = new TextEncoder().encode("Sign this message to login");
const signedMessage = await window.solana.signMessage(message, 'utf8');
console.log(signedMessage);

Message signing enhances security by proving wallet ownership without incurring blockchain fees.

Handling Network Compatibility

Phantom primarily supports the Solana network. Developers should check the user’s connected network and provide prompts to switch networks if necessary. Proper network handling ensures transaction success and reduces user errors.

User Experience Best Practices

Security Considerations

Developers are responsible for securing their applications. While Phantom keeps private keys safe, applications must be free from malicious scripts and vulnerabilities. Validate all inputs, secure backend APIs, and avoid exposing sensitive logic client-side. Educate users to avoid phishing scams and to never share their recovery phrase.

Common Integration Mistakes

Use Cases for Phantom Integration

Phantom integration is ideal for various decentralized applications, including DeFi platforms, NFT marketplaces, blockchain games, and membership platforms. Developers can leverage wallet connectivity, transaction signing, and message authentication to enable rich Web3 experiences while maintaining security and user control.

Final Thoughts

Building with Phantom empowers developers to create secure, user-friendly Web3 applications. By integrating wallet connections, transaction signing, and message authentication responsibly, developers can provide seamless experiences for Solana users. Following best practices for security, UX, and network handling ensures long-term adoption and trust in your application.