0

I read the solc document and followed the instruction.
When I am using solc@0.4.24 version, compile command is working fine

solc.compile(smartContractPath, 1);

When I switched to solc@0.5.0 version, compile command throwing error

(function (exports, require, module, __filename, __dirname) { var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath"normalize";var ret=nodeFS"readFileSync";i

AssertionError [ERR_ASSERTION]: Invalid callback specified.

In the solc documentation it is not mentioned about the changes in compile command.
Please tell how to use .compile function in solc@0.5.0 version.

  • Further down the documentation states: Starting from version 0.5.0, compile, compileStandard and compileStandardWrapper all do the same thing - what compileStandardWrapper used to do. There's some help how to use the new syntax here stackoverflow.com/a/49709550. – Ismael Nov 30 '18 at 5:27
  • Yes, and below that it is also mentioned that compileStandard and compileStandardWrapper will be deprecated. Then only compile is remained there. In the error: it is giving error of invalid callback specified. May be in 0.5 callback is introduced in compile function but it is not mentioned in document – Shubham Chadokar Nov 30 '18 at 5:41
  • compile in v0.5 expect a json string and output a json string. The format of the input is in solidity documentation. In the stackoverflow answer is the input equivalent to v0.4.xx behavior. – Ismael Nov 30 '18 at 5:48
1

At first, I also tried your method to compile and got the same error.
Finaly, I found a workable method in the official doc.

I tried it with solc@0.5.0. It's OK.

let contractSource = fs.readFileSync(contractPath, 'utf-8');
//console.log("contract content: \n" + contractSource);

let jsonContractSource = JSON.stringify({
    language: 'Solidity',
    sources: {
      'Task': {
          content: contractSource,
       },
    },
    settings: { 
        outputSelection: {
            '*': {
                '*': ['abi',"evm.bytecode"],   
             // here point out the output of the compiled result
            },
        },
    },
});

let solcResult = solc.compile(jsonContractSource);  

You can see the output format of the compile in this link.

https://solidity.readthedocs.io/en/develop/using-the-compiler.html#compiler-input-and-output-json-description

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.