This file guides AI coding agents working in the flow-emulator repository. Keep it current when commands, ports, or admin endpoints change.
flow-emulator is a Go implementation of a local Flow blockchain node that
implements the Flow Access API (gRPC + REST) for development and testing.
It is bundled by flow-cli as flow emulator and is also consumable as a
Go module (github.com/onflow/flow-emulator). Entry point:
cmd/emulator/main.go, which wires cmd/emulator/start/start.go (a Cobra
start subcommand).
All 12 targets are defined in the root Makefile.
make run— run the emulator server (go run ./cmd/emulator).make test— run all Go tests with-coverprofile=cover.out.make coverage— requiresCOVER=true; producesindex.htmlandcoverage.zipviagocov/gocov-html/gozip.make generate/make generate-mocks— regenerate mocks viamockgenintoemulator/mocks/,storage/mocks/,internal/mocks/.make install-tools— installsmockgen,gocov,gocov-html,gozipinto$GOPATH/bin. Required beforemake generate.make install-linter— installsgolangci-lintv2.4.0.make lint/make fix-lint— rungolangci-lint run -v ./...(config in.golangci.yml: errcheck, govet, ineffassign, misspell, staticcheck).make check-headers— runs./check-headers.shto verify Apache-2.0 license headers on source files.make check-tidy— runsmake generate+go mod tidy+git diff --exit-code; fails if generated files orgo.sumare stale.make ci— full CI bundle:install-tools test check-tidy test coverage check-headers.
Go toolchain: Go 1.25.1 (go.mod).
cmd/emulator/— CLI binary.main.gosupplies a default service-key generator;start/start.godefines the Cobra command,Configstruct, and all CLI flags (env prefixFLOW).emulator/— core in-memory blockchain:blockchain.go,blocks.go,pendingBlock.go,contracts.go,clock.go,scheduled_transactions.go,computation_report.go,pragma.go. 21*_test.gofiles live here.server/— networked surfaces.server.gocomposesserver/access/(gRPC + REST Access API),server/debugger/(Debug Adapter Protocol),server/utils/(admin HTTP + emulator control API),server/liveness/.storage/— pluggable backends:memstore/,sqlite/,redis/,remote/(fork from live node),checkpoint/(load from a flow-go checkpoint),util/.adapters/— bridgesemulator.Emulatorto the flow-goaccess.APIand flow-go-sdk interfaces.convert/— conversions between flow-go, flow-go-sdk, and Cadence types (flow.go,vm.go,emu.go).types/,utils/,internal/— supporting packages;internal/mocks/andemulator/mocks/are generated, do not hand-edit.
Top-level emulator.go re-exports emulator.New(opts ...Option) for
library consumers.
The admin server (default port 8080, configurable via --admin-port /
FLOW_ADMINPORT) is defined in server/utils/admin.go and mounts:
/metrics— Prometheus metrics./live— liveness probe./— gRPC-Web wrapper around the Access API gRPC server./emulator/…— emulator control API, routed inserver/utils/emulator.go:/emulator/newBlock— commit a block (any method).POST /emulator/rollback?height=<n>— roll back to block height.GET /emulator/snapshots— list snapshots.POST /emulator/snapshots?name=<n>— create snapshot.PUT /emulator/snapshots/{name}— jump to snapshot.GET /emulator/logs/{id}— transaction logs by tx ID (hex)./emulator/config— service-key info (any method).GET /emulator/codeCoverage— Cadence coverage report.PUT /emulator/codeCoverage/reset— reset coverage.GET /emulator/computationProfile— pprof profile download.PUT /emulator/computationProfile/reset— reset profile.GET /emulator/computationReport— computation report.GET /emulator/allContracts— zip of all deployed contracts.
Defined in cmd/emulator/start/start.go:
3569— gRPC Access API (--port/-p).8888— REST Access API (--rest-port).8080— Admin HTTP (--admin-port).2345— Debug Adapter Protocol (--debugger-port).
- Env vars come from the Go struct field name, not the flag name.
initConfiginstart.gousessconfig.New(&conf).FromEnvironment("FLOW") .BindFlags(...), which derives env names from theConfigstruct field (uppercased, with theFLOW_prefix) and binds flags separately. Examples: fieldServicePrivateKey(flag--service-priv-key) →FLOW_SERVICEPRIVATEKEY; fieldAdminPort(flag--admin-port) →FLOW_ADMINPORT; fieldRestPort(flag--rest-port) →FLOW_RESTPORT. Do not infer env names by mangling the flag; read the struct field. - Deprecated flags are hidden but still parsed (
start.golines 293–300):--rpc-host→--fork-host;--start-block-height→--fork-height;--transaction-max-gas-limit→--transaction-max-compute-limit;--script-gas-limit→--script-compute-limit. Do not reuse these names. - Fork mode:
--fork-heightrequires--fork-host; otherwise the server exits with an error (start.goline 185). - Chain IDs:
--chain-idaccepts onlyemulator,testnet,mainnet(getSDKChainIDinstart.go). In fork mode, the chain ID is re-detected from the remote node viaserver.DetectRemoteChainID. - Run
make generatebeforemake testwhen editing interfaces that have mocks:emulator.Emulator,storage.Store,internal.AccessAPIClient,internal.ExecutionDataAPIClient. CI enforces this viamake check-tidy. - License headers required:
check-headers.sh(run viamake check-headers) fails the build if the Apache-2.0 header is missing. New.gofiles must include it (copy from any existing file). - Linter config is deliberately minimal (
.golangci.yml): only errcheck, govet, ineffassign, misspell, staticcheck. Do not add new linters without discussion. - Commit style (
CONTRIBUTING.md): imperative mood, first line ≤72 chars.
emulator/mocks/emulator.go,storage/mocks/store.go,internal/mocks/access.go,internal/mocks/executiondata.go— generated bymake generate-mocks.go.sum— managed bygo mod tidy.emulator/templates/systemChunkTransactionTemplate.cdc— template embedded into the runtime; edit with care.