How to use the solc.compile function in solc

To help you get started, we’ve selected a few solc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rsksmart / utilities / tests / lib / contracts.js View on Github external
function compileContract(name, filename) {
    console.log('compiling contract', name);
    var input = fs.readFileSync(filename).toString();
    var sources = {};
    sources[filename] = input;
    var output = solc.compile({ sources: sources }, 1, findImports); // 1 activates the optimiser

    return output.contracts[name];
}
github ethfinex / efx-api-node / test / helpers / compile.js View on Github external
const compile = async (filename) => {
  filename = filename.replace('.sol', '')

  const filePath = path.join(CONTRACTS_PATH, filename + '.sol')
  const source = fs.readFileSync(filePath, 'utf-8')

  // grabs the contract reference
  const compiled = solc.compile(source, 1)

  const contract = compiled.contracts[':' + filename]

  if (contract) {
    console.log('  OK!')
  }

  if (compiled.errors) {
    if (contract) {
      console.log('warnings:')
    } else {
      console.log('errors:')
    }

    console.log(compiled.errors)
  }
github trufflesuite / truffle-artifactor / test / contracts.js View on Github external
before(function(done) {
    this.timeout(10000);

    // Compile first
    var result = solc.compile(fs.readFileSync("./test/Example.sol", {encoding: "utf8"}), 1);

    // Clean up after solidity. Only remove solidity's listener,
    // which happens to be the first.
    process.removeListener("uncaughtException", process.listeners("uncaughtException")[0]);

    var compiled = Schema.normalize(result.contracts["Example"]);
    abi = compiled.abi;
    binary = compiled.bytecode;

    // Setup
    var dirPath = temp.mkdirSync({
      dir: path.resolve("./"),
      prefix: 'tmp-test-contract-'
    });

    var expected_filepath = path.join(dirPath, "Example.json");
github BANKEX / solidity-float-point-calculation / compile.js View on Github external
async function main() {
  console.log("Compiling contracts...");
  var inputs = {}; 
    for (contract of Contracts){
      var parts = contract.split(':');
      inputs[contract+'.sol'] =  fs.readFileSync("./contracts/"+parts[0]+".sol", 'utf8');
    }
    try{ 
      var output = solc.compile({ sources: inputs }, 1, findImports)
    }
    catch(error){
      console.log(error);
    }
    for (err in output.errors){
      console.log(output.errors[err]);
    }
    if (!output.contracts || Object.keys(output.contracts).length == 0){
      throw("Didn't compile");
    }
    // new RegExp('__([a-zA-Z.:]+)[_]*', 'g');
    // const libraryRE = /__([a-zA-Z.:]+)[_]*/g.compile();
    const libraryRE = new RegExp('__([a-zA-Z.:]+)[_]*', 'g');
    for (var property in output.contracts) {
      if (output.contracts.hasOwnProperty(property)) {
        var contract = output.contracts[property];
github zapproject / zap-nodejs-api / src / oldapi / market / marketDeploy.js View on Github external
function compileContracts(source_files) {
    // Load the inputs
    const sources = {};

    for ( const file of source_files ) {
        sources[file] = fs.readFileSync(file).toString();
    }
    
    // Compile the input
    const output = solc.compile({
        sources: sources
    }, 1);
    console.log(23423,output);
    const result = {};

    // Parse all compiled contracts
    for ( const k in  output.contracts ) {
        // Find which contract was compiled
        const contractKey = k.split(':').pop();
        const contract = output.contracts[k];

        // Get the bytecode and ABI
        const bytecode = contract.bytecode;
        const abi = JSON.parse(contract.interface);

        result[contractKey] = {
github chuckfairy / ether-sheet-music / bin / build.js View on Github external
const MAIN_ADDRESS = web.eth.accounts[ 0 ];
//web.personal.unlockAccount( MAIN_ADDRESS, "" );

//console.log( MAIN_ADDRESS, web.eth.getBalance( MAIN_ADDRESS ).toNumber() );


//Code

const GAME_SOL = __dirname + "/../contracts/sheet-music.sol";

const GAME_CODE = FS.readFileSync( GAME_SOL ).toString();


//Main

var compiled = Solc.compile( GAME_CODE );

if( compiled.errors ) {

    console.log( "ERRORS/WARNINGS:" );
    console.log( compiled.errors );

}

if( compiled.contracts[ ":SheetMusic" ] ) {

    compile( compiled.contracts[ ":SheetMusic" ], "sheet-music" );

} else {

    throw new Error( "Failed to compile" );
github kumavis / eth-adventure / templates / sol.js View on Github external
var solc = require('solc')
module.exports = solc.compile(`

  contract MyContract {

  }

`)
github ProofSuite / togen-cli / lib / compiler.js View on Github external
_compileAndClean(filePath) {
    try {
      let source = fs.readFileSync(filePath, { encoding: 'utf8' })
      let compiled = solc.compile(source, 1)

      if (compiled.errors) return [compiled.errors, null]

      let contractName = getContractName(filePath)
      let cleaned = this._clean(compiled, contractName)
      return [null, cleaned]
    }

    catch(e) {
      throw(e)
    }
  }
github KyberNetwork / smart-contracts / scripts / feeHandler.js View on Github external
async function getAbis() {
    const output = await solc.compile({ sources: input }, 1);
    erc20Abi = output.contracts["ERC20Interface.sol:ERC20"].interface;
    networkAbi = output.contracts["KyberNetwork.sol:KyberNetwork"].interface;
    feeBurnerAbi = output.contracts["FeeBurner.sol:FeeBurner"].interface;
    feeBurnerWrapperAbi = output.contracts["WrapFeeBurner.sol:WrapFeeBurner"].interface;
}
github validitylabs / hopr / src / utils / index.js View on Github external
const input = {
            language: 'Solidity',
            sources: srcObject,
            settings: {
                optimizer: {
                    enabled: true,
                    runs: 200
                },
                outputSelection: {
                    '*': {
                        '*': ['*']
                    }
                }
            }
        }
        const compiledContracts = JSON.parse(solc.compile(JSON.stringify(input), findImports))

        if (compiledContracts.errors) throw compiledContracts.errors.map(err => err.formattedMessage).join('\n')

        this.createDirectoryIfNotExists('build/contracts')

        await Promise.all(
            Object.entries(compiledContracts.contracts).map(array =>
                Promise.all(
                    Object.entries(array[1]).map(([contractName, jsonObject]) =>
                        fsPromise.writeFile(`${process.cwd()}/build/contracts/${contractName}.json`, JSON.stringify(jsonObject, null, '\t'))
                    )
                )
            )
        )
    }