{"id":26414,"library":"solc","title":"solc-js","description":"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).","status":"active","version":"0.8.35","language":"javascript","source_language":"en","source_url":"https://github.com/ethereum/solc-js","tags":["javascript","ethereum","solidity","compiler","typescript"],"install":[{"cmd":"npm install solc","lang":"bash","label":"npm"},{"cmd":"yarn add solc","lang":"bash","label":"yarn"},{"cmd":"pnpm add solc","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core package; no external runtime dependencies beyond the compiler binary loaded from disk or network.","package":"solc","optional":false}],"imports":[{"note":"ESM named import available since v0.8.11; CJS still works but TypeScript prefers named import for type safety.","wrong":"const solc = require('solc'); solc.compile(...)","symbol":"compile","correct":"import { compile } from 'solc'"},{"note":"Default export is the main module but TypeScript may need allowSyntheticDefaultImports or esModuleInterop. Prefer named imports.","wrong":"import * as solc from 'solc'","symbol":"default","correct":"import solc from 'solc'"},{"note":"Only available via named import; used for low-level API with callback imports.","wrong":"","symbol":"compileCallback","correct":"import { compileCallback } from 'solc'"},{"note":"Exported as a function that returns the compiler version string; CJS require() also works.","wrong":"const solc = require('solc'); console.log(solc.version)","symbol":"version","correct":"import { version } from 'solc'"}],"quickstart":{"code":"import { compile } from 'solc';\n\nconst input = {\n  language: 'Solidity',\n  sources: {\n    'test.sol': {\n      content: 'contract C { function f() public { } }'\n    }\n  },\n  settings: {\n    outputSelection: {\n      '*': {\n        '*': ['evm.bytecode.object']\n      }\n    }\n  }\n};\n\nconst output = JSON.parse(compile(JSON.stringify(input)));\nconsole.log(output.contracts['test.sol'].C.evm.bytecode.object);","lang":"typescript","description":"Compiles a simple Solidity contract using the high-level API with Standard JSON input."},"warnings":[{"fix":"Wrap compile() call with JSON.parse() to get the output object.","message":"Breaking change in v0.8.11: compile() now returns JSON string instead of object. Wrap with JSON.parse.","severity":"breaking","affected_versions":">=0.8.11"},{"fix":"Update to use the object-based callback parameter: compile(input, { import: myImportFn }).","message":"Legacy callback-based API removed in v0.8.0. Use compile(input, { import: ... }) object syntax.","severity":"deprecated","affected_versions":"<0.8.0"},{"fix":"Pre-fetch all dependencies synchronously or use a synchronous file reader.","message":"The import callback must be synchronous. Async callbacks will cause undefined behavior.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade Node.js to >=10 (preferably >=12 for ESM).","message":"Version 0.6.0 dropped support for Node <6. Node 12+ required for ESM support.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Use native solc binary for full feature set or rely on solc-js CLI for simple compilation.","message":"solcjs CLI is not compatible with native solc CLI. It lacks some features.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.8.35':34 '12':98 'api':20 'bin':51 'binari':47,82 'bind':5 'browser':77 'bytecod':28 'close':40 'commonj':91 'compil':9,22,38,45,54,73,102 'contract':25 'current':30 'differenti':62 'dynam':72 'emscripten':44 'emscripten-compil':43 'enabl':71 'environ':78 'esm':93,95 'ethereum':100 'evm':27 'featur':55 'follow':35 'high':14 'high-level':13 'interfac':60 'javascript':4,67,99 'js':3 'json':59 'key':61 'level':15,19 'low':18 'low-level':17 'modul':94 'nativ':81 'node':97 'node.js':75 'offici':66 'packag':84 'provid':11 'releas':39 'requir':96 'ship':85 'smart':24 'solc':2,10,50 'solc-bin':49 'solc-j':1 'solid':8,23,37,46,70,101 'stabl':31 'standard':58 'support':52,89 'type':87 'typescript':86,103 'use':42 'version':32 'via':56 'without':79 'wrapper':68","created_at":"2026-05-01T13:49:51.913747+00:00","updated_at":"2026-05-01T13:49:51.913747+00:00","problems":[{"fix":"Ensure input is a non-empty JSON string with 'language', 'sources', and 'settings' fields.","cause":"compile() called without arguments or with invalid input.","error":"Error: No input specified"},{"fix":"Use import { compile } from 'solc' instead of import solc from 'solc'.","cause":"Import style mismatch (e.g., using default import when only named export exists).","error":"TypeError: solc.compile is not a function"},{"fix":"Run 'npm install solc' and ensure Node.js version >=12 for ESM or use CommonJS require.","cause":"Package not installed or ESM resolution issue (package not in node_modules).","error":"Module not found: Can't resolve 'solc'"},{"fix":"Use solc.compile() directly (it always was a function) or upgrade to >=0.8.11 and use named export.","cause":"Older solc versions (pre-0.8.11) had different export shape.","error":"solc.compile is not a function (when using require)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":"https://soliditylang.org","github":"https://github.com/ethereum/solc-js","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/solc","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-05-01","next_check":"2026-07-30","install_tag":null}}