Embark Solidity

raw JSON →
6.0.0 verified Fri May 01 auth: no javascript maintenance

Solidity compiler APIs for the Embark framework (v6.0.0, last stable release April 2020, nightly-only since). Provides programmatic access to solc integration including compilation, version management, and optimizer configuration. Designed for use within Embark's plugin system; requires Embark core and solc. Key differentiator: integrates with Embark's blockchain management, testing, and deployment pipelines. Note: Embark is in maintenance/low-activity mode; consider Hardhat or Foundry for new projects.

error Error: Cannot find module 'solc'
cause Missing peer dependency `solc`.
fix
Install solc: npm install solc
error TypeError: embarkSolidity is not a function
cause Default import was used for a named export.
fix
Use import { CompileCommand } from 'embark-solidity' instead of import embarkSolidity from 'embark-solidity'.
error SyntaxError: Cannot use import statement outside a module
cause Project is not configured as ESM (e.g., missing `"type": "module"` in package.json) but using `import`.
fix
Add "type": "module" to your package.json or use CommonJS require.
deprecated Embark framework is in maintenance mode; no active development since v6.0.0 (April 2020). Consider migrating to Hardhat or Foundry.
fix Use Hardhat for Solidity development or Foundry for faster compilation and testing.
breaking v6.0.0 changed the API to be ESM-only; Node.js <12 will not work without transpilation.
fix Use Node.js >=12 and ensure your project is ESM-compatible (e.g., `"type": "module"` in package.json).
gotcha The package requires `solc` as a peer dependency; not installing it leads to runtime errors.
fix Run `npm install solc` in your project before using embark-solidity.
npm install embark-solidity
yarn add embark-solidity
pnpm add embark-solidity

Shows how to compile a Solidity contract using CompileCommand with version and optimizer settings.

import { CompileCommand } from 'embark-solidity';

const compiler = new CompileCommand({
  contracts: ['MyContract.sol'],
  solcVersion: '0.8.0',
  optimizer: { enabled: true, runs: 200 },
  outputDir: './build/contracts'
});

compiler.compile().then(result => {
  console.log(result.contracts['MyContract.sol']['MyContract'].abi);
}).catch(err => {
  console.error('Compilation failed:', err);
});