The emulator exposes a gRPC server that implements the Flow Access API, which is designed to have near feature parity with the real network API.
There is also a block explorer GUI for the emulator, that will help you speed up development when using the emulator.
The Flow Emulator can be run in different modes and settings, all of them are described in the table bellow.
Please note that if you will run the emulator using the Flow CLI you must use flags to pass configuration values and if you plan to run the emulator with Docker you must use the environment variables (Env) to pass configuration values.
|gRPC port to listen on|
|REST API port to listen on|
|Admin API port to listen on|
|Enable verbose logging (useful for debugging)|
|Output log format (valid values |
|Time between sealed blocks. Valid units are |
|Start with contracts like FUSD, NFT and an NFT Marketplace, when the emulator starts|
|random||Private key used for the service account|
|random||Public key used for the service account|
|Service account key signature algorithm|
|Service account key hash algorithm|
|Generate and set a new service account|
|Enable REST API debugging output|
|Enable gRPC server reflection for debugging with grpc_cli|
|false||Enable persistence of the state between restarts|
|Specify path for the database file persisting the state|
|Use sequential addresses starting with |
|Initial FLOW token supply|
|Transaction expiry, measured in blocks|
|Enable account storage limit|
|Specify size of the storage in MB for each FLOW in account balance. Default value from the flow-go|
|Specify minimum balance the account must have. Default value from the flow-go|
|Enable variable transaction fees and execution effort metering |
as decribed in Variable Transaction Fees: Execution Effort FLIP
|Maximum gas limit for transactions|
|Specify gas limit for script execution|
The emulator is bundled with the Flow CLI, a command-line interface for working with Flow.
Follow these steps to install the Flow CLI.
Starting the emulator by using Flow CLI also leverages CLI configuration file
You can use the
flow.json to specify the service account which will be reused between restarts.
Read more about CLI configuration here.
You can start the emulator with the Flow CLI:
flow emulator --init
You can start the emulator in your project context by running the above command
in the same directory as
flow.json. This will configure the emulator with your
project's service account, meaning you can use it to sign and submit transactions.
Read more about the project and configuration here.
You can use the emulator as a module in your Go project. To install emulator, use go get:
go get github.com/onflow/flow-emulator
After installing the emulator module you can initialize it in the code:
var opts emulator.Option privKey, err := crypto.DecodePrivateKeyHex(crypto.ECDSA_P256, "") opts = append(opts, emulator.WithServicePublicKey( privKey.PublicKey(), crypto.ECDSA_P256, crypto.SHA3_256, )) blockchain, err := emulator.NewBlockchain(opts...)
You can then access all methods of the blockchain like so:
account, err := blockchain.GetAccount(address)
It's possible to manage emulator state by using the admin API. You can at any point create a new named snapshot of the state and then at any later point revert emulator state to that reference.
In order to use the state management functionality you need to run the emulator with persistent state:
flow emulator --persist
Create a new snapshot by doing an HTTP request:
Please note the example above uses the default admin API port
At any later point you can reload to that snapshot by executing the same HTTP request as before.
You need to use the same value for
The snapshot functionality is a great tool for testing where you can first initialize a base snapshot with seed values, execute the test and then revert to that initialized state.
Docker builds for the emulator are automatically built and pushed to
gcr.io/flow-container-registry/emulator, tagged by commit and semantic version. You can also build the image locally.
docker run gcr.io/flow-container-registry/emulator
The full list of environment variables can be found here.
You can pass any environment variable by using
-e docker flag and pass the valid value.
Custom Configuration Example:
docker run -e FLOW_PORT=9001 -e FLOW_VERBOSE=true -e FLOW_SERVICEPUBLICKEY=<hex-encoded key> gcr.io/flow-container-registry/emulator
To generate a service key, use the
keys generate command in the Flow CLI.
flow keys generate
Read contributing document.