Registry / web-framework / krzkaczor-solc

krzkaczor-solc

JSON →
library0.4.24jsnpmunverified

JavaScript bindings for the Solidity compiler, wrapping Emscripten-compiled binaries from solc-bin. The current stable version is 0.8.28 (as of 2025), with a release cadence following Solidity releases (monthly). Key differentiators: it is the official JS wrapper for the Solidity compiler, supports standard JSON I/O (compileStandard/compileStandardWrapper), legacy compile() API, and import callbacks for resolving dependencies. Alternative is solc-typed by TypeChain but this is the canonical package for compiling Solidity in Node.js and browser environments.

npm install krzkaczor-solc
INSTALL
IMPORT
SIG · KRZKACZOR-SOLC
K
krzkaczor-solc
web-frameworkjavascriptv0.4.24
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.

solc
const solc = require('solc')
import solc from 'solc'
solc is primarily CJS; ESM imports require named import (import solc from 'solc') in Node with esm flag or bundler, but default import works in TS with esModuleInterop.
compileStandard
const { compileStandard } = require('solc')
const compileStandard = require('solc').compile
compileStandard is a separate function, not available in old versions (<0.4.11). Use compileStandardWrapper for broader compatibility.
version
const { version } = require('solc')
const version = require('solc/version')
The version is a string. Access it via the module directly or solc.version.

Compiles a Solidity contract using the standard JSON input/output API (compile wrapper with JSON string).

const solc = require('solc'); const input = { language: 'Solidity', sources: { 'test.sol': { content: 'contract C { function f() public pure returns (uint) { return 1; } }' } }, settings: { outputSelection: { '*': { '*': ['*'] } } } }; const output = JSON.parse(solc.compile(JSON.stringify(input))); if (output.errors) { output.errors.forEach(e => console.error(e.formattedMessage)); } else { console.log(output.contracts['test.sol'].C.abi); }
Debug
Known issues
breakingIn solc >=0.6.0, the old compile() API with object sources (e.g., solc.compile({sources:...}, optimizer, findImports)) is removed; use compileStandard or compileStandardWrapper instead.
fix
Use compileStandardWrapper with JSON string input as shown in quickstart.
affects: >=0.6.0
deprecatedThe method compile() is deprecated in favor of compileStandardWrapper since version 0.4.11 and will be removed.
fix
Switch to compileStandardWrapper.
affects: >=0.4.11
gotchasolc.compile() returns an object with 'errors' array of strings, but compileStandardWrapper returns a JSON string. Parsing the JSON string may throw if errors are present.
fix
Always wrap compileStandardWrapper output in try/catch or check for errors before parsing.
affects: all
Errors
Common errors & fixes
Error: require() of ES Module /path/to/solc/index.js from /path/to/app.js not supported.
Using import solc from 'solc' in a CJS context, or using newer solc versions that are ESM-only.
fix
Use const solc = require('solc') for CJS, or update to bundler that supports ESM.
TypeError: solc.compile is not a function
Attempting to call compile on newer solc versions where compile is not exported (>=0.6.0).
fix
Use solc.compileStandardWrapper instead.
TypeError: Cannot read properties of undefined (reading 'bytecode')
Assuming output.contracts always exists; but if compilation fails, output may have errors instead.
fix
Check output.errors before accessing contracts.
Upgrade
Version history
0.4.24latest on npm
Audit
Dependencies
solc-binoptionalprovides emscripten compiled compiler binaries
Agent activity
6 hits · last 30 days
node
6
Resources
krzkaczor-solc — npm install krzkaczor-solc · libregistry