Skip to content
chouandyPublic

About

Simulate an Ethereum mainnet transaction before you sign it and see every balance it moves. Works for a 1/1 Safe or a plain EOA, through your own RPC. Read-only, never touches keys.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

txdelta

Simulate a transaction before you sign it, and see what it would do: which addresses lose or gain which assets and how much, which approvals it grants, and whether it reverts. Two kinds of transaction are supported:

  • txdelta safe: a 1/1 Safe's execTransaction. It also shows whether the transaction changes the Safe itself, and recomputes the safeTxHash and the exact execTransaction calldata locally, so you can compare them with what your wallet shows. It is built for a Safe with threshold 1 whose only signer is the owner EOA that executes it; Safes with a higher threshold are refused.
  • txdelta eoa: a plain call sent from your EOA (see EOA transactions).

Install

Requires Go 1.27 or later.

go install github.com/chouandy/txdelta@latest

or from a clone:

make dev        # builds bin/txdelta

RPC setup

The RPC URL is read from a variable named after the chain, TXDELTA_RPC_URL_<CHAIN>; only mainnet is supported today, so that is TXDELTA_RPC_URL_MAINNET. It is never taken from a flag or a prompt, so an API key does not end up in your shell history or on screen. The tool never prints the URL; it prints only where it came from (process env or the absolute path of the .env file).

The process environment wins. Otherwise txdelta reads .env in the current directory:

cp .env.example .env
# edit .env: TXDELTA_RPC_URL_MAINNET=https://your-provider.example/<key>
chmod 600 .env

Only TXDELTA_RPC_URL_* keys are read from .env, and nothing is exported to the environment. A .env owned by another user is refused; one readable by group or others gets a warning. These owner and permission checks are Unix-only: on Windows they are skipped, so protect .env with its ACL there.

Accepted risk. A .env in whatever directory you run txdelta from is trusted. If you run it inside a cloned repository that ships its own .env, that file can point txdelta at a hostile RPC endpoint, which can fabricate a consistent, clean-looking result. The only protection is that the .env path is shown before anything is simulated, so check it: in interactive mode in the summary you confirm, and with every field passed as flags (or stdin not a terminal) only as a warning: RPC URL taken from <source> line, with no confirm. In that case only the locally computed hashes and calldata are still trustworthy.

Provider requirements

The provider must support:

  • eth_simulateV1 with traceTransfers, stateOverrides with code, returnFullTransactions (for txdelta eoa), and the EIP-1898 block parameter {blockHash, requireCanonical: true} (also for eth_call, eth_getCode, eth_getStorageAt, eth_getBalance);
  • a gas budget for two 16,777,216-gas calls per simulated block: the transaction and one read call run together in each request, so the pinned block's gas limit must be at least 33,554,432.

Usage

txdelta          # asks whether you are about to sign a Safe or an EOA transaction
txdelta safe     # the Safe flow
txdelta eoa      # the EOA flow
txdelta -h       # the commands; txdelta safe -h and txdelta eoa -h list each command's flags

The rest of this section is the Safe flow; the EOA flow is in EOA transactions.

Pick the chain, then paste the transaction JSON the Safe UI transaction details page copies (all of to, value, data, operation, nonce, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver; gasPrice must be 0 and gasToken the zero address), then enter the Safe address and the sender. Leave the JSON empty to enter the fields one by one instead; the JSON prompt is skipped when any transaction field comes as a flag.

Entered one by one, the fields are exactly as the Safe UI transaction details page shows them: Safe address, sender (the owner EOA), to, value (wei), data (hex), operation, nonce. The nonce prompt shows the Safe's current on-chain nonce as a hint. Every field except the advanced ones must be filled in: Enter on an empty field is refused (shift+tab still goes back), and empty calldata is typed as 0x. Advanced fields (safeTxGas, baseGas, refundReceiver) default to zero; after Edit, declining them keeps the previous values. gasPrice and gasToken are always zero.

In interactive mode a summary with the RPC source and the data byte length and keccak256 (to confirm a long paste arrived whole) is shown, and nothing is simulated until you choose Simulate. Edit goes through the prompts again with your previous answers filled in; Cancel exits.

Every field can be passed as a flag instead; prompts appear only for the ones you leave out:

txdelta safe --chain mainnet --safe 0x... --sender 0x... --to 0x... --value 0 --data 0x... --operation 0 \
  --nonce 12 [--safe-tx-gas 0] [--base-gas 0] [--refund-receiver 0x...]

With every basic field passed, or when stdin is not a terminal, nothing is prompted and there is no summary or confirm: only a warning: RPC URL taken from <source> line is printed (to stderr) before the simulation runs, and a missing field is an error. The report goes to stdout; errors and warnings go to stderr.

Before you sign: what to check

