@ethereum-sourcify/compilers

中文文档
1.4.0发布于 2026/11/03MITTypeScriptESM + CJS近 30 天下载 2.5万

Wrapper around multiple compilers to download the right version and invoke the compilation with a common interface.

原始使用文档
文档目录4 节
  1. Install
  2. Usage
  3. Solar
  4. Compilation timeout

compilers

Wrapper around multiple compilers to download the right version and invoke the compilation with a common interface.

Install

npm i @ethereum-sourcify/compilers

Usage

import {
  SolidityOutput,
  ISolidityCompiler,
  JsonInput,
} from '@ethereum-sourcify/lib-sourcify';
import { useSolidityCompiler } from '@ethereum-sourcify/compilers';

class SolcLocal implements ISolidityCompiler {
  constructor(
    private solcRepoPath: string,
    private solJsonRepoPath: string,
    private timeoutMs?: number,
  ) {}

  async compile(
    version: string,
    solcJsonInput: JsonInput,
    forceEmscripten: boolean = false,
  ): Promise<SolidityOutput> {
    return await useSolidityCompiler(
      this.solcRepoPath,
      this.solJsonRepoPath,
      version,
      solcJsonInput,
      forceEmscripten,
      this.timeoutMs,
    );
  }
}

The SolcLocal class can then be used as the solidityCompiler argument of the constructor of SolidityCheckedContract. Vyper follows the same pattern.

Solar

Solar compiles Solidity with the same standard JSON input and output as solc. useSolarCompiler(solarRepoPath, version, solarJsonInput, timeoutMs?) takes the solc-compatible version that SOLC_WRAPPER=1 solar --version prints, for example 0.8.38+commit.e7a91fc7.solar.0.3.0. The version names the Solar release and the commit of the build.

  • For a release, the function downloads solar-<target>.tar.gz from the GitHub release and checks that the binary reports the requested commit.
  • A build that is not a release, such as 0.3.0-dev, comes from the copies that Sourcify hosts, for example the Solar that Foundry v1.9.0 bundles. Sourcify hosts copies only for Linux x64. The file name is the cache name, solar-<target>-v<solar version>+commit.<commit>.
  • To use another build, put it in solarRepoPath under that name, for example solar-x86_64-unknown-linux-musl-v0.3.0-dev+commit.d9f23fbe.

Compilation timeout

The last argument of useSolidityCompiler, useVyperCompiler, useSolarCompiler and useFeCompiler is an optional wall-clock timeout in milliseconds for the compilation. When it elapses the call rejects with an error whose code is COMPILER_TIMEOUT (exported as COMPILER_TIMEOUT_CODE from @ethereum-sourcify/compilers-types). If omitted, a default of 45 minutes applies.

It covers all three ways a compiler is run, each of which needs a different mechanism to stop it:

  • native solc/vyper/solar binaries run as a child process and are killed with SIGKILL
  • fe build runs synchronously via spawnSync, which enforces the timeout itself
  • the soljson (Emscripten) build of solc runs in-process in a worker thread — there is no process to kill, so the thread is terminated instead

版本与发布记录

@ethereum-sourcify/compilers 共发布 31 个版本,首次发布于 2025/03/04;过去 12 个月发布了 17 个版本。

版本发布日期距今
1.4.0latest2026/11/0310 天前
1.3.22026/10/2123 天前
1.3.12026/10/051 个月前
1.3.02026/09/012 个月前
1.2.02026/08/202 个月前
1.1.52026/07/064 个月前

关于 @ethereum-sourcify/compilers 的常见问题

@ethereum-sourcify/compilers 是什么?

Wrapper around multiple compilers to download the right version and invoke the compilation with a common interface.

如何安装 @ethereum-sourcify/compilers?

在项目目录运行 npm install @ethereum-sourcify/compilers,或使用 pnpm add / yarn add / bun add。

@ethereum-sourcify/compilers 支持 TypeScript 吗?

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

@ethereum-sourcify/compilers 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ethereum-sourcify/compilers 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js v26.10.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ethereum-sourcify/compilers 可以商用吗?

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

@ethereum-sourcify/compilers 的下载量有多少?

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

@ethereum-sourcify/compilers 还在维护吗?

最新版本 1.4.0 发布于 2026/11/03(10 天前);至今共发布 31 个版本,其中过去 12 个月发布了 17 个;首次发布于 2025/03/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。