Skip to content

0xStabby/solana-tx-simulator

Repository files navigation

Solana TX Simulator

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.


✨ Features

  • Simulates any base64-encoded or raw transaction
  • Displays SOL and token balance changes

📦 Installation

npm install solana-tx-simulator

🚀 Usage

import { 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);

📘 API

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;

About

simulate solana txs and get balance changes

Resources

Stars

Watchers

Forks

Packages

No packages published