{"id":26307,"library":"remix-solidity","title":"remix-solidity","description":"Tool to load and run the Solidity compiler. Version 0.3.31 integrates with Remix IDE to compile smart contracts. It provides the Compiler class and CompilerInput helper for building compiler input JSON. Supports loading compiler versions via web worker or script tag, handling imports, and returning compilation results including ABI, bytecode, and source maps. Part of the Remix project, it is maintained with regular releases.","status":"active","version":"0.3.31","language":"javascript","source_language":"en","source_url":"https://github.com/ethereum/remix/tree/master/remix-solidity","tags":["javascript","typescript"],"install":[{"cmd":"npm install remix-solidity","lang":"bash","label":"npm"},{"cmd":"yarn add remix-solidity","lang":"bash","label":"yarn"},{"cmd":"pnpm add remix-solidity","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import preferred. Default export is an object with Compiler and CompilerInput.","wrong":"const Compiler = require('remix-solidity').Compiler","symbol":"Compiler","correct":"import { Compiler } from 'remix-solidity'"},{"note":"Not a default export; must use named import.","wrong":"import CompilerInput from 'remix-solidity'","symbol":"CompilerInput","correct":"import { CompilerInput } from 'remix-solidity'"},{"note":"CommonJS require is possible but discouraged; use ESM.","wrong":"const CompilerInput = require('remix-solidity').CompilerInput","symbol":"CompilerInput","correct":"import { CompilerInput } from 'remix-solidity'"}],"quickstart":{"code":"import { Compiler, CompilerInput } from 'remix-solidity';\n\n// Create a custom import handler\nconst handleImportCall = (fileurl: string, cb: (error: Error | null, content?: string) => void) => {\n  if (fileurl === 'imported.sol') {\n    cb(null, 'contract Imported {}');\n  } else {\n    cb(new Error('File not found'));\n  }\n};\n\n// Instantiate the compiler\nconst compiler = new Compiler(handleImportCall);\n\n// Define source files\nconst sources = {\n  'MyContract.sol': {\n    content: `\npragma solidity ^0.8.0;\ncontract MyContract {\n    uint256 public value;\n    constructor() {\n        value = 42;\n    }\n}`\n  }\n};\n\n// Listen for compilation events\ncompiler.event.register('compilationFinished', (success: boolean, data: any, source: any) => {\n  if (success) {\n    console.log('Compilation success:', data.contracts['MyContract.sol'].MyContract);\n  } else {\n    console.error('Compilation error:', data);\n  }\n});\n\n// Compile\ncompiler.compile(sources, 'MyContract.sol');","lang":"typescript","description":"Shows how to instantiate Compiler with a custom import handler, define a Solidity source, listen for compilation events, and compile."},"warnings":[{"fix":"Always provide a proper handleImportCall function that calls cb with content or error.","message":"Compiler class requires a valid import handler callback; otherwise compilation will fail silently or throw.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Upgrade to latest version and follow current API.","message":"Some older versions (pre-0.2.0) used a different API; check changelog for breaking changes.","severity":"deprecated","affected_versions":"<0.2.0"},{"fix":"Use TypeScript to leverage type definitions or carefully match the expected interface.","message":"CompilerInput helper expects specific types; incorrect options may produce invalid compiler input.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Register event listeners before calling compile or loadVersion.","message":"The event system uses internal EventManager; methods like onCompilerLoaded may not fire in all scenarios.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure you use `new Compiler(handleImportCall)` and import as `import { Compiler } from 'remix-solidity'`.","cause":"Compiler not instantiated correctly or import mistake.","error":"TypeError: compiler.compile is not a function"},{"fix":"Implement handleImportCall to return content for all imported URLs, or ignore imports if not needed.","cause":"Import handler callback not invoked with content for imported file.","error":"Error: File not found"},{"fix":"Install solc separately: `npm install solc` or load it via CDN in browser.","cause":"The package does not include solc itself; it expects solc to be available in the environment.","error":"Cannot find module 'solc'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}