Transaction Simulation: A Useful Wallet Check, Not a Promise
Simulate transactions to expose likely reverts and surprising effects, but account for approvals, pending state and the gap between a local result and final execution.

A wallet asks the user to sign a transaction and displays "simulation successful." It is tempting to translate that into "safe." The simulator did not establish that. It evaluated a proposed operation against a particular state with particular assumptions.
Simulation is useful because it can reveal a likely revert, estimate execution requirements and expose some unexpected token movement. The value disappears when the interface presents that evidence as a guarantee of the user's final outcome.
Define what you are simulating
Record the chain, sender, destination, calldata and native value. A simulation with the wrong sender can pass even though the actual wallet has no permission. A simulation on the wrong chain can evaluate a different contract at the same address.
Specify the state context: latest, pending or a supported historical block. Providers differ in supported methods and extensions. An ordinary eth_call is not identical to a specialised simulator that returns traces and balance deltas.
A call that succeeds says the EVM execution did not revert in that context. It does not establish fair pricing, trustworthy contract ownership or the absence of a harmful future approval.
Use maintained libraries for encoding
ABI encoding and bigint handling are easy places to introduce avoidable mistakes. This illustrative viem example simulates an ERC-20 transfer with a validated configuration and caller-provided amount in base units:
import { parseAbi } from class="text-code-string">"viem";
const abi = parseAbi([
class="text-code-string">"function transfer(address to, uint256 amount) returns (bool)",
]);
const result = await publicClient.simulateContract({
address: configuredTokenAddress,
abi,
functionName: class="text-code-string">"transfer",
args: [validatedRecipient, amountInBaseUnits],
account: connectedAccount,
});
if (result.result !== true) {
throw new Error(class="text-code-string">"Token did not report a successful transfer");
}
class="text-code-comment">// Present the operation for review before submitting result.request.The address variables must already be validated for the selected chain, and the account must be the intended signer. This ABI assumes a token returning a boolean; token implementations vary. Do not treat this fragment as universal handling for every asset.
Never convert token amounts through JavaScript floating-point numbers. Parse the user's decimal input with the token's verified decimals and preserve integer base units throughout the transaction path.
Check the surrounding prerequisites
A router call may depend on token allowance, balance, deadline and price limits. Simulate the actual intended transaction, not a simplified transfer that omits those conditions.
When an approval is required first, the current state may cause the later swap simulation to fail. A simulator with state overrides or bundled transaction support may help explore the sequence, but those features are provider-specific and may not faithfully model every production condition.
If you simulate with an artificial allowance, explain that assumption. It does not mean the user's current wallet is ready to execute. Do not automatically send an unlimited approval just to make the simulation green.
Inspect effects, not only success
| Evidence | What it can help reveal | |---|---| | Revert reason | Failed requirement or contract error | | Gas estimate | Approximate execution resources | | Token deltas | Expected transfers in the simulated path | | Approval changes | New spending permissions | | Call trace | Contracts reached during execution |
A trace can be lengthy and incomplete depending on tooling. Summarise relevant effects without hiding the recipient and spender addresses. Resolve friendly names carefully; a recognisable label is not proof that an address is legitimate.
Fee estimation is separate from understanding the action. An affordable transaction can still approve a dangerous spender. A transaction showing no immediate asset loss can still grant a permission that permits loss later.
Account for state changing underneath you
Between simulation and inclusion, balances, allowances, prices and contract state can change. Other transactions may execute first. A successful simulation can become a revert, and an estimated output can shift.
Use contract-level limits such as slippage bounds and deadlines where the protocol supports them. Those constrain execution on-chain rather than relying on a screenshot of earlier state. Make the limits understandable and avoid increasing them automatically after a failure.
Contracts can inspect block context and caller conditions. Simulation services may also use assumptions that differ from real inclusion. A malicious contract can exploit the gap between a reassuring preview and actual behaviour. Do not present any preview as a security audit.
Handle the complete transaction lifecycle
After the user reviews and signs, track submission, pending status, receipt and the application's chosen confirmation or finality policy. Submission of a hash is not completion. Detect replacements and cancellations where the wallet and chain tooling support them.
If a transaction reverts, explain the observed error without suggesting that the user repeat it blindly. If the network is congested, a pending operation may need a replacement strategy rather than a second independent operation.
Keep transaction hashes and chain IDs together in support records. The same hash-shaped string without chain context is not a useful operational identifier.
Test failure cases deliberately
Use a test environment to exercise an insufficient balance, wrong sender, missing approval, expired deadline, unsupported chain and a contract returning false. Test a state change after simulation and before execution.
Review the interface's language as part of the safety test. "No revert detected in this simulation" is defensible evidence. "Guaranteed safe" is not.
Simulation belongs in a layered workflow: validated inputs, known contract configuration, explicit permissions, execution limits and honest status handling. It should help the user understand a decision, not replace that decision with a green badge.
Paj Digital Labs
The engineering journal of Paj Digital Solutions — hosting, server infrastructure and web engineering, written by the people who run the servers.
Related reading

Solana Transaction Operations: Blockhash Expiry, Commitments and Retries
A timed-out submission may still have landed. Track signatures, validity windows and commitment levels before rebuilding a transaction and risking a duplicate business action.

Blockchain Dependency Incidents: Circuit Breakers for RPC and Indexer Failures
A stale indexer and an unavailable RPC need different responses. Monitor data freshness, stop unsafe writes and preserve transaction tracking when chain infrastructure degrades.

ERC-4337 Account Abstraction: Bundlers, Paymasters and the Product Boundary
Smart accounts can improve recovery and transaction UX, but their dependencies need explicit limits. Understand user operations, sponsorship and deployed versions before treating gasless as free.