This guide shows you how to work with imported Solana wallets for common operations. Once you’ve imported a private key, you’ll need to retrieve key shares and perform various wallet operations.
Use your imported wallet to sign Solana transactions:
Copy
Ask AI
import { Transaction, SystemProgram, LAMPORTS_PER_SOL } from '@solana/web3.js';// Create a SOL transfer transactionconst 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 walletconst signedTransaction = await svmClient.signTransaction({ senderAddress: 'YourImportedSolanaWalletAddress', externalServerKeyShares: keyShares, transaction: transaction, password: 'your-wallet-password', // if wallet is password-protected});console.log('Transaction signed with imported wallet');
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';// Get all token accounts for the walletconst tokenAccounts = await connection.getTokenAccountsByOwner(publicKey, { programId: TOKEN_PROGRAM_ID,});console.log('Token accounts found:', tokenAccounts.value.length);// Get balance for a specific tokenfor (const account of tokenAccounts.value) { const accountInfo = await connection.getTokenAccountBalance(account.pubkey); console.log(`Token ${account.pubkey.toString()}: ${accountInfo.value.uiAmount}`);}