simulate-tx
v0.1.1
Published
EVM transaction simulator — simulate what a tx will do before sending it
Maintainers
Readme
simulate-tx
EVM transaction simulator — simulate what a tx will do before sending it.
Works on any EVM chain (Ethereum, Base, Arbitrum, Optimism, Polygon, BSC, etc.) and EraVM chains (ZkSync, Lens, Cronos zkEVM, Zircuit).
Powered by revm, compiled to WebAssembly.
Install
npm install simulate-txUsage
const { simulate, simulateFromObject } = require('simulate-tx');
// From a JSON string
const result = await simulate('https://eth.llamarpc.com', JSON.stringify({
from: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
to: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
data: '0x095ea7b3...',
value: '0x0',
chain_id: 1,
}));
// Or pass a JS object directly
const result = await simulateFromObject('https://base-rpc.publicnode.com', {
from: '0x...',
to: '0x...',
data: '0x...',
value: '0x0',
chain_id: 8453,
});Output
{
success: true,
gas_used: 55582,
return_data: '0x...0001',
revert_reason: null, // decoded string if tx reverts
effects: [
{
type: 'Erc20Approval',
token: '0xa0b8...',
owner: '0xd8da...',
spender: '0x6e4c...',
value: '0x2386f26fc10000'
}
],
logs: [...], // raw event logs (EVM chains only)
calls: [...] // internal call trace
}Effect types
| Type | Description |
|------|-------------|
| NativeTransfer | ETH/native token transfer |
| Erc20Transfer | ERC-20 transfer |
| Erc20Approval | ERC-20 approve |
| Erc721Transfer | NFT transfer |
| Erc1155TransferSingle | ERC-1155 single transfer |
| Erc1155TransferBatch | ERC-1155 batch transfer |
| ApprovalForAll | Operator grant (ERC-721/1155) |
| Permit | EIP-2612 permit |
| Permit2Approval | Uniswap Permit2 |
| ContractCreated | New contract deployed |
| SelfDestruct | Contract self-destructed |
Input fields
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| from | address | yes | Sender |
| to | address | no | Recipient (omit for contract creation) |
| data | hex string | yes | Calldata |
| value | hex uint256 | yes | Wei to send |
| chain_id | number | yes | Chain ID |
| block_number | number | no | Block to fork from (default: latest) |
| gas_limit | number | no | Gas limit (default: 30M) |
How it works
- EVM chains: forks state via
eth_createAccessList, prefetches in parallel, executes in revm with an inspector - EraVM chains: parallel
eth_call+debug_traceCall, decodes effects from calldata
Engine is auto-selected by chain ID.
Links
License
MIT
