A server application that simulates Ethereum (and other EVM chain) transactions using Anvil forks. This allows you to test complex transaction sequences without spending real funds.
- Simulate transactions on any EVM-compatible chain
- Execute multiple transactions in sequence
- Impersonate any account for testing
- Comprehensive transaction result reporting
- Error parsing
- Support for "expectations" (e.g. users balance is adjusted)
- Node.js (v16 or higher)
- Foundry installed (for Anvil)
git clone https://github.com/buidlguidl/transaction-simulator.git
cd transaction-simulator
yarn install
yarn start
The server will start in HTTP mode by default. To use HTTPS, place your SSL certificates in the certs
directory:
certs/key.pem
: SSL private keycerts/cert.pem
: SSL certificate
Simulates a sequence of transactions on a fork of the provided RPC URL.
Request body:
{
"rpcUrl": "https://eth-mainnet.alchemyapi.io/v2/your-api-key",
"transactions": [
{
"from": "0xsenderAddress",
"to": "0xtargetAddress",
"data": "0xcalldata",
"value": "1000000000000000000",
"gasLimit": "100000"
}
],
"expect": [] // To Be Implemented
}
Response:
{
"success": true,
"results": {
"transactions": [
{
"success": true,
"hash": "0xtransactionHash",
"error": "error message",
"gasUsed": "21000"
}
]
}
}
Simulating a WETH deposit:
curl -X POST http://localhost:3000/api/simulate \
-H "Content-Type: application/json" \
-d '{
"rpcUrl": "https://eth-mainnet.alchemyapi.io/v2/your-api-key",
"transactions": [{
"from": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
"to": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"value": "1000000000000000000",
"data": "0xd0e30db0"
}],
"expect": []
}'
yarn test
For tests to run successfully, you need to provide an RPC URL in your environment:
RPC_URL_ETHEREUM=https://eth-mainnet.alchemyapi.io/v2/your-api-key
yarn dev
server.ts
: Main server setup with HTTP/HTTPS supportsrc/services/anvilService.ts
: Manages Anvil instances and transaction executionsrc/handlers/simulationHandler.ts
: Handles simulation requestssrc/types.ts
: TypeScript type definitionssrc/utils/serialization.ts
: Utilities for handling BigInt serializationsrc/utils/errorParser.ts
: Utilities for parsing and formatting error messages
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request