Skip to main content
logo

solc

nest badge

⚠️ Highly experimental!

Solidity bindings for Deno, based on solc-js.

Solidity 0.7+ is supported.

Docs

See solc-js README.

Example

import { download } from 'https://deno.land/x/solc/download.ts'
import { setupMethods } from 'https://deno.land/x/solc/wrapper.ts'
import 'https://deno.land/x/solc/process.ts'
import { createRequire } from 'https://deno.land/std@0.108.0/node/module.ts'
import { exists } from 'https://deno.land/x/solc/utils.ts'

if (!(await exists('./soljson.js'))) download('./soljson.js')

const require = createRequire(import.meta.url)

const solc = setupMethods(require('./soljson.js'))

const input = {
  language: 'Solidity',
  sources: {
    'test.sol': {
      content: 'contract C { function f() public { } }'
    }
  },
  settings: {
    outputSelection: {
      '*': {
        '*': ['*']
      }
    }
  }
}

const result = JSON.parse(solc.compile(JSON.stringify(input)))

const { contracts } = result

// `output` here contains the JSON output as specified in the documentation
for (const contractName in contracts['test.sol']) {
  console.log(`${contractName}: ${contracts['test.sol'][contractName].evm.bytecode.object}`)
}

And then run with

deno run -A --unstable --no-check mod.js

See example for a more advanced example.