@zigen/ganache-core2.1.0 • Public • Published
This is the core code that powers the Ganache application and the the Ganache command line tool.
npm. Make sure you have Node.js (>= v8.9.0) installed, and your environment is capable of installing and compiling
macOS Make sure you have the XCode Command Line Tools installed. These are needed in general to be able to compile most C based languages on your machine, as well as many npm modules.
Windows See our Windows install instructions.
Ubuntu/Linux Follow the basic instructions for installing Node.js and make sure that you have
npm installed, as well as the
apt package (it supplies
make which you will need to compile most things). Use the official Node.js packages, do not use the package supplied by your distribution.
npm install ganache-core
As a Web3 provider:
var Ganache = ;web3;
As a general http server:
var Ganache = ;var server = Ganache;server;
.server() take a single object which allows you to specify behavior of the Ganache instance. 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
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.
integer- Same as
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, that chain will be initialized instead of creating a new one.
Object- Specify an alternative database instance, for instance MemDOWN.
"ws": Enable a websocket server. This is
"vmErrorsOnRPCResponse": Whether to report runtime errors from EVM code as RPC errors. 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/"
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 no parameters. Mines a block independent of whether or not mining is started or stopped.
Run tests via:
$ npm test