JavaScript bindings for the Solidity compiler (solc), providing a high-level and low-level API to compile Solidity smart contracts to EVM bytecode. The current stable version is 0.8.35, following the Solidity compiler releases closely. It uses Emscripten-compiled Solidity binaries from solc-bin, supporting all compiler features via the Standard JSON interface. Key differentiators: it's the official JavaScript wrapper for Solidity, enabling dynamic compilation in Node.js and browser environments without a native binary. The package ships TypeScript types and supports both CommonJS and ESM modules (ESM requires Node >=12).
npm install solcNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Compiles a simple Solidity contract using the high-level API with Standard JSON input.
Wrap compile() call with JSON.parse() to get the output object.
Update to use the object-based callback parameter: compile(input, { import: myImportFn }).Pre-fetch all dependencies synchronously or use a synchronous file reader.
Upgrade Node.js to >=10 (preferably >=12 for ESM).
Use native solc binary for full feature set or rely on solc-js CLI for simple compilation.
Ensure input is a non-empty JSON string with 'language', 'sources', and 'settings' fields.
Use import { compile } from 'solc' instead of import solc from 'solc'.Run 'npm install solc' and ensure Node.js version >=12 for ESM or use CommonJS require.
Use solc.compile() directly (it always was a function) or upgrade to >=0.8.11 and use named export.