TL;DR
- Wallets securely store your keys and handle transaction signing
- Hardware wallets keep keys on a separate device
- Software wallets use your computer for secure storage
- Browser extensions are common software wallet implementations
- Solana's Wallet Adapter Library simplifies wallet extension integration
- Websites can request wallet addresses and prompt transaction signatures
Understanding Wallets
In our previous lessons, we explored key pairs - essential for account identification and transaction signing. While public keys can be safely shared, private keys must remain secure. Compromised private keys can lead to asset theft and unauthorized transactions.
A wallet refers to any secure storage solution for private keys. These typically fall into two categories:
- Hardware wallets: Physical devices separate from your computer
- Software wallets: Applications installed on existing devices
Browser extensions are the most common software wallet implementation, enabling website interactions limited to:
- Viewing public keys (addresses)
- Submitting transactions for approval
- Sending approved transactions to the network
Security Considerations
- Never expose private keys to websites
- Only share keys with trusted wallet applications
- Reputable wallets should handle all signing operations
Phantom Wallet
Phantom stands as one of Solana's most popular software wallets, featuring:
- Cross-browser support (Chrome, Brave, Firefox, Edge)
- Mobile applications for on-the-go access
- Robust security features
Solana's Wallet Adapter
This suite of libraries simplifies wallet extension integration, offering:
- Core functionality (
@solana/wallet-adapter-base,@solana/wallet-adapter-react) - UI framework components (
@solana/wallet-adapter-react-ui) - Wallet-specific adapters (including Phantom)
Installation
npm install @solana/wallet-adapter-base \
@solana/wallet-adapter-react \
@solana/wallet-adapter-react-uiWallet Connection Setup
import { ConnectionProvider, WalletProvider } from "@solana/wallet-adapter-react";
import { WalletModalProvider, WalletMultiButton } from "@solana/wallet-adapter-react-ui";
import * as web3 from "@solana/web3.js";
const Home = () => {
const endpoint = web3.clusterApiUrl("devnet");
const wallets = useMemo(() => [], []);
return (
<ConnectionProvider endpoint={endpoint}>
<WalletProvider wallets={wallets}>
<WalletModalProvider>
<WalletMultiButton />
{/* Application content */}
</WalletModalProvider>
</WalletProvider>
</ConnectionProvider>
);
};Accessing Account Information
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
const BalanceDisplay = () => {
const { connection } = useConnection();
const { publicKey } = useWallet();
// Fetch and display balance logic
};Transaction Submission
const { publicKey, sendTransaction } = useWallet();
const { connection } = useConnection();
const handleTransaction = async (recipientAddress, amount) => {
const transaction = new web3.Transaction();
const recipientPubKey = new web3.PublicKey(recipientAddress);
const instruction = web3.SystemProgram.transfer({
fromPubkey: publicKey,
toPubkey: recipientPubKey,
lamports: amount * web3.LAMPORTS_PER_SOL,
});
transaction.add(instruction);
const signature = await sendTransaction(transaction, connection);
return signature;
};Practical Implementation Guide
Setting Up Phantom Wallet
- Install the Phantom browser extension
- Create a new account/wallet
- Enable "Testnet Mode" in Developer Settings
Building a Transaction Interface
- Create wallet connection context
- Implement balance display component
- Develop transaction submission form
- Add transaction confirmation handling
๐ Explore advanced wallet integration techniques
FAQ Section
Q: How do hardware wallets differ from software wallets?
A: Hardware wallets store keys on separate physical devices, while software wallets use applications on existing devices. Hardware wallets generally offer stronger security.
Q: Can my website support multiple wallet providers?
A: Yes, Solana's wallet adapter supports all Wallet Standard-compliant providers. You can implement multiple wallet options or use the wallet selector modal.
Q: Is it safe to connect my Phantom wallet to websites?
A: Reputable websites only request public keys and transaction approvals. Your private keys never leave your wallet. Always verify website authenticity before connecting.
Q: How can I view my transaction history?
A: Transactions can be explored on Solana Explorer using your wallet address. Many wallets also provide built-in transaction history features.
Q: What happens if I lose access to my wallet?
A: Recovery depends on your backup method. Most wallets provide recovery phrases during setup - store these securely offline. Without backups, funds may become permanently inaccessible.