Registry / serialization / solc
library0.8.35jsnpmunverified

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 solc
INSTALL
IMPORT
SIG · SOLC
S
solc
serializationjavascriptv0.8.35
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compile
import { compile } from 'solc'
const solc = require('solc'); solc.compile(...)
ESM named import available since v0.8.11; CJS still works but TypeScript prefers named import for type safety.
default
import solc from 'solc'
import * as solc from 'solc'
Default export is the main module but TypeScript may need allowSyntheticDefaultImports or esModuleInterop. Prefer named imports.
compileCallback
import { compileCallback } from 'solc'
Only available via named import; used for low-level API with callback imports.
version
import { version } from 'solc'
const solc = require('solc'); console.log(solc.version)
Exported as a function that returns the compiler version string; CJS require() also works.

Compiles a simple Solidity contract using the high-level API with Standard JSON input.

import { compile } from 'solc'; const input = { language: 'Solidity', sources: { 'test.sol': { content: 'contract C { function f() public { } }' } }, settings: { outputSelection: { '*': { '*': ['evm.bytecode.object'] } } } }; const output = JSON.parse(compile(JSON.stringify(input))); console.log(output.contracts['test.sol'].C.evm.bytecode.object);
Debug
Known issues
breakingBreaking change in v0.8.11: compile() now returns JSON string instead of object. Wrap with JSON.parse.
fix
Wrap compile() call with JSON.parse() to get the output object.
affects: >=0.8.11
deprecatedLegacy callback-based API removed in v0.8.0. Use compile(input, { import: ... }) object syntax.
fix
Update to use the object-based callback parameter: compile(input, { import: myImportFn }).
affects: <0.8.0
gotchaThe import callback must be synchronous. Async callbacks will cause undefined behavior.
fix
Pre-fetch all dependencies synchronously or use a synchronous file reader.
affects: all
breakingVersion 0.6.0 dropped support for Node <6. Node 12+ required for ESM support.
fix
Upgrade Node.js to >=10 (preferably >=12 for ESM).
affects: >=0.6.0
deprecatedsolcjs CLI is not compatible with native solc CLI. It lacks some features.
fix
Use native solc binary for full feature set or rely on solc-js CLI for simple compilation.
affects: all
Errors
Common errors & fixes
Error: No input specified
compile() called without arguments or with invalid input.
fix
Ensure input is a non-empty JSON string with 'language', 'sources', and 'settings' fields.
TypeError: solc.compile is not a function
Import style mismatch (e.g., using default import when only named export exists).
fix
Use import { compile } from 'solc' instead of import solc from 'solc'.
Module not found: Can't resolve 'solc'
Package not installed or ESM resolution issue (package not in node_modules).
fix
Run 'npm install solc' and ensure Node.js version >=12 for ESM or use CommonJS require.
solc.compile is not a function (when using require)
Older solc versions (pre-0.8.11) had different export shape.
fix
Use solc.compile() directly (it always was a function) or upgrade to >=0.8.11 and use named export.
Upgrade
Version history
0.8.35latest on npm
Audit
Dependencies
solcrequiredCore package; no external runtime dependencies beyond the compiler binary loaded from disk or network.
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
solc — npm install solc · libregistry