Moxiesuite Ganache Core is moving to https://github.com/moxiesuite/moonrock-core This is the core code that powers the Ganache application and the the Ganache command line tool.
ganache-core
is written in JavaScript and distributed as a Node.js package via npm
. Make sure you have Node.js (>= v8.9.0) installed, and your environment is capable of installing and compiling npm
modules.
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 build-essential
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.
Using npm:
npm install ganache-core
or, if you are using Yarn:
yarn add ganache-core
As a Web3 provider:
const ganache = require("ganache-core");
web3.setProvider(ganache.provider());
As an vapors.js provider:
const ganache = require("ganache-core");
const provider = new vapors.providers.Web3Provider(ganache.provider());
As a general HTTP and WebSocket server:
const ganache = require("ganache-core");
const server = ganache.server();
server.listen(port, function(err, blockchain) {...});
Both .provider()
and .server()
take a single object which allows you to specify behavior of the Ganache instance. This parameter is optional. Available options are:
"accounts"
:Array
ofObject
's. Each object should have a balance key with a hexadecimal value. The keysecretKey
can also be specified, which represents the account's private key. If nosecretKey
, the address is auto-generated with the given balance. If specified, the key is used to determine the account's address."debug"
:boolean
- Output VM opcodes for debugging"blockTime"
: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 theblockTime
option is discouraged unless you have tests which require a specific mining interval."logger"
:Object
- Object, likeconsole
, that implements alog()
function."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."default_balance_vapor"
:number
- The default account balance, specified in vapor."total_accounts"
:number
- Number of accounts to generate at startup."fork"
:string
orobject
- When astring
, same as--fork
option above. Can also be a Web3 Provider object, optionally used in conjunction with thefork_block_number
option below."fork_block_number"
:string
ornumber
- Block number the provider should fork from, when thefork
option is specified. If thefork
option is specified as a string including the@
sign and a block number, the block number in thefork
parameter 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)"time"
:Date
- Date that the first block should start. Use this feature, along with thevvm_increaseTime
method to test time-dependent code."locked"
:boolean
- whether or not accounts are locked by default."unlocked_accounts"
:Array
- array of addresses or address indexes specifying which accounts should be unlocked."db_path"
:String
- Specify a path to a directory to save the chain database. If a database already exists,ganache-core
will initialize that chain instead of creating a new one."db"
:Object
- Specify an alternative database instance, for instance MemDOWN."ws"
: Enable a websocket server. This istrue
by default."account_keys_path"
:String
- Specifies a file to save accounts and private keys to, for testing."vmErrorsOnRPCResponse"
:boolean
- Whether or not to transmit transaction failures as RPC errors. Set tofalse
for error reporting behaviour which is compatible with other clients such as gvap and Parity. This istrue
by 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/""allowUnlimitedContractSize"
:boolean
- Allows unlimited contract sizes while debugging. By setting this totrue
, the check within the VVM for contract size limit of 24KB (see EIP-170) is bypassed. Setting this totrue
will causeganache-core
to behave differently than production environments. (default:false
; ONLY set totrue
during debugging)."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"0x6691b7"
."keepAliveTimeout"
: If using.server()
- Sets the HTTP server'skeepAliveTimeout
in milliseconds. See the NodeJS HTTP docs for details.5000
by default.
The RPC methods currently implemented are:
bzz_hive
(stub)bzz_info
(stub)debug_traceTransaction
vap_accounts
vap_blockNumber
vap_call
vap_coinbase
vap_estimateGas
vap_gasPrice
vap_getBalance
vap_getBlockByNumber
vap_getBlockByHash
vap_getBlockTransactionCountByHash
vap_getBlockTransactionCountByNumber
vap_getCode
(only supports block number “latest”)vap_getCompilers
vap_getFilterChanges
vap_getFilterLogs
vap_getLogs
vap_getStorageAt
vap_getTransactionByHash
vap_getTransactionByBlockHashAndIndex
vap_getTransactionByBlockNumberAndIndex
vap_getTransactionCount
vap_getTransactionReceipt
vap_hashrate
vap_mining
vap_newBlockFilter
vap_newFilter
(includes log/event filters)vap_protocolVersion
vap_sendTransaction
vap_sendRawTransaction
vap_sign
vap_subscribe
(only for websocket connections. "syncing" subscriptions are not yet supported)vap_unsubscribe
(only for websocket connections. "syncing" subscriptions are not yet supported)vap_syncing
vap_uninstallFilter
net_listening
net_peerCount
net_version
miner_start
miner_stop
personal_listAccounts
personal_lockAccount
personal_newAccount
personal_importRawKey
personal_unlockAccount
personal_sendTransaction
shh_version
rpc_modules
web3_clientVersion
web3_sha3
There’s also special non-standard methods that aren’t included within the original RPC specification:
vvm_snapshot
: Snapshot the state of the blockchain at the current block. Takes no parameters. Returns the integer id of the snapshot created.vvm_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. Returnstrue
.vvm_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.vvm_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.
vap_compileSolidity
: If you'd like Solidity compilation in Javascript, please see the solc-js project.
Run tests via:
$ npm test