Flow Emulator
The Flow Emulator is a lightweight tool that emulates the behavior of the real Flow network for local development and testing.
Installation
The emulator is included with the Flow CLI. Follow the installation guide to get started.
Quick Start
First, create a flow.json configuration file:
_10flow init --config-only
Then start the Flow Emulator in fork mode (defaults to mainnet when value omitted):
_10flow emulator --fork
You'll see output similar to:
_10INFO[0000] ⚙️ Using service account 0xf8d6e0586b0a20c7 serviceAddress=f8d6e0586b0a20c7 ..._10INFO[0000] 🌱 Starting Flow Emulator_10INFO[0000] 🛠 GRPC server started on 127.0.0.1:3569_10INFO[0000] 📡 HTTP server started on 127.0.0.1:8080
This starts a local Flow network with:
- gRPC server on port
3569 - REST API on
http://localhost:8888 - Admin API on port
8080
Available commands
snapshot: Create/Load/List emulator snapshots. See: Create Emulator Snapshot
Key flags
-
Networking
--host <string>: Host to listen on for gRPC, REST, and Admin (default: all interfaces)--port, -p <int>: gRPC port (default3569)--rest-port <int>: REST API port (default8888)--admin-port <int>: Admin API port (default8080)--debugger-port <int>: Debug Adapter Protocol port (default2345)--grpc-debug: Turn on gRPC server reflection--rest-debug: Turn on REST API debug output
-
State and Persistence
--persist: Turn on persistent storage (default disabled)--dbpath <path>: Directory for on-disk state (default./flowdb)--sqlite-url <url>: Use SQLite storage backend--redis-url <url>: Use Redis storage backend--checkpoint-dir <path>: Load state from checkpoint directory--state-hash <string>: Load state from checkpoint state hash
-
Forking
--fork <string>: Start the emulator in fork mode using a network fromflow.json. If provided without a value, defaults tomainnet.--fork-host <host>: Access node to query when you fork Mainnet or Testnet--fork-height <uint>: Starting block height when you fork
-
Cadence and VM
--block-time, -b <duration>: Time between sealed blocks (for exxample,1s,300ms)--coverage-reporting: Turn on code coverage reporting--computation-reporting: Turn on computation reporting--legacy-upgrade: Turn on legacy contract upgrade behavior--scheduled-transactions: Turn on scheduled transactions (default true)--script-compute-limit <int>: Compute unit limit for scripts (default100000)--transaction-max-compute-limit <int>: Max transaction compute unit limit (default9999)--transaction-expiry <int>: Transaction expiry in blocks (default10)--skip-tx-validation: Skip tx signature and sequence number checks--simple-addresses: Use sequential addresses starting with0x01--storage-limit: Enforce account storage limit (default true)--storage-per-flow <decimal>: MB of storage per 1 FLOW token--token-supply <decimal>: Initial FLOW token supply (default1000000000.0)--transaction-fees: Turn on transaction fees--setup-evm: Deploy EVM contracts (default true)--setup-vm-bridge: Deploy VM Bridge contracts (default true)
-
Service Account and Identity
--chain-id <emulator|testnet|mainnet>: Address generation chain (defaultemulator)--service-priv-key <hex>/--service-pub-key <hex>: Service account keys--service-sig-algo <ECDSA_P256|ECDSA_secp256k1>: Service key signature algo (defaultECDSA_P256)--service-hash-algo <SHA3_256|SHA2_256>: Service key hash algo (defaultSHA3_256)--min-account-balance <decimal>: Minimum account balance or account creation cost--num-accounts <int>: Number of accounts to precreate and fund at startup (default0)--contracts: Deploy common contracts on start--contract-removal: Allow contract removal for development (default true)--init: Initialize a new account profile
-
Logging and Output
--verbose, -v: Verbose logging--log-format <text|JSON>: Logging output format (defaulttext)
-
Snapshots
--snapshot: Enable snapshots in the emulator
Precreated Accounts
The Flow Emulator supports precreating and funding multiple accounts automatically when the emulator starts up. This feature streamlines development workflows by eliminating the need to manually create test accounts for each emulator session.
Usage
Use the --num-accounts flag to specify the number of accounts to precreate:
_10flow emulator --num-accounts 5
Or via environment variable:
_10FLOW_NUMACCOUNTS=5 flow emulator
Account Details
Funding: Each precreated account is automatically funded with 1000.0 FLOW tokens. The funding amount is currently fixed and not configurable.
Keys: All precreated accounts use the same public key as the service account. This simplifies development by allowing you to use the same private key across all accounts. The service account private key (displayed at startup) can be used to sign transactions for any precreated account.
Account Addresses: Accounts are created sequentially at emulator startup. Account addresses and the shared private key are displayed in the console when the emulator starts.
Example Output
When starting the emulator with --num-accounts 3:
_11Available Accounts_11==================_11(0) 0x01cf0e2f2f715450 (1000.0 FLOW)_11(1) 0x179b6b1cb6755e31 (1000.0 FLOW)_11(2) 0xf3fcd2c1a78f5eee (1000.0 FLOW)_11_11Private Keys_11==================_11(0) 0x<SERVICE_PRIVATE_KEY>_11(1) 0x<SERVICE_PRIVATE_KEY>_11(2) 0x<SERVICE_PRIVATE_KEY>
Examples
_38# Verbose logs_38flow emulator --verbose_38_38# Custom ports_38flow emulator --port 9000 --rest-port 9001 --admin-port 9002_38_38# Custom block time (1 second between blocks)_38flow emulator --block-time 1s_38_38# Persist state on disk_38flow emulator --persist --dbpath ./flowdb_38_38# Fork from Mainnet using flow.json_38flow emulator --fork_38_38# Fork from Testnet using flow.json and pin to a height_38flow emulator --fork testnet --fork-height 12345678_38_38# Fork from Testnet at a specific height_38flow emulator --fork-host access.devnet.nodes.onflow.org:9000 --fork-height 12345678_38_38# Disable fees and use simple addresses for local testing_38flow emulator --transaction-fees=false --simple-addresses_38_38# Enable code coverage reporting_38flow emulator --coverage-reporting_38_38# Change the gRPC and REST API ports_38flow emulator --port 9000 --rest-port 9001_38_38# Precreate 5 accounts for testing_38flow emulator --num-accounts 5_38_38# Precreate accounts with persistence enabled_38flow emulator --num-accounts 3 --persist_38_38# For a complete list of available flags, run:_38flow emulator --help
For the complete and current list of flags, run:
_10flow emulator --help
Debugging and Testing
- Code Coverage: Add
--coverage-reportingflag and visithttp://localhost:8080/emulator/codeCoverage - Debugging: Use
#debugger()pragma in Cadence code for breakpoints - Fork mode note: When you use
flow emulator --fork, only Flow chain state is available. External oracles/APIs and cross-chain reads are not live; mock these or run local stub services for E2E.
Snapshots
The Flow CLI provides a command to create emulator snapshots, which are points in blockchain history you can later jump to and reset the state to that moment. This can be useful to test where you establish a beginning state, run tests and after revert back to the initial state.
Quick snapshot workflow
_10# 1) Start the emulator with snapshots enabled (in a separate terminal)_10flow emulator --snapshot_10_10# 2) Create a snapshot at the current state_10flow emulator snapshot create baseline_10_10# 3) Make changes, run tests, etc._10_10# 4) Reset the emulator back to the snapshot_10flow emulator snapshot load baseline
Create a new snapshot
Create a new emulator snapshot at the current block with a name of myInitialState.
_10flow emulator snapshot create myInitialState
Load a current snapshot
To jump to a previously created snapshot we use the load command in combination with the name.
_10flow emulator snapshot load myInitialState
List all snapshots
To list all the snapshots we previously created and can load to run:
_10flow emulator list
Additional resources
To learn more about how to use the Emulator, have a look at the public GitHub repository.