Simulate a Solana transaction and view detailed balance changes for any user — including SOL and SPL tokens. Useful for previews before submitting swaps or transfers.
🔍 Built for developers integrating with Jupiter and other Solana DEXes, wallets, or explorers.
- Simulates any base64-encoded or raw transaction
- Displays SOL and token balance changes
npm install solana-tx-simulatorimport { Connection, PublicKey } from "@solana/web3.js";
import { simulateEncodedTransaction } from "solana-tx-simulator";
const connection = new Connection("https://api.mainnet-beta.solana.com");
const user = new PublicKey("your-wallet-public-key");
const encodedTx = "base64_transaction_string";
const result = await simulateEncodedTransaction(connection, encodedTx, user);
console.log(result);Simulate a base64-encoded transaction:
simulateEncodedTransaction(connection, encodedTx, signerPublicKey)Simulate a VersionedTransaction:
simulateTransaction(connection, transaction, signerPublicKey)Both return a BalanceChangeResult:
type BalanceChange = {
preBalance: number,
postBalance: number,
change: number,
}
type SuccessResult = {
success: true;
balanceChanges: Record<string, BalanceChange>;
};
type FailureResult = {
success: false;
error?: string;
};
type BalanceChangeResult = SuccessResult | FailureResult;