simulateTransaction
Simulates sending a transaction
Parameters
Transaction to simulate, as a base-64 encoded string
Configuration object containing:
If true, verify transaction signatures
Commitment level (processed, confirmed, finalized)
Encoding format for the transaction (base58, base64, json)
If true, replace the transaction’s recent blockhash with the most recent blockhash
The minimum slot that the request can be evaluated at
Response
Object containing:
Error if transaction simulation failed, null if simulation succeeded
Array of log messages the transaction instructions output during execution
Array of accounts with their data (if requested)
Number of compute units consumed by the transaction
Program return data from the simulation
Code Examples
Basic Request
Using web3.js
Notes
- Simulates sending a transaction without actually sending it
- The response includes execution logs and errors
- The simulation is performed on the current state
- No state changes are persisted
- Useful for testing and debugging transactions
Best Practices
- Use simulation before sending real transactions
- Check compute unit consumption
- Analyze program logs for errors
- Verify account states after simulation
- Handle simulation errors appropriately
Common Errors
Code | Message | Solution |
---|---|---|
-32601 | Method not found | Verify you’re connected to a Solana RPC node |
-32602 | Invalid params | Check transaction format and encoding |
-32003 | Transaction simulation failed | Verify transaction validity and account balances |
-32004 | Blockhash not found | Use a more recent blockhash |
-32005 | Node is behind | Try a different RPC node |
Use Cases
-
Transaction Analysis
-
Transaction Validation
-
Transaction Optimization