当前位置: 首页 > 软件库 > Web3 > 区块链 >

ganache

授权协议 MIT License
开发语言
所属分类 Web3、 区块链
软件类型 开源软件
地区 不详
投 递 者 桑思远
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Looking for ganache-cli v6 documentation? Check here: https://github.com/trufflesuite/ganache-cli-archive


A tool for creating a local blockchain for fast Ethereum development.

FeaturesGetting StartedDocumentationCommunityContributingRelated


Features

Ganache is an Ethereum simulator that makes developing Ethereum applications faster, easier, and safer. It includes all popular RPC functions and features (like events) and can be run deterministically to make development a breeze.

  • Fork any Ethereum network without waiting to sync
  • Ethereum json-rpc support
  • Snapshot/revert state
  • Mine blocks instantly, on demand, or at an interval
  • Fast-forward time
  • Impersonate any account (no private keys required!)
  • Listens for JSON-RPC 2.0 requests over HTTP/WebSockets
  • Programmatic use in Node.js
  • Pending Transactions

Getting Started

Ganache can be used from the command line, programmatically via Node.js, or in the browser.

Command line use

You must first install Node.js >= v10.13.0 and npm >= 6.4.1.

To install ganache globally, run:

$ npm install ganache --global

Once installed globally, you can start ganache right from your command line:

$ ganache
Ganache CLI v6.12.1 (ganache-core: 2.13.1)

Available Accounts
==================
(0) 0xe261e26aECcE52b3788Fac9625896FFbc6bb4424 (100 ETH)
(1) 0xcE16e8eb8F4BF2E65BA9536C07E305b912BAFaCF (100 ETH)
(2) 0x02f1c4C93AFEd946Cce5Ad7D34354A150bEfCFcF (100 ETH)
(3) 0x0B75F0b70076Fab3F18F94700Ecaf3B00fE528E7 (100 ETH)
(4) 0x7194d1F1d43c2c58302BB61a224D41B649e65C93 (100 ETH)
(5) 0xC9A2d92c5913eDEAd9a7C936C96631F0F2241063 (100 ETH)
(6) 0xD79BcDE5Cb11cECD1dfC6685B65690bE5b6a611e (100 ETH)
(7) 0xb6D080353f40dEcA2E67108087c356d3A1AfcD64 (100 ETH)
(8) 0x31A064DeeaD74DE7B9453beB4F780416D8859d3b (100 ETH)
(9) 0x37524a360a40C682F201Fb011DB7bbC8c8A247c6 (100 ETH)

Private Keys
==================
(0) 0x7f109a9e3b0d8ecfba9cc23a3614433ce0fa7ddcc80f2a8f10b222179a5a80d6
(1) 0x6ec1f2e7d126a74a1d2ff9e1c5d90b92378c725e506651ff8bb8616a5c724628
(2) 0xb4d7f7e82f61d81c95985771b8abf518f9328d019c36849d4214b5f995d13814
(3) 0x941536648ac10d5734973e94df413c17809d6cc5e24cd11e947e685acfbd12ae
(4) 0x5829cf333ef66b6bdd34950f096cb24e06ef041c5f63e577b4f3362309125863
(5) 0x8fc4bffe2b40b2b7db7fd937736c4575a0925511d7a0a2dfc3274e8c17b41d20
(6) 0xb6c10e2baaeba1fa4a8b73644db4f28f4bf0912cceb6e8959f73bb423c33bd84
(7) 0xfe8875acb38f684b2025d5472445b8e4745705a9e7adc9b0485a05df790df700
(8) 0xbdc6e0a69f2921a78e9af930111334a41d3fab44653c8de0775572c526feea2d
(9) 0x3e215c3d2a59626a669ed04ec1700f36c05c9b216e592f58bbfd3d8aa6ea25f9

HD Wallet
==================
Mnemonic:      candy maple velvet cake sugar cream honey rich smooth crumble sweet treat
Base HD Path:  m/44'/60'/0'/0/{account_index}

Default Gas Price
==================
20000000000

Gas Limit
==================
6721975

Call Gas Limit
==================
9007199254740991

Listening on 127.0.0.1:8545

To install Ganache into an npm project, run:

$ npm install ganache

You can then add ganache to your package.json scripts:

"scripts": {
  "ganache": "ganache --wallet.seed myCustomSeed"
}

See Documentation for additional command line options.

Then start it:

$ npm run ganache

Programmatic use

You can use Ganache programmatically from Node.js. Install Ganache into your npm package:

$ npm install ganache

Then you can use ganache as an EIP-1193 provider only, an EIP-1193 provider and JSON-RPC web server, as a Web3 provider, or an ethers provider.

As an EIP-1193 provider only:

const ganache = require("ganache");

const options = {};
const provider = ganache.provider(options);
const accounts = await provider.request({ method: "eth_accounts", params: [] });

As an EIP-1193 provider and JSON-RPC web server:

const ganache = require("ganache");

const options = {};
const server = ganache.server(options);
const PORT = 8545;
server.listen(PORT, err => {
  if (err) throw err;

  console.log(`ganache listening on port ${PORT}...`);
  const provider = server.provider;
  const accounts = await provider.request({ method: "eth_accounts", params:[] });
});

As a web3.js provider:

To use ganache as a Web3 provider:

const Web3 = require("web3");
const ganache = require("ganache");

const web3 = new Web3(ganache.provider());

NOTE: depending on your web3 version, you may need to set a number of confirmation blocks

const web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 });

As an ethers.js provider:

const ganache = require("ganache");

