Documentation Index
Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This guide shows you how to work with imported Solana wallets for common operations. Once you’ve imported a private key, you can perform various wallet operations directly.
Prerequisites
Step 1: Check Wallet Balance
Check the SOL balance of your imported wallet:
import { Connection, PublicKey, LAMPORTS_PER_SOL } from '@solana/web3.js';
const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');
const publicKey = new PublicKey('YourImportedSolanaWalletAddress');
const balance = await connection.getBalance(publicKey);
console.log('Balance:', balance, 'lamports');
console.log('Balance in SOL:', balance / LAMPORTS_PER_SOL);
Step 2: Sign Transactions with Imported Wallet
Use your imported wallet to sign Solana transactions:
import { Transaction, SystemProgram, LAMPORTS_PER_SOL } from '@solana/web3.js';
// Create a SOL transfer transaction
const fromPubkey = new PublicKey('YourImportedSolanaWalletAddress');
const toPubkey = new PublicKey('11111111111111111111111111111112');
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey,
toPubkey,
lamports: LAMPORTS_PER_SOL * 0.001, // 0.001 SOL
})
);
// Sign with imported wallet
const signedTransaction = await svmClient.signTransaction({
senderAddress: 'YourImportedSolanaWalletAddress',
transaction: transaction,
});
console.log('Transaction signed with imported wallet');
Step 3: Sign Messages with Imported Wallet
Sign messages for authentication or data integrity:
const message = 'Hello from my imported Solana wallet!';
const signature = await svmClient.signMessage({
message,
accountAddress: 'YourImportedSolanaWalletAddress',
});
console.log('Message signed:', signature);
Step 4: Check Token Balances
Check SPL token balances in your imported wallet:
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
// Get all token accounts for the wallet
const tokenAccounts = await connection.getTokenAccountsByOwner(publicKey, {
programId: TOKEN_PROGRAM_ID,
});
console.log('Token accounts found:', tokenAccounts.value.length);
// Get balance for a specific token
for (const account of tokenAccounts.value) {
const accountInfo = await connection.getTokenAccountBalance(account.pubkey);
console.log(`Token ${account.pubkey.toString()}: ${accountInfo.value.uiAmount}`);
}
Complete Example: Send SOL from Imported Wallet
export const sendSolFromImportedWallet = async ({
walletAddress,
toAddress,
amount,
}: {
walletAddress: string;
toAddress: string;
amount: number; // Amount in SOL
}) => {
const svmClient = await authenticatedSvmClient();
const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');
// Check balance first
const publicKey = new PublicKey(walletAddress);
const balance = await connection.getBalance(publicKey);
const amountLamports = LAMPORTS_PER_SOL * amount;
if (balance < amountLamports) {
throw new Error('Insufficient balance');
}
// Create transaction
const fromPubkey = new PublicKey(walletAddress);
const toPubkey = new PublicKey(toAddress);
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey,
toPubkey,
lamports: amountLamports,
})
);
// Sign transaction
const signedTransaction = await svmClient.signTransaction({
senderAddress: walletAddress,
transaction,
});
// Send transaction
const txHash = await connection.sendRawTransaction(signedTransaction.serialize());
await connection.confirmTransaction(txHash);
return txHash;
};
// Usage
const txHash = await sendSolFromImportedWallet({
walletAddress: 'YourImportedSolanaWalletAddress',
toAddress: 'RecipientAddress',
amount: 0.001,
});
console.log('SOL sent:', txHash);
Step 5: Verify Wallet Operations
Verify that your imported wallet can perform operations:
// Check if wallet requires password for operations
const requiresPassword = await svmClient.requiresPasswordForOperation({
accountAddress: 'YourImportedSolanaWalletAddress',
walletOperation: 'SIGN_MESSAGE',
});
console.log('Requires password for signing:', requiresPassword);
// Verify password if needed
if (requiresPassword) {
await svmClient.verifyPassword({
accountAddress: 'YourImportedSolanaWalletAddress',
password: 'your-wallet-password',
walletOperation: 'SIGN_MESSAGE',
});
console.log('Password verified successfully');
}
Best Practices
- Balance Checking: Verify sufficient balance before sending transactions
- Error Handling: Implement proper error handling for all wallet operations
- Security: Never expose sensitive information in client-side code
- Network Selection: Use appropriate Solana network (mainnet, devnet, testnet)
Common Operations
Check Account Info
const accountInfo = await connection.getAccountInfo(publicKey);
console.log('Account info:', accountInfo);
Get Recent Transactions
const signatures = await connection.getSignaturesForAddress(publicKey, { limit: 10 });
console.log('Recent transactions:', signatures);
Estimate Transaction Fee
const { feeCalculator } = await connection.getRecentBlockhash();
const fee = feeCalculator.lamportsPerSignature;
console.log('Transaction fee:', fee, 'lamports');
Next Steps