GithubHelp home page GithubHelp logo

isabella232 / flow-emulator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from onflow/flow-emulator

0.0 0.0 0.0 3.25 MB

The Flow Emulator is a lightweight tool that emulates the behaviour of the real Flow network

Home Page: https://onflow.org

License: Apache License 2.0

Makefile 1.26% Go 98.35% Dockerfile 0.32% Shell 0.06%

flow-emulator's Introduction


Logo

The Flow Emulator is a lightweight tool that emulates the behaviour of the real Flow network.
Read the docs»

Report Bug · Contribute



The Emulator

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.

The Flowser Emulator Explorer

There is also an block explorer GUI for the emulator, that will help you speed up development when using the emulator.

Running

Configuration

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.

Flag Env Default Description
--port, -p FLOW_PORT 3569 gRPC port to listen on
--rest-port FLOW_RESTPORT 8888 REST API port to listen on
--admin-port FLOW_ADMINPORT 8080 Admin API port to listen on
--dev-wallet FLOW_DEVWALLET false Enable local Dev Wallet server
--dev-wallet-port FLOW_DEVWALLETPORT 8701 Port to run Dev Wallet server on
--verbose, -v FLOW_VERBOSE false Enable verbose logging (useful for debugging)
--log-format FLOW_LOGFORMAT text Output log format (valid values text, JSON)
--block-time, -b FLOW_BLOCKTIME 0 Time between sealed blocks. Valid units are ns, us (or µs), ms, s, m, h
--contracts FLOW_WITHCONTRACTS false Start with contracts like FUSD, NFT and an NFT Marketplace, when the emulator starts
--service-priv-key FLOW_SERVICEPRIVATEKEY random Private key used for the service account
--service-pub-key FLOW_SERVICEPUBLICKEY random Public key used for the service account
--service-sig-algo FLOW_SERVICEKEYSIGALGO ECDSA_P256 Service account key signature algorithm
--service-hash-algo FLOW_SERVICEKEYHASHALGO SHA3_256 Service account key hash algorithm
--init FLOW_INIT false Generate and set a new service account
--rest-debug FLOW_RESTDEBUG false Enable REST API debugging output
--grpc-debug FLOW_GRPCDEBUG false Enable gRPC server reflection for debugging with grpc_cli
--persist FLOW_PERSIST false Enable persistence of the state between restarts
--dbpath FLOW_DBPATH ./flowdb Specify path for the database file persisting the state
--simple-addresses FLOW_SIMPLEADDRESSES false Use sequential addresses starting with 0x1
--token-supply FLOW_TOKENSUPPLY 1000000000.0 Initial FLOW token supply
--transaction-expiry FLOW_TRANSACTIONEXPIRY 10 Transaction expiry, measured in blocks
--storage-limit FLOW_STORAGELIMITENABLED true Enable account storage limit
--storage-per-flow FLOW_STORAGEMBPERFLOW Specify size of the storage in MB for each FLOW in account balance. Default value from the flow-go
--min-account-balance FLOW_MINIMUMACCOUNTBALANCE Specify minimum balance the account must have. Default value from the flow-go
--transaction-fees FLOW_TRANSACTIONFEESENABLED false Enable transaction fees
--transaction-max-gas-limit FLOW_TRANSACTIONMAXGASLIMIT 9999 Maximum gas limit for transactions
--script-gas-limit FLOW_SCRIPTGASLIMIT 100000 Specify gas limit for script execution

Running the emulator with the Flow CLI

The emulator is bundled with the Flow CLI, a command-line interface for working with Flow.

Installation

Follow these steps to install the Flow CLI.

Starting the server

Starting the emulator by using Flow CLI also leverages CLI configuration file flow.json. 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

Using the emulator in a project

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.

Managing emulator state

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 managment functionality you need to run the emulator with persistent state:

flow emulator --persist

Create a new snapshot by doing an HTTP request:

GET http://localhost:8080/emulator/snapshot/{name}

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 name parameter.

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.

Launching dev-wallet with the emulator

You can start the dev-wallet with the --dev-wallet flag. Default dev-wallet port is 8701.

After starting dev-wallet, you can set your fcl config to use it like below:

import * as fcl from "@onflow/fcl"

fcl.config()
  // Point App at Emulator
  .put("accessNode.api", "http://localhost:8080") 
  // Point FCL at dev-wallet (default port)
  .put("discovery.wallet", "http://localhost:8701/fcl/authn") 

You can read more about setting up dev-wallet at FCL Dev Wallet Project

Running the emulator with Docker

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

Development

Read contributing document.

flow-emulator's People

Contributors

10thfloor avatar arturenault avatar avcdsld avatar benjaminkvm avatar bluesign avatar intelliot avatar janezpodhostnik avatar jordanschalm avatar joshuahannan avatar jrkhan avatar kay-zee avatar keisukeyamashita avatar m4ksio avatar magusfabius avatar mrbrianhobo avatar philipstanislaus avatar psiemens avatar ramtinms avatar sideninja avatar turbolent avatar vishalchangrani avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.