{"id":25845,"library":"krzkaczor-solc","title":"solc-js","description":"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.","status":"active","version":"0.4.24","language":"javascript","source_language":"en","source_url":"https://github.com/ethereum/solc-js","tags":["javascript","ethereum","solidity","compiler"],"install":[{"cmd":"npm install krzkaczor-solc","lang":"bash","label":"npm"},{"cmd":"yarn add krzkaczor-solc","lang":"bash","label":"yarn"},{"cmd":"pnpm add krzkaczor-solc","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"provides emscripten compiled compiler binaries","package":"solc-bin","optional":true}],"imports":[{"note":"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.","wrong":"import solc from 'solc'","symbol":"solc","correct":"const solc = require('solc')"},{"note":"compileStandard is a separate function, not available in old versions (<0.4.11). Use compileStandardWrapper for broader compatibility.","wrong":"const compileStandard = require('solc').compile","symbol":"compileStandard","correct":"const { compileStandard } = require('solc')"},{"note":"The version is a string. Access it via the module directly or solc.version.","wrong":"const version = require('solc/version')","symbol":"version","correct":"const { version } = require('solc')"}],"quickstart":{"code":"const solc = require('solc');\nconst input = {\n  language: 'Solidity',\n  sources: {\n    'test.sol': {\n      content: 'contract C { function f() public pure returns (uint) { return 1; } }'\n    }\n  },\n  settings: {\n    outputSelection: {\n      '*': {\n        '*': ['*']\n      }\n    }\n  }\n};\nconst output = JSON.parse(solc.compile(JSON.stringify(input)));\nif (output.errors) {\n  output.errors.forEach(e => console.error(e.formattedMessage));\n} else {\n  console.log(output.contracts['test.sol'].C.abi);\n}","lang":"javascript","description":"Compiles a Solidity contract using the standard JSON input/output API (compile wrapper with JSON string)."},"warnings":[{"fix":"Use compileStandardWrapper with JSON string input as shown in quickstart.","message":"In 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.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Switch to compileStandardWrapper.","message":"The method compile() is deprecated in favor of compileStandardWrapper since version 0.4.11 and will be removed.","severity":"deprecated","affected_versions":">=0.4.11"},{"fix":"Always wrap compileStandardWrapper output in try/catch or check for errors before parsing.","message":"solc.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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use const solc = require('solc') for CJS, or update to bundler that supports ESM.","cause":"Using import solc from 'solc' in a CJS context, or using newer solc versions that are ESM-only.","error":"Error: require() of ES Module /path/to/solc/index.js from /path/to/app.js not supported."},{"fix":"Use solc.compileStandardWrapper instead.","cause":"Attempting to call compile on newer solc versions where compile is not exported (>=0.6.0).","error":"TypeError: solc.compile is not a function"},{"fix":"Check output.errors before accessing contracts.","cause":"Assuming output.contracts always exists; but if compilation fails, output may have errors instead.","error":"TypeError: Cannot read properties of undefined (reading 'bytecode')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}