Wallet Adapter
Wallet Adapter¶
Wallet Adapter is the standard library for Solana wallet connections, enabling DApps to easily support multiple wallets.
Core Features¶
Unified Interface A single codebase supporting all wallets: - Phantom - Solflare - Backpack - Ledger - And 20+ other wallets
React Integration
import { useWallet } from '@solana/wallet-adapter-react';
function MyComponent() {
const { publicKey, signTransaction } = useWallet();
return (
<div>
{publicKey ? `Connected: ${publicKey}` : 'Not connected'}
</div>
);
}
UI Components
Installation¶
npm install @solana/wallet-adapter-react @solana/wallet-adapter-react-ui @solana/wallet-adapter-wallets
Wallet Configuration¶
import { PhantomWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapter-wallets';
const wallets = [
new PhantomWalletAdapter(),
new SolflareWalletAdapter(),
];
Features¶
- Connect/disconnect wallets
- Get public key
- Sign transactions
- Sign messages
- Send transactions
Best Practices¶
Error Handling Catch wallet rejection, network errors, etc.
Auto Reconnect Remember the user's selected wallet.
Mobile Adaptation Support the WalletConnect protocol.
Related Concepts¶
- WalletConnect: Mobile connection protocol
- DApp: Decentralized Application
- React: Frontend framework
- Solana Web3.js: Solana's JavaScript SDK
- Anchor: Solana smart contract framework
- Phantom: The most popular Solana wallet
- Solflare: Solana multi-chain wallet
- WalletConnect: Mobile wallet connection protocol
Solana Wallet Adapter greatly simplifies Solana DApp development by providing a standardized wallet integration solution. Its modular design, multi-framework support, and rich wallet ecosystem make it the preferred tool for Solana developers.