Stop at the first item that does not match what you meant to do.

  1. Inputs. The JSON you copied is for the nonce you mean to sign, and the summary's RPC source is the .env you expect. Any other .env path means the result cannot be trusted.
  2. Safe tx lines (top of the report). to is the contract or recipient you meant (check its name on a block explorer), operation is 0 (call) unless this is an official MultiSend batch, and value and selector are what you expect (an ERC20 transfer is 0xa9059cbb).
  3. safeTxHash. It matches the hash your hardware wallet shows, at least the first and last 6–8 characters. This ties what you sign to what was simulated.
  4. Result sections. execTransaction succeeded; no [HIGHEST] red flag, and every [warning] understood; the Safe config diff says no change unless changing owners, threshold, modules, guards, the fallback handler or the singleton is the point of this transaction.
  5. Balance changes. Who loses and who gains which asset matches your intent, and no address you do not know gains anything. A [MISMATCH] on an interest-bearing token (Aave aTokens, stETH) is expected: its balance grows without events.
  6. Approvals. none, or only the approval you meant, to the spender you meant. Look twice at unlimited amounts.
  7. RESULT. clean (exit 0) means txdelta found nothing, not that items 1–6 can be skipped. NOT clean names its reasons. error: (exit 2) means nothing was verified.

What clean cannot tell you is in Simulation caveats; item 2 is the check for those cases.

EOA transactions

txdelta eoa
txdelta eoa --chain mainnet --from 0x... --to 0x... --value 0 --data 0x... [--gas-limit 120000]

Enter from (your EOA), to, value (wei) and data (hex; 0x for none) as your wallet shows them, then the gas limit your wallet shows (Enter on an empty answer keeps the default). The same prompt rules, summary and Simulate / Edit / Cancel apply as in the Safe flow.

txdelta stops before simulating (exit 1) when from has code (a contract, or an EOA delegated with EIP-7702: not supported) or when value exceeds from's balance. Calldata sent to an address with no code (other than a precompile) is a highest-severity flag: nothing would run it, so it cannot be what you meant.

The report shows the transaction (from, to, value, gas limit, selector, the full calldata and its keccak256), then the same sections as the Safe report without the Safe ones: red flags, balance changes of every holder (from first), approvals, NFT transfers and unrecognised logs.

Before you sign an EOA transaction:

  1. Transaction lines. to, value and the calldata match what your wallet will sign; compare the full calldata, or its keccak256, with the wallet's data. A swapped recipient is only visible here and in the balance changes.
  2. Balance changes. Every holder that gains is one you meant to pay.
  3. Approvals. none, or only the one you meant.
  4. Gas limit. Pass your wallet's limit (--gas-limit or at the prompt). With the default, a contract can act differently under your wallet's lower limit, and the report says so.
  5. RESULT, as in the Safe flow.

What txdelta eoa does not cover:

  • Off-chain signatures (permit, Permit2 signatures, CoW / UniswapX orders): they are not transactions, so nothing is simulated. Read what a signature request grants before signing it.
  • EIP-7702 delegation and type-4 transactions.
  • Whether from can pay the gas fee on top of value, and any access list your wallet adds (the simulated call has none, so gas metering can differ).
  • Balance changes that emit no event (rebasing tokens), and state a contract keeps per caller, as in the Safe flow.

What it does not do

  • It is read-only. It uses only eth_chainId, eth_getBlockByNumber, eth_call, eth_getCode, eth_getStorageAt, eth_getBalance and eth_simulateV1. It never asks for a private key, mnemonic or keystore, and it never signs or broadcasts anything.
  • No USD prices, no pending transactions from the Safe Transaction Service, no third-party simulation service.

Simulation caveats

  • The result is a prediction at one pinned block (shown in the output), with a fixed 16,777,216 gas for execTransaction. Real execution happens later, against different state, and can differ.
  • In the simulated block BASEFEE and tx.gasprice are 0. A contract can detect that it is being simulated and behave differently than it will in real execution.
  • The simulation signs with the owner-as-sender pre-approved signature. If the Safe has a guard, the guard may treat the real signature differently; this is flagged.
  • Balances that change with no event (rebasing tokens) cannot be discovered and are not shown.
  • Gas paid by the sender is not included.
  • clean does not cover state a third-party contract keeps per caller: an authorisation (Morpho setAuthorization), a credit delegation (Aave approveDelegation), a pre-signed CoW order, a gauge deposit approval. Such a call moves no tokens and emits no ERC20 / Permit2 approval, so it can come out clean. Check the Safe tx to / selector lines against what you meant to sign; calls to the Safe's own handler, guards, modules and other owners are flagged.

Exit codes

  • 0: clean. The transaction succeeded in simulation, every balance was readable, and nothing of highest severity was flagged.
  • 1: do not sign as-is. The run aborted (for example the nonce or safeTxHash did not match), the Safe was refused, from has code or cannot pay value, the simulated execution failed, a balance was unreadable, or a highest-severity flag was raised.
  • 2: no verdict. Bad usage, a cancelled prompt, or a failed RPC, simulation or pre-execution Safe config read, including an RPC that ran the EOA call with less gas than asked (a provider gas cap). RPC failures are printed as fixed diagnostics (method and category) and never include the provider's error text or the URL. A failure after the red flags were computed prints every highest-severity flag first: a transaction that breaks the simulation does not get to hide them behind what reads like a provider error.

About

Simulate an Ethereum mainnet transaction before you sign it and see every balance it moves. Works for a 1/1 Safe or a plain EOA, through your own RPC. Read-only, never touches keys.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages