Giter VIP home page Giter VIP logo

ganache-core's Introduction

Ganache Core

This is the core code that powers the Ganache application and the the Ganache command line tool.

INSTALL

ganace-core is written in Javascript and distributed as a Node package via npm. Make sure you have Node.js (>= v6.9.1) 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.

npm install ganache-core

USAGE

As a Web3 provider:

var Ganache = require("ganache-core");
web3.setProvider(Ganache.provider());

As a general http server:

var Ganache = require("ganache-core");
var 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 of Object's. Each object should have a balance key with a hexadecimal value. The key secretKey can 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.
  • "debug": boolean - Output VM opcodes for debugging
  • "logger": Object - Object, like console, that implements a log() 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.
  • "total_accounts": number - Number of accounts to generate at startup.
  • "fork": string or object - When a string, same as --fork option above. Can also be a Web3 Provider object, optionally used in conjunction with the fork_block_number option below.
  • "fork_block_number": string or number - Block number the provider should fork from, when the fork option is specified. If the fork option is specified as a string including the @ sign and a block number, the block number in the fork parameter takes precedence.
  • "network_id": integer - Same as --networkId option above.
  • "time": Date - Date that the first block should start. Use this feature, along with the evm_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, that chain will be initialized instead of creating a new one.

IMPLEMENTED METHODS

The RPC methods currently implemented are:

  • bzz_hive (stub)
  • bzz_info (stub)
  • debug_traceTransaction
  • eth_accounts
  • eth_blockNumber
  • eth_call
  • eth_coinbase
  • eth_estimateGas
  • eth_gasPrice
  • eth_getBalance
  • eth_getBlockByNumber
  • eth_getBlockByHash
  • eth_getBlockTransactionCountByHash
  • eth_getBlockTransactionCountByNumber
  • eth_getCode (only supports block number “latest”)
  • eth_getCompilers
  • eth_getFilterChanges
  • eth_getFilterLogs
  • eth_getLogs
  • eth_getStorageAt
  • eth_getTransactionByHash
  • eth_getTransactionByBlockHashAndIndex
  • eth_getTransactionByBlockNumberAndIndex
  • eth_getTransactionCount
  • eth_getTransactionReceipt
  • eth_hashrate
  • eth_mining
  • eth_newBlockFilter
  • eth_newFilter (includes log/event filters)
  • eth_protocolVersion
  • eth_sendTransaction
  • eth_sendRawTransaction
  • eth_sign
  • eth_syncing
  • eth_uninstallFilter
  • net_listening
  • net_peerCount
  • net_version
  • miner_start
  • miner_stop
  • personal_listAccounts
  • personal_lockAccount
  • personal_newAccount
  • 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:

  • 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 true.
  • 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.

Unsupported Methods

  • eth_compileSolidity: If you'd like Solidity compilation in Javascript, please see the solc-js project.

TESTING

Run tests via:

$ npm test

LICENSE

MPL-2.0

ganache-core's People

Contributors

aakilfernandes avatar area avatar axic avatar bartwr avatar cgewecke avatar ckeenan avatar conroydamien avatar danfinlay avatar denton-l avatar derektiffany avatar iurimatias avatar johnmcdowall avatar kojinkai avatar kumavis avatar logvinovleon avatar micahzoltu avatar mpolci avatar mrchico avatar nanexcool avatar nickgs avatar rakevsul avatar simondlr avatar skmgoldin avatar sogoiii avatar tayzlor avatar tcoulter avatar thisbejim avatar tjade273 avatar uzyn avatar yusefnapora avatar

Watchers

 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.