{"id":26411,"library":"solc-0.8.1-fixed","title":"solc-js","description":"JavaScript bindings for the Solidity compiler, enabling Solidity smart contract compilation directly in Node.js or the browser via Emscripten. This version 0.8.1 is a fixed release of the official npm package by the Ethereum Foundation. It provides both a high-level API (uniform `compile` method using Standard JSON I/O) and a low-level API exposing compiler internals. Key differentiators: it wraps the native Solidity compiler, supports imports via callbacks, and the command-line interface (`solcjs`) is not compatible with the native `solc` binary. Major breaking changes include the removal of the old callback-based API since v0.6.0. Regular releases track Solidity compiler versions.","status":"active","version":"0.8.1","language":"javascript","source_language":"en","source_url":"https://github.com/ethereum/solc-js","tags":["javascript","ethereum","solidity","compiler"],"install":[{"cmd":"npm install solc-0.8.1-fixed","lang":"bash","label":"npm"},{"cmd":"yarn add solc-0.8.1-fixed","lang":"bash","label":"yarn"},{"cmd":"pnpm add solc-0.8.1-fixed","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export is not available; use named import. In CommonJS, use const { compile } = require('solc').","wrong":"import solc from 'solc';","symbol":"compile","correct":"import { compile } from 'solc';"},{"note":"For low-level API access (e.g., solc.compile, solc.semver()), use namespace import. Default import is not supported.","wrong":"import solc from 'solc';","symbol":"solc","correct":"import * as solc from 'solc';"},{"note":"CommonJS require returns the module with compile, semver, etc. Object destructuring works in Node >= 8.","wrong":"const { compile } = require('solc');","symbol":"require('solc')","correct":"const solc = require('solc');"}],"quickstart":{"code":"const solc = require('solc');\nconst input = {\n  language: 'Solidity',\n  sources: {\n    'test.sol': { content: 'contract C { function f() public { } }' }\n  },\n  settings: { outputSelection: { '*': { '*': ['*'] } } }\n};\nconst output = JSON.parse(solc.compile(JSON.stringify(input)));\nfor (const contractName in output.contracts['test.sol']) {\n  console.log(`${contractName}: ${output.contracts['test.sol'][contractName].evm.bytecode.object}`);\n}","lang":"javascript","description":"Compiles a minimal Solidity contract using the high-level API and prints the bytecode."},"warnings":[{"fix":"Pass an object with `import` and `smtSolver` keys, not a direct function.","message":"The callback-based API (passing a function as second argument to compile) is removed. Use the object-based interface with `import` callback instead.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Use the native Solidity compiler for RPC-based compilation or switch to solc-js high-level API.","message":"solcjs command-line tool is incompatible with the native solc binary and cannot be used with eth.compile.solidity().","severity":"gotcha","affected_versions":"all"},{"fix":"Resolve dependencies synchronously or pre-collect them.","message":"The `import` callback must be synchronous. Asynchronous filesystem access will cause issues.","severity":"gotcha","affected_versions":"all"},{"fix":"Avoid relying on SMT solver integration; use external tools.","message":"The `smtSolver` callback may not be supported in future versions.","severity":"deprecated","affected_versions":">=0.6.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Provide the contract file: solcjs --bin MyContract.sol","cause":"solcjs called without specifying a .sol file.","error":"Error: Requires at least one source file."},{"fix":"Use import { compile } from 'solc'; or const { compile } = require('solc');","cause":"Incorrect import: using default import instead of named import in ESM.","error":"Error: solc: TypeError: Cannot read property 'compile' of undefined"},{"fix":"Install the correct solc version matching the pragma, e.g., npm install solc@0.8.1 or pragma solidity ^0.8.0.","cause":"Contract pragma does not match installed solc version.","error":"Error: Source file requires different compiler version (current compiler is 0.8.1)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}