> ## 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.

# Use Imported SVM Wallets

> Learn how to work with imported Solana wallets for common operations like checking balances and signing transactions

## 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

* [Imported a Solana private key](/node/svm/import-private-keys)
* [Set up your authenticated client](/node/quickstart)
* [Installed Solana web3.js](https://docs.solana.com/developing/clients/javascript-api)

## Step 1: Check Wallet Balance

Check the SOL balance of your imported wallet:

```typescript theme={"system"}
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:

```typescript theme={"system"}
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 — returns base58 signature, not the full signed tx
const signatureBase58 = await svmClient.signTransaction({
  walletMetadata,
  transaction: transaction,
});

// Decode and attach signature before broadcasting
import { decodeBase58, addSignatureToTransaction } from '@dynamic-labs-wallet/node-svm';
const signatureBytes = decodeBase58(signatureBase58);
const signedTransaction = addSignatureToTransaction({
  transaction,
  signature: signatureBytes,
  signerPublicKey: new PublicKey(walletMetadata.accountAddress),
});

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

## Step 3: Sign Messages with Imported Wallet

Sign messages for authentication or data integrity:

```typescript theme={"system"}
const message = 'Hello from my imported Solana wallet!';
const signature = await svmClient.signMessage({
  message,
  walletMetadata,
});

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

## Step 4: Check Token Balances

Check SPL token balances in your imported wallet:

```typescript theme={"system"}
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

```typescript theme={"system"}
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 — returns base58 signature, not the full signed tx
  const signatureBase58 = await svmClient.signTransaction({
    walletMetadata,
    transaction,
  });

  // Decode signature and add it back to the transaction before broadcasting
  const { decodeBase58, addSignatureToTransaction } = await import('@dynamic-labs-wallet/node-svm');
  const signatureBytes = decodeBase58(signatureBase58);
  const signedTransaction = addSignatureToTransaction({
    transaction,
    signature: signatureBytes,
    signerPublicKey: new PublicKey(walletAddress),
  });

  // 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:

```typescript theme={"system"}
// Check if wallet requires password for operations
const requiresPassword = await svmClient.requiresPasswordForOperation({
  walletMetadata,
  walletOperation: 'SIGN_MESSAGE',
});

console.log('Requires password for signing:', requiresPassword);

// Verify password if needed
if (requiresPassword) {
  await svmClient.verifyPassword({
    walletMetadata,
    password: 'your-wallet-password',
    walletOperation: 'SIGN_MESSAGE',
  });
  console.log('Password verified successfully');
}
```

## Best Practices

1. **Balance Checking**: Verify sufficient balance before sending transactions
2. **Error Handling**: Implement proper error handling for all wallet operations
3. **Security**: Never expose sensitive information in client-side code
4. **Network Selection**: Use appropriate Solana network (mainnet, devnet, testnet)

## Common Operations

### Check Account Info

```typescript theme={"system"}
const accountInfo = await connection.getAccountInfo(publicKey);
console.log('Account info:', accountInfo);
```

### Get Recent Transactions

```typescript theme={"system"}
const signatures = await connection.getSignaturesForAddress(publicKey, { limit: 10 });
console.log('Recent transactions:', signatures);
```

### Estimate Transaction Fee

```typescript theme={"system"}
const { feeCalculator } = await connection.getRecentBlockhash();
const fee = feeCalculator.lamportsPerSignature;
console.log('Transaction fee:', fee, 'lamports');
```

## Next Steps

* [Sign Solana transactions](/node/svm/sign-transactions)
* [Sign Solana messages](/node/svm/sign-messages)
