LinuxCommandLibrary

ganache-cli

Run local Ethereum blockchain for testing

TLDR

Run Ganache

$ ganache-cli
copy

Run Ganache with a specific number of accounts
$ ganache-cli --accounts=[number_of_accounts]
copy

Run Ganache and lock available accounts by default
$ ganache-cli --secure
copy

Run Ganache server and unlock specific accounts
$ ganache-cli --secure --unlock "[account_private_key1]" --unlock "[account_private_key2]"
copy

Run Ganache with a specific account and balance
$ ganache-cli --account="[account_private_key],[account_balance]"
copy

Run Ganache with accounts with a default balance
$ ganache-cli --defaultBalanceEther=[default_balance]
copy

Run Ganache and log all requests to stdout
$ ganache-cli --verbose
copy

SYNOPSIS

ganache-cli [options]

PARAMETERS

-p, --port <port>
    The port to listen on (default: 8545).

-h, --host <host>
    The host to listen on (default: 0.0.0.0).

-d, --deterministic
    Generates deterministic addresses and mnemonic.

-a, --accounts <num>
    Number of accounts to generate (default: 10).

-e, --defaultBalanceEther <ether>
    Default Ether balance for accounts (default: 100).

-m, --mnemonic <phrase>
    Mnemonic phrase to generate accounts from.

-i, --networkId <id>
    The network ID to use (default: current time or deterministic).

-l, --gasLimit <limit>
    The gas limit for transactions (default: 6721975).

-g, --gasPrice <price>
    The gas price for transactions (default: 20000000000).

-s, --seed <seed>
    The seed to use to generate accounts.

-b, --blockTime <seconds>
    Configures Ganache to create a block every specified seconds (default: 0, immediate mining).

-f, --fork <url/path>
    Fork a remote chain. Allows interaction with existing contracts on a live network.

-k, --hardfork <name>
    The Ethereum hardfork to use (e.g., istanbul, london).

-v, --version
    Output the version number.

DESCRIPTION

ganache-cli is a command-line tool that provides a personal, in-memory Ethereum blockchain for rapid decentralized application (DApp) development and testing. It simulates an Ethereum client, allowing developers to deploy contracts, run tests, and execute transactions without connecting to a public Ethereum network like Mainnet or a testnet. It's designed to offer immediate feedback and a highly configurable environment, making the development workflow significantly faster. Ganache-CLI automatically generates a set of pre-funded accounts, instantly mines blocks as transactions occur, and supports the standard JSON-RPC methods, enabling seamless integration with development tools like Truffle, Hardhat, and Web3.js.

CAVEATS

Not for Production: ganache-cli is an in-memory, local development tool and is not suitable for production deployments or use on public networks.
Ephemeral State: All blockchain state is lost when the process is terminated, unless a snapshot (using the --db option) is explicitly saved.
Limited JSON-RPC Support: While it supports most common eth_ and net_ methods, some advanced or rarely used RPC calls might not be implemented.
Resource Usage: Forking a large mainnet chain can consume significant memory and disk space.

INTEGRATION WITH TRUFFLE

ganache-cli is often used in conjunction with the Truffle framework. Truffle projects automatically connect to Ganache-CLI (or a similar local blockchain) on port 8545 by default for deployment and testing.

DEBUGGING SUPPORT

It provides verbose logging and transaction tracing capabilities, aiding in debugging smart contracts during development.

HISTORY

ganache-cli originated as testrpc, a simple local Ethereum development server. It was later rebranded and integrated into the Truffle Suite by ConsenSys, becoming ganache-cli. This rebranding aimed to align it with the broader Ganache product line, which also includes a desktop application (Ganache UI). Its development has focused on providing a fast, reliable, and feature-rich local blockchain simulation environment, continually adapting to new Ethereum protocol upgrades (hardforks) and developer needs.

SEE ALSO

truffle(1), hardhat(1), web3.js, ethers.js, geth(1)

Copied to clipboard