| Crates.io | solana-simulate |
| lib.rs | solana-simulate |
| version | 0.1.0 |
| created_at | 2025-03-07 12:06:46.775428+00 |
| updated_at | 2025-03-07 12:06:46.775428+00 |
| description | A Solana transaction simulator |
| homepage | |
| repository | https://github.com/yutianwu/solana-simulate |
| max_upload_size | |
| id | 1582834 |
| size | 2,215,465 |
The Solana Simulator is a tool for testing and simulating Solana programs in a local environment with limited accounts. It allows developers to simulate transactions and observe their effects without a full node, making it ideal for testing and simulation purposes.
For example, if you want to simulate a transaction like the quote for a Raydium swap, you can use the Solana Simulator to simulate the request without a full node.
The simulator is implemented in Rust and provides a straightforward API for simulating Solana transactions. Here's how to use it in your code:
As shown in src/main.rs, you can create a simulator instance with custom configuration:
let config = SimulatorConfig {
accounts_path: PathBuf::from("./accounts.json"),
};
let simulator = Simulator::new(config);
The accounts.json file should contain the accounts that you want to use in the simulation. You can refer the accounts.json file in the example for the format.
The simulator accepts standard Solana transactions. You can create them as follows:
let signer = Keypair::from_bytes(&keypair_bytes).unwrap();
let instruction = Instruction::new_with_bytes(
program_id,
&instruction_data,
vec![
AccountMeta::new(account1, true),
AccountMeta::new(account2, false),
AccountMeta::new_readonly(account3, false),
],
);
let message = Message::new(&[instruction1, instruction2], Some(&signer.pubkey()));
let transaction = Transaction::new(
&[&signer],
message,
Hash::default(),
);
let sanitized_transaction = SanitizedTransaction::try_create(
transaction.into(),
MessageHash::Compute,
None,
simulator.clone(),
&HashSet::new(),
).unwrap();
Execute the transaction simulation:
let simulation_result = simulator.simulate_transaction_unchecked(
&sanitized_transaction,
true,
);