Skip to main content

Wallet Integration

This guide explains how to integrate Solana wallets into your Next.js application using wallet adapters.

Overview

The template uses the official Solana wallet adapter libraries:
  • @solana/wallet-adapter-react - React hooks and context
  • @solana/wallet-adapter-react-ui - Pre-built UI components
  • @solana/wallet-adapter-wallets - Wallet implementations

Wallet Provider Setup

Create wallet/provider.tsx:

Key Concepts

ConnectionProvider

Provides the Solana connection to all child components:

WalletProvider

Manages wallet state and provides hooks:
Options:
  • wallets - Array of wallet adapters to support
  • autoConnect - Automatically reconnect on page load

WalletModalProvider

Provides the wallet selection modal:

Using Wallet Hooks

useWallet

Access wallet state and methods:

useConnection

Access the Solana connection:

useAnchorWallet

Get a wallet compatible with Anchor:

useWalletModal

Control the wallet selection modal:

Header Component with Wallet

Here’s the complete header component with wallet connection:

Supported Wallets

The template supports these wallets out of the box:
WalletAdapter
PhantomPhantomWalletAdapter
SolflareSolflareWalletAdapter
LedgerLedgerWalletAdapter
To add more wallets:

Handling SSR

Next.js renders on the server, but wallets only work in the browser. Use dynamic imports:

Next Steps

Learn how to build the Components for encryption and balance display.