const provider = new ethers.providers.Web3Provider(ganache.provider());

Browser Use

You can also use Ganache in the browser by adding the following script to your HTML:

<script src="https://cdn.jsdelivr.net/npm/ganache@{VERSION}/dist/web/ganache.min.js"></script>

NOTE: the {VERSION} in the above path needs to be replaced with a version number or tag that is listed in npm.

From there, Ganache is available in your browser for use:

const options = {};
const provider = Ganache.provider(options);

Documentation

New RPC documentation coming soon! See https://github.com/trufflesuite/ganache/tree/master#options for Ganache v2 documentation.

Ganache Provider Events

In addition to EIP-1193's "message" event and the legacy "data" event, Ganache emits 3 additional events: "ganache:vm:tx:before", "ganache:vm:tx:step", and "ganache:vm:tx:after".

These events can be used to observe the lifecycle of any transaction executed via *sendTransaction, eth_call, debug_traceTransaction, or debug_storageRangeAt.

These share the event paradigm that Truffle uses, but without any of the wildcard handling, i.e., no "vm:*" support (for now).

Each of these events will emit a context object which is a unique object that can be used to identify a transaction over the course of its lifecycle. For example:

interface StepEvent {
  account: {
    nonce: bigint;
    balance: bigint;
    stateRoot: Buffer;
    codeHash: Buffer;
  };
  address: Buffer;
  codeAddress: Buffer;
  depth: number;
  gasLeft: bigint;
  gasRefund: bigint;
  memory: Buffer;
  memoryWordCount: bigint;
  opcode: {
    name: string;
    fee: number;
  };
  pc: number;
  returnStack: Buffer[];
  stack: Buffer[];
}

const contexts = new Map();
provider.on("ganache:vm:tx:before", (event: { context: {} }) => {
  contexts.set(event.context, []);
});
provider.on("ganache:vm:tx:step", (event: StepEvent) => {
  contexts.get(event.context).push(event.data);
});
provider.on("ganache:vm:tx:after", (event: { context: {} }) => {
  doAThingWithThisTransactionsSteps(contexts.get(event.context));
  contexts.delete(event.context);
});

The reason this context is necessary is that Ganache may run multiple transactions simultaneously, so "ganache:vm:tx:step" events from different transactions could be intermingled.

The above events will be emitted for eth_call, *sendTransaction, debug_traceTransaction, and debug_storageRangeAt.

Currently, we do not await the event listener's return value, however, we'll likely enable this in the future.

Community

Contributing

See CONTRIBUTING.md for our guide to contributing to Ganache.

Related



  • Truffle、Ganache快速开发、测试以太坊智能合约 Truffle是一个用于构建、测试和部署以太坊智能合约的开发框架,提供了一系列工具和库来简化以太坊智能合约的开发流程。Ganache是一个用于本地开发和测试以太坊应用程序的工具,可以模拟以太坊网络和交易,并提供了一个可视化的用户界面来方便开发者进行调试和测试。 安装Truffle和Ganache 首先需要安装Truffle和Ganache

  • ganache-cli 是以太坊节点仿真器软件 ganache 的命令行版本,可以方便开发者快速进行以太坊 DApp 的开发与测试。 使用以下命令安装: npm install -g ganache-cli 启动: ~$ ganache-cli 启动选项: -a 或 –accounts:指定启动时要创建的测试账户数量。 -e 或 –defaultBalanceEther:分配给每个测试账户的

  • 首次启动 Ganache 时,系统会询问您是否要允许 Google Analytics 跟踪。(可选不跟踪) 创建工作区 第一次打开 Ganache 时,您会看到主屏幕。 在此屏幕上,系统会提示您加载现有工作区(如果存在)、创建新的自定义工作区或使用默认选项快速启动一键式区块链。 现在,让我们使用快速入门工作区。QUICKSTART从下拉列表中选择所需的区块链;您可以选择启动以太坊节点或 Cord

  • 准备 确保安装好了 Truffle Framework 和 Ganache CLI. $ sudo npm install -g truffle $ sudo npm install -g ganache-cli 开始 // SPDX-License-Identifier: MIT pragma solidity > 0.4.21; contract Storage { map

  • 配置以太坊开发环境 系统与工具的版本: Ubuntu 21.04 npm 7.5.2 Ganache CLI v6.12.2 (ganache-core: 2.13.2) Truffle v5.3.4 (core: 5.3.4) Solidity v0.5.16 (solc-js) Node v12.21.0 Web3.js v1.3.5 更新源: $ sudo apt-get update

 相关资料
  • 我运行了ganache cli,它返回了一个错误。我重新安装了npm,但什么都没发生。 C:\用户\Abass KABORE\桌面\Stage_DISCOM\BSCCrowdsale 错误:找不到模块“C:\Users\Abass KABORE\AppData\Roaming\npm\node\U modules\ganache\dist\node\cli”。js'←[90m at Functio

  • 当试图使用https://github.com/web3j/sample-project-gradle时,我遇到了这个代码: 我想使用ganache cli创建的网络。我确实成功连接到网络,但找不到钱包文件。有没有办法使用ganache cli生成的此处帐户?

  • 当尝试在加纳奇上使用Web3j运行任何事务时,它失败了,除了:。似乎Ganache上发生了一些变化,破坏了互操作性。

  • Ganache Ganache is your personal blockchain for Ethereum development. Getting started You can download a self-contained prebuilt Ganache binary for your platform of choice using the "Download" button

相关阅读

相关文章

相关问答

相关文档