Skip to main content
Local WASM replay allows you to test smart contracts on your development machine without deploying to any network. This accelerates the development cycle and enables rapid iteration during contract development.

Overview

Local WASM replay:
  • Loads WASM files directly from your filesystem
  • Executes contracts in a local Soroban environment
  • Uses mock state (no real ledger data)
  • Captures diagnostic events and logs
  • Supports basic argument types
  • Enforces Soroban VM compatibility
Local replay uses mock state, not mainnet or testnet data. This mode is intended for rapid contract development and testing, not production debugging.

Quick start

Run a local WASM file:
With function arguments:
With verbose output:

Building contracts for replay

Arguments

Local WASM replay supports basic Soroban argument types:

Integer arguments

Parsed as u32 or i32 depending on contract signature.

Symbol/String arguments

Parsed as Soroban Symbol type.

Multiple arguments

Pass multiple --args flags in order:
Arguments are passed to the contract function in the order specified.
Complex types (Maps, Vectors, Addresses) are not yet supported. Use integers and symbols for testing.

Example output

Running local WASM replay:
Output:

Mock state warning

When using --wasm, you’ll always see:
This indicates:
  • No real ledger data is available
  • Contract storage is empty
  • External contract calls may fail
  • Token balances are zero
  • Authorization checks use mock identities
Use cases for mock state:
  • Testing pure functions (no storage access)
  • Validating computation logic
  • Checking WASM compatibility
  • Rapid iteration during development
  • Unit testing without deployment
When NOT to use mock state:
  • Debugging production failures (use real transaction hash)
  • Testing storage interactions (use testnet)
  • Validating cross-contract calls (use network)
  • Analyzing real user transactions

Soroban compatibility

Erst enforces Soroban VM restrictions:

Floating-point detection

The simulator rejects WASM binaries containing floating-point instructions:
Solution: Remove all f32 and f64 usage from your contract:

Determinism enforcement

Erst ensures your contract produces deterministic results:
  • No floating-point operations
  • No system calls (time, random)
  • Consistent execution across runs
  • Predictable resource consumption
This keeps local behavior aligned with on-chain restrictions.

Diagnostic logging

Standard output

By default, Erst shows:
  • Execution status (success/failure)
  • Function result
  • Summary of logs and events
  • Performance metrics (CPU, memory)

Verbose mode

Enable detailed diagnostics:
Additional output:
  • Detailed host budget breakdown
  • Full event data structures
  • WASM module information
  • Instruction-level traces
  • Memory allocation details

Performance profiling

Generate flamegraphs for local execution:
Creates contract.flamegraph.html showing:
  • Function call hierarchy
  • CPU time per function
  • Memory allocation patterns
  • Hot paths in execution
See Using flamegraphs for details.

Common workflows

Rapid iteration loop

No network deployment required - iterate in seconds.

Pre-deployment validation

Catch issues locally before wasting testnet transactions.

Regression testing

Create a test suite:
Run before commits:

Compare local vs network

Limitations

Mock state restrictions

Local WASM replay cannot test:
  • Contract storage reads/writes (storage is empty)
  • Cross-contract invocations (no other contracts exist)
  • Token transfers (no token contracts)
  • Authorization (uses mock signers)
  • Time-dependent logic (fixed timestamp)
  • Network-specific state
Solution: Use testnet for integration testing:

Argument type limitations

Currently supported:
  • Integers (u32, i32, u64, i64)
  • Symbols (short strings)
Not yet supported:
  • Addresses
  • Maps
  • Vectors
  • Custom types
  • Bytes
Workaround: Test complex types on testnet.

No state persistence

Each replay starts with empty state:
Solution: Use testnet for stateful testing.

Advanced usage

Custom function invocation

By default, Erst invokes the first exported function. To call a specific function:
Direct function selection is not yet implemented. Deploy to testnet and use soroban contract invoke to call specific functions.

Batch testing

Test multiple WASM files:

Integration with CI/CD

Add to GitHub Actions:

Troubleshooting

WASM file not found

Solutions:
  • Check file path: ls -la ./contract.wasm
  • Use absolute path: erst debug --wasm /full/path/to/contract.wasm
  • Verify file exists and is readable

Invalid WASM format

Solutions:
  • Rebuild contract: cargo build --target wasm32-unknown-unknown --release
  • Verify WASM magic bytes: hexdump -C contract.wasm | head -n 1
  • Check file isn’t corrupted: file contract.wasm

Execution failed

Solutions:
  • Check contract expects the arguments you provided
  • Verify contract doesn’t require storage (not available locally)
  • Test with --verbose for detailed error info
  • Deploy to testnet for full environment

Floating-point error

Solutions:
  • Remove all f32/f64 types from contract
  • Use fixed-point integer math instead
  • Check dependencies don’t use floating-point
  • Rebuild with --release (some debug code uses floats)

Implementation details

Architecture

CLI Layer (Go):
  • internal/cmd/debug.go - Handles --wasm flag
  • internal/simulator/schema.go - Extended with wasm_path, mock_args
Simulator Layer (Rust):
  • simulator/src/main.rs - Contains run_local_wasm_replay()
  • Loads WASM from disk
  • Initializes Soroban Host
  • Deploys contract to host
  • Parses arguments
  • Invokes contract function
  • Captures diagnostic events

Source files

Local WASM replay implementation:
  • internal/cmd/debug.go - CLI integration
  • simulator/src/main.rs - Core replay logic
  • simulator/src/wasm.rs - WASM loading and validation

Next steps

Debugging failed transactions

Debug real transactions with full network state

Using flamegraphs

Profile local WASM execution performance

Working with sessions

Save local test results for later review