feat: add simulate_transaction tool#100
Open
Ridwannurudeen wants to merge 4 commits intobase:masterfrom
Open
Conversation
Add a transaction simulation tool that lets users preview transactions before execution. Uses viem's simulateContract() for ABI-aware calls and call()/estimateGas() for raw calldata, returning gas estimates, decoded results, and revert reasons — all without broadcasting. Closes base#68
- Validate abi/functionName are provided together (not one without the other) - Validate value is a valid numeric string before BigInt conversion - Separate try/catch for simulation vs gas estimation so a gas estimation failure doesn't mask a successful simulation result - Remove basescanUrl from response (no tx hash in simulation context) - Replace type assertion with proper Hex typing from viem
…ured results - Args are now JSON-parsed before passing to viem: "true" becomes boolean, "[1,2]" becomes an array, plain strings (addresses, hex) stay as-is. This fixes simulation of contracts with bool, tuple, array, or struct params. - Simulation results are recursively serialized (BigInts to strings, nested objects/arrays preserved) instead of collapsed with String(), so tuple and array return values remain structured and usable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
simulate_transactiontool that lets users preview transactions before execution — gas cost, return value, and revert risk — without broadcasting.simulateContract()for ABI-aware calls (decoded return values) andcall()/estimateGas()for raw calldata or plain ETH transfers{ success, gasEstimate, result, basescanUrl }on success,{ success: false, error }on revertCloses #68
Changes
src/tools/simulate/schemas.tsSimulateTransactionSchema(Zod):to,value,data,abi,functionName,argssrc/tools/simulate/index.tsBaseMcpSimulateActionProviderwith@CreateAction simulate_transactionsrc/main.tsbaseMcpSimulateActionProvider()Usage Examples
ABI-aware contract simulation (e.g. preview a USDC transfer):
{ "to": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "abi": "[{\"name\":\"transfer\",\"type\":\"function\",\"inputs\":[{\"name\":\"to\",\"type\":\"address\"},{\"name\":\"amount\",\"type\":\"uint256\"}],\"outputs\":[{\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\"}]", "functionName": "transfer", "args": ["0xRecipient...", "1000000"] }Raw calldata simulation:
{ "to": "0xContractAddress...", "data": "0xa9059cbb000000000000000000000000..." }Plain ETH transfer preview:
{ "to": "0xRecipient...", "value": "1000000000000000000" }Test plan
yarn buildpassesyarn lintpassesyarn formatpassessimulate_transactionwith a known contract, verify gas estimate + decoded result without broadcasting