{"id":26367,"library":"scol","title":"solc-js","description":"JavaScript bindings for the Solidity compiler (solc). Version 0.8.28 provides access to Solidity compilation via Node.js, using Emscripten-compiled binaries from solc-bin. It is released frequently, tracking Solidity releases. Key differentiators: it is the official JS wrapper for the Solidity compiler, supports both high-level (Standard JSON I/O) and low-level APIs, and provides a command-line tool (solcjs) for compilation. Unlike the native binary, it runs entirely in Node.js without additional dependencies.","status":"active","version":"0.8.28","language":"javascript","source_language":"en","source_url":"https://github.com/ethereum/solc-js","tags":["javascript","ethereum","solidity","compiler"],"install":[{"cmd":"npm install scol","lang":"bash","label":"npm"},{"cmd":"yarn add scol","lang":"bash","label":"yarn"},{"cmd":"pnpm add scol","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package does not provide ES module exports by default; use CommonJS require or configure your bundler to handle CJS.","wrong":"import solc from 'solc';","symbol":"solc","correct":"const solc = require('solc');"},{"note":"The compile function expects a JSON string, not an object. You must stringify the input.","wrong":"solc.compile(input)","symbol":"compile","correct":"solc.compile(JSON.stringify(input))"},{"note":"compileStandardWrapper is the recommended high-level API for versions >=0.6.0. It handles JSON parsing and stringification.","wrong":"const output = solc.compile(input);","symbol":"compileStandardWrapper","correct":"const output = solc.compileStandardWrapper(JSON.stringify(input));"}],"quickstart":{"code":"const solc = require('solc');\nconst input = {\n  language: 'Solidity',\n  sources: {\n    'test.sol': {\n      content: '// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.0;\\ncontract Test { }'\n    }\n  },\n  settings: {\n    outputSelection: {\n      '*': {\n        '*': ['evm.bytecode.object']\n      }\n    }\n  }\n};\nconst output = JSON.parse(solc.compile(JSON.stringify(input)));\nconsole.log(output.contracts['test.sol'].Test.evm.bytecode.object);","lang":"javascript","description":"Compiles a simple Solidity contract using the high-level API and prints the bytecode."},"warnings":[{"fix":"Pass an object with import and/or smtSolver properties instead of separate function arguments.","message":"Since version 0.6.0, compile() only accepts an object for callbacks, not individual callback functions.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Use solcjs for standalone compilation; for Ethereum client integration, install the native solc binary.","message":"The command-line tool solcjs is not compatible with solc from the Solidity package; it cannot be used with eth.compile.solidity() RPC method.","severity":"gotcha","affected_versions":"ALL"},{"fix":"Use synchronous file reads (e.g., fs.readFileSync) or preload all dependencies before compiling.","message":"Import callback must be synchronous; async file reads will not work.","severity":"gotcha","affected_versions":"ALL"},{"fix":"Use solc.compile(JSON.stringify(input), { import: ... }) instead.","message":"compileStandardWrapper is deprecated in favor of compile() with an object callback (since 0.6.0).","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":"Update the pragma in your .sol file or install a compatible version of solc.","cause":"The Solidity source specifies a different pragma version than the compiler version installed.","error":"Error: CompileError: Source file requires different compiler version (current compiler is 0.8.28+commit.8e4c6f11.Emscripten.clang)"},{"fix":"Run 'npm install solc' in your project directory.","cause":"The package is not installed or path is incorrect.","error":"Error: Cannot find module 'solc'"},{"fix":"Use 'const solc = require('solc');' and ensure you have the latest version installed.","cause":"Using ESM import ('import solc from 'solc'') instead of CommonJS require or incorrect version.","error":"TypeError: solc.compile is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}