Overview

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.

Prerequisites

Step 1: Retrieve Your Wallet Information

After importing a wallet, you’ll need to get the external server key shares for signing operations:
import { authenticatedSvmClient } from './client';

const svmClient = await authenticatedSvmClient();

// Get external server key shares for your imported wallet
const keyShares = await svmClient.getExternalServerKeyShares({
  accountAddress: 'YourImportedSolanaWalletAddress'
});

console.log('Key shares retrieved:', keyShares.length);

Step 2: 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 3: 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',
  externalServerKeyShares: keyShares,
  transaction: transaction,
  password: 'your-wallet-password', // if wallet is password-protected
});

console.log('Transaction signed with imported wallet');

Step 4: 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',
  externalServerKeyShares: keyShares,
  password: 'your-wallet-password', // if wallet is password-protected
});

console.log('Message signed:', signature);

Step 5: 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,
  password,
}: {
  walletAddress: string;
  toAddress: string;
  amount: number; // Amount in SOL
  password?: string;
}) => {
  const svmClient = await authenticatedSvmClient();
  const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');

  // Get key shares for imported wallet
  const keyShares = await svmClient.getExternalServerKeyShares({
    accountAddress: walletAddress,
  });

  // 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,
    externalServerKeyShares: keyShares,
    transaction,
    password,
  });

  // 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,
  password: 'your-wallet-password',
});

console.log('SOL sent:', txHash);

Step 6: 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

  1. Key Share Management: Always retrieve fresh key shares before operations
  2. Balance Checking: Verify sufficient balance before sending transactions
  3. Password Handling: Check if password is required and handle accordingly
  4. Error Handling: Implement proper error handling for all wallet operations
  5. Security: Never expose key shares in client-side code
  6. 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