Skip to main content
Bookie simulates every transaction before presenting it for approval, preventing failures and unexpected outcomes.

How Simulation Works

Before you see a transaction in your wallet, Bookie runs it through Solana’s simulation engine:
1

Build Transaction

Construct transaction with all instructions and accounts
2

Simulate Execution

Run transaction against current blockchain state
3

Analyze Results

Check for errors, compute usage, and balance changes
4

Present to User

Only show transaction if simulation succeeds

What Simulation Catches

Insufficient Balance

Not enough tokens or SOL for transaction

Slippage Exceeded

Price moved beyond acceptable range

Account Errors

Missing or invalid token accounts

Program Failures

Smart contract execution errors

Simulation API

Bookie uses Solana’s simulateTransaction RPC method:
const simulation = await connection.simulateTransaction(
  transaction,
  {
    commitment: 'confirmed',
    sigVerify: false
  }
);

if (simulation.value.err) {
  throw new Error(`Simulation failed: ${simulation.value.err}`);
}

console.log('Compute units used:', simulation.value.unitsConsumed);
console.log('Logs:', simulation.value.logs);

Simulation Response

A successful simulation returns:
FieldDescription
errError object (null if successful)
logsProgram execution logs
unitsConsumedCompute units used
accountsPost-transaction account states

Error Types

Common simulation errors and their meanings:

Insufficient Funds

Error: Attempt to debit an account but found no record of a prior credit
Cause: Not enough SOL or tokens in wallet Solution: Add funds before retrying

Slippage Tolerance Exceeded

Error: Slippage tolerance exceeded
Cause: Price moved more than allowed slippage Solution: Increase slippage or wait for better price

Account Not Found

Error: AccountNotFound
Cause: Token account doesn’t exist Solution: Bookie automatically creates account (adds ~0.002 SOL to cost)

Blockhash Expired

Error: Blockhash not found
Cause: Transaction took too long to build Solution: Bookie automatically rebuilds with fresh blockhash

Compute Budget Optimization

Simulation reveals exact compute units needed:
const simulation = await connection.simulateTransaction(transaction);
const computeUnits = simulation.value.unitsConsumed;

// Add 20% buffer for safety
const computeLimit = Math.ceil(computeUnits * 1.2);

transaction.add(
  ComputeBudgetProgram.setComputeUnitLimit({
    units: computeLimit
  })
);
Benefits:
  • Prevents out-of-compute errors
  • Optimizes transaction fees
  • Improves success rate

Balance Change Preview

Simulation shows expected balance changes: Before Simulation:
  • SOL: 10.5
  • USDC: 100
Simulated Swap: 1 SOL → USDC After Simulation:
  • SOL: 9.499995 (1 SOL + 0.000005 fee)
  • USDC: 250.43 (received from swap)
Actual execution may differ slightly from simulation due to price movements between simulation and execution.

Simulation Limitations

Simulation cannot predict:
  • Price Changes: Market moves between simulation and execution
  • Network Congestion: Transaction may fail due to congestion
  • MEV Attacks: Sandwich attacks happen after simulation
  • Concurrent Transactions: Other transactions affecting same accounts
Simulation success does not guarantee execution success. Always monitor transactions after submission.

Performance

MetricValue
Simulation Time (p50)12ms
Simulation Time (p99)28ms
Success Rate99.7%
False Positives0.3%

Advanced Features

Preflight Commitment

Bookie uses confirmed commitment for simulation:
const simulation = await connection.simulateTransaction(
  transaction,
  { commitment: 'confirmed' }
);
Options:
  • processed: Fastest, least reliable
  • confirmed: Balanced (default)
  • finalized: Slowest, most reliable

Signature Verification

Disabled during simulation for speed:
const simulation = await connection.simulateTransaction(
  transaction,
  { sigVerify: false }
);
Signatures are verified during actual execution.

Debugging Failed Simulations

If simulation fails, Bookie provides detailed logs:
Program log: Instruction: Swap
Program log: Input: 5000000000 lamports
Program log: Error: Slippage tolerance exceeded
Program log: Expected minimum: 750000000
Program log: Actual output: 745000000
Use these logs to understand why a transaction would fail.

Solana RPC Methods

Learn more about simulateTransaction RPC method