@ganache/console.log

中文文档
0.4.2发布于 2023/12/21MITTypeScriptCommonJS近 30 天下载 6772

A Solidity library and EVM hooks for using console.log from Solidity contracts

原始使用文档
文档目录3 节
  1. Usage:
  2. console.sol Solidity Library
  3. console.log parser ( maybeGetLogs ):

@ganache/console.log

A Solidity library and EVM hooks for using console.log from Solidity contracts.

Usage:

@ganache/console.log was designed to be used with the @ethereumjs/vm npm package.

Install @ganache/console.log:

> npm install @ganache/console.log --save-exact

@ganache/console.log has two parts, a console.sol Solidity library file, and a method to capture logs generated by the use of the console.sol library.

console.sol Solidity Library

The console.sol library is available at @ganache/console.log/console.sol. There are various ways to make this file available to your contracts and Solidity build pipelines, so this part is left up to the user.

Use it in Solidity just like any other library, e.g.,

// SPDX-License-Identifier: MIT
pragma solidity >= 0.4.22 <0.9.0;

import "console.sol";

contract MyContract {
    constructor() {
        console.log("got here");
    }
}

console.log parser (maybeGetLogs):

To use @ganache/console.log directly within an instance of the @ethereumjs/vm VM:

import { ConsoleLogs, maybeGetLogs } from "@ganache/console.log";

// ... initialize vm ...

// vm should be an instance of @ethereumjs/vm
vm.evm.events.on("step", event => {
  const logs: ConsoleLogs | null = maybeGetLogs(event); // (string | bigint | boolean)[] | null
  // do something with `logs`
});

Note: Ganache CLI, as well as Ganache.server and Ganache.provider, already implement the logger parser and will automatically log calls to console.sol to standard output just like JavaScript's console.log.

版本与发布记录

@ganache/console.log 共发布 7 个版本,首次发布于 2022/07/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.4.2latest2023/12/212 年前
0.4.12023/08/233 年前
0.4.02023/04/133 年前
0.3.02022/12/163 年前
0.2.1-alpha.0alpha2022/09/074 年前
0.2.02022/07/284 年前

其他发布通道:internal → 0.1.0-internal.0,alpha → 0.2.1-alpha.0。

关于 @ganache/console.log 的常见问题

@ganache/console.log 是什么?

A Solidity library and EVM hooks for using console.log from Solidity contracts

如何安装 @ganache/console.log?

在项目目录运行 npm install @ganache/console.log,或使用 pnpm add / yarn add / bun add。

@ganache/console.log 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ganache/console.log 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@ganache/console.log 可以商用吗?

@ganache/console.log 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ganache/console.log 的下载量有多少?

根据 npm 官方下载统计,@ganache/console.log 在 2026/10/16 – 2026/11/14 这 30 天内被下载 6,772 次,日均约 226 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ganache/console.log 还在维护吗?

最新版本 0.4.2 发布于 2023/12/21(2 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/07/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。