testrpc is now
ganache-cli. Use it just as you would
Welcome to Ganache CLI
Ganache CLI, part of the Truffle suite of Ethereum development tools, is the command line version of Ganache, your personal blockchain for Ethereum development.
Ganache CLI uses ethereumjs to simulate full client behavior and make developing Ethereum applications faster, easier, and safer. It also includes all popular RPC functions and features (like events) and can be run deterministically to make development a breeze.
Looking for TestRPC?
If you came here expecting to find the TestRPC, you're in the right place! Truffle has taken the TestRPC under its wing and made it part of the Truffle suite of tools. From now on you can expect better support along with tons of new features that help make Ethereum development safer, easier, and more enjoyable. Use
ganache-cli just as you would
npm. Make sure you have Node.js (>= v6.11.5) installed.
npm install -g ganache-cli
or, if you are using Yarn:
yarn global add ganache-cli
ganache-core internally, which is distributed with optional native dependencies for increased performance. If these native dependencies fail to install on your system
ganache-cli will automatically fallback to
Having problems? Be sure to check out the FAQ and if you're still having issues and you're sure its a problem with
ganache-cli please open an issue.
Using Ganache CLI
$ ganache-cli <options>
--accounts: Specify the number of accounts to generate at startup.
--defaultBalanceEther: Amount of ether to assign each test account. Default is 100.
--blockTime: Specify blockTime in seconds for automatic mining. If you don't specify this flag, ganache will instantly mine a new block for every transaction. Using the --blockTime flag is discouraged unless you have tests which require a specific mining interval.
--deterministic: Generate deterministic addresses based on a pre-defined mnemonic.
--secure: Lock available accounts by default (good for third party transaction signing)
--mnemonic: Use a bip39 mnemonic phrase for generating a PRNG seed, which is in turn used for hierarchical deterministic (HD) account generation.
--port: Port number to listen on. Defaults to 8545.
--hostname: Hostname to listen on. Defaults to 127.0.0.1 (defaults to 0.0.0.0 for Docker instances of ganache-cli).
--seed: Use arbitrary data to generate the HD wallet mnemonic to be used.
--gasPrice: The price of gas in wei (defaults to 20000000000)
--gasLimit: The block gas limit (defaults to 0x6691b7)
--fork: Fork from another currently running Ethereum client at a given block. Input should be the HTTP location and port of the other client, e.g.
http://localhost:8545. You can optionally specify the block to fork from using an
--networkId: Specify the network id ganache-cli will use to identify itself (defaults to the current time or the network id of the forked blockchain if configured)
--db: Specify a path to a directory to save the chain database. If a database already exists, ganache-cli will initialize that chain instead of creating a new one.
--debug: Output VM opcodes for debugging
--mem: Output ganache-cli memory usage statistics. This replaces normal output.
--quiet: Run ganache-cli without any logs.
--verbose: Log all requests and responses to stdout
--help: Display help information
--version: Display the version of ganache-cli
--noVMErrorsOnRPCResponse: Do not transmit transaction failures as RPC errors. Enable this flag for error reporting behaviour which is compatible with other clients such as geth and Parity.
--allowUnlimitedContractSize: Allows unlimited contract sizes while debugging. By enabling this flag, the check within the EVM for contract size limit of 24KB (see EIP-170) is bypassed. Enabling this flag will cause ganache-cli to behave differently than production environments.
--keepAliveTimeout: Sets the HTTP server's
keepAliveTimeoutin milliseconds. See the NodeJS HTTP docs for details.
--time: Date (ISO 8601) that the first block should start. Use this feature, along with the evm_increaseTime method to test time-dependent code.
--account=...(no 's') any number of times passing arbitrary private keys and their associated balances to generate initial addresses:
$ ganache-cli --account="<privatekey>,balance" [--account="<privatekey>,balance"]
Note that private keys are 64 characters long, and must be input as a 0x-prefixed hex string. Balance can either be input as an integer or 0x-prefixed hex value specifying the amount of wei in that account.
An HD wallet will not be created for you when using
--unlock ...any number of times passing either an address or an account index to unlock specific accounts. When used in conjunction with
--unlockwill override the locked state of specified accounts.
$ ganache-cli --secure --unlock "0x1234..." --unlock "0xabcd..."
You can also specify a number, unlocking accounts by their index:
$ ganache-cli --secure -u 0 -u 1
This feature can also be used to impersonate accounts and unlock addresses you wouldn't otherwise have access to. When used with the
--forkfeature, you can use ganache-cli to make transactions as any address on the blockchain, which is very useful for testing and dynamic analysis.
As a Web3 provider:
const ganache = ;web3;
As an ethers.js provider:
const ganache = ;const provider = ganache;
As a general HTTP and WebSocket server:
const ganache = ;const server = ganache;server;
.server() take a single object which allows you to specify behavior of
ganache-cli. This parameter is optional. Available options are:
Object's. Each object should have a balance key with a hexadecimal value. The key
secretKeycan also be specified, which represents the account's private key. If no
secretKey, the address is auto-generated with the given balance. If specified, the key is used to determine the account's address.
boolean- Output VM opcodes for debugging
number- Specify blockTime in seconds for automatic mining. If you don't specify this flag, ganache will instantly mine a new block for every transaction. Using the
blockTimeoption is discouraged unless you have tests which require a specific mining interval.
Object- Object, like
console, that implements a
"mnemonic": Use a specific HD wallet mnemonic to generate initial addresses.
"port": Port number to listen on when running as a server.
"seed": Use arbitrary data to generate the HD wallet mnemonic to be used.
number- The default account balance, specified in ether.
number- Number of accounts to generate at startup.
object- When a
string, same as
--forkoption above. Can also be a Web3 Provider object, optionally used in conjunction with the
number- Block number the provider should fork from, when the
forkoption is specified. If the
forkoption is specified as a string including the
@sign and a block number, the block number in the
forkparameter takes precedence.
"network_id": Specify the network id ganache-core will use to identify itself (defaults to the current time or the network id of the forked blockchain if configured)
Date- Date that the first block should start. Use this feature, along with the
evm_increaseTimemethod to test time-dependent code.
boolean- whether or not accounts are locked by default.
Array- array of addresses or address indexes specifying which accounts should be unlocked.
String- Specify a path to a directory to save the chain database. If a database already exists,
ganache-cliwill initialize that chain instead of creating a new one.
Object- Specify an alternative database instance, for instance MemDOWN.
"ws": Enable a websocket server. This is
String- Specifies a file to save accounts and private keys to, for testing.
boolean- Whether or not to transmit transaction failures as RPC errors. Set to
falsefor error reporting behaviour which is compatible with other clients such as geth and Parity. This is
trueby default to replicate the error reporting behavior of previous versions of ganache.
"hdPath": The hierarchical deterministic path to use when generating accounts. Default: "m/44'/60'/0'/0/"
boolean- Allows unlimited contract sizes while debugging. By setting this to
true, the check within the EVM for contract size limit of 24KB (see EIP-170) is bypassed. Setting this to
ganache-clito behave differently than production environments. (default:
false; ONLY set to
"gasPrice": Sets the default gas price for transactions if not otherwise specified. Must be specified as a hex string in wei. Defaults to
"0x77359400", or 2 gwei.
"gasLimit": Sets the block gas limit. Must be specified as a hex string. Defaults to
"keepAliveTimeout": If using
.server()- Sets the HTTP server's
keepAliveTimeoutin milliseconds. See the NodeJS HTTP docs for details.
The RPC methods currently implemented are:
eth_getCode(only supports block number “latest”)
eth_newFilter(includes log/event filters)
eth_subscribe(only for websocket connections. "syncing" subscriptions are not yet supported)
eth_unsubscribe(only for websocket connections. "syncing" subscriptions are not yet supported)
There’s also special non-standard methods that aren’t included within the original RPC specification:
evm_snapshot: Snapshot the state of the blockchain at the current block. Takes no parameters. Returns the integer id of the snapshot created.
evm_revert: Revert the state of the blockchain to a previous snapshot. Takes a single parameter, which is the snapshot id to revert to. If no snapshot id is passed it will revert to the latest snapshot. Returns
evm_increaseTime: Jump forward in time. Takes one parameter, which is the amount of time to increase in seconds. Returns the total time adjustment, in seconds.
evm_mine: Force a block to be mined. Takes one optional parameter, which is the timestamp a block should setup as the mining time. Mines a block independent of whether or not mining is started or stopped.
The Simplest way to get started with the Docker image:
docker run -d -p 8545:8545 trufflesuite/ganache-cli:latest
To pass options to ganache-cli through Docker simply add the arguments to the run command:
docker run -d -p 8545:8545 trufflesuite/ganache-cli:latest -a 10 --debug^^^^^^^^^^^^^
The Docker container adds an environment variable
DOCKER=true; when this variable is set to
true (case insensitive),
ganache-cli use a default hostname IP of
0.0.0.0 instead of the normal default
127.0.0.1. You can still specify a custom hostname however:
docker run -d -p 8545:8545 trufflesuite/ganache-cli:latest -h XXX.XXX.XXX.XXX^^^^^^^^^^^^^^^^^^
To build and run the Docker container from source:
git clone && cd ganache-cli
docker build -t trufflesuite/ganache-cli .docker run -p 8545:8545 trufflesuite/ganache-cli
npm run docker
Contributing to Ganache CLI
You can contribute to the core code at ganache-core.
To contribue to ganache-cli, run:
git clone && cd ganache-clinpm install
You'll need Python 2.7 installed, and on Windows, you'll likely need to install windows-build-tools from an Administrator PowerShell Prompt via
npm install --global windows-build-tools.