solc-js: loadRemoteVersion in solc-js 0.5.0 returns corrupted compiler

I have solc-js 0.5.0 installed on my machine and need to use remote compiler version 0.4.22+commit.4cb486ee.Emscripten.clang

Here is the small snippet code I wrote:

solc.loadRemoteVersion(cleanedVersion, function(err, remoteSolc) {
      if (err) {
        return cb(err);
      }
      console.log('>>>>>>>>>>>>>>>>>>>>>>>>>', remoteSolc.semver())
      console.log(remoteSolc)
      const compiled = remoteSolc.compile(solfile, 1);
      return cb(null, compiled);
});

This is the output:

>>>>>>>>>>>>>>>>>>>>>>>>> 0.4.22+commit.4cb486ee.Emscripten.clang
{ version: [Function],
  semver: [Function: versionToSemver],
  license: [Function],
  lowlevel:
   { compileSingle: [Function],
     compileMulti: [Function],
     compileCallback: [Function: compileJSONCallback],
     compileStandard: [Function: compileStandard] },
  features:
   { legacySingleInput: true,
     multipleInputs: true,
     importCallback: true,
     nativeStandardJSON: true },
  compile: [Function: compileStandardWrapper],
  compileStandard: [Function: compileStandardWrapper],
  compileStandardWrapper: [Function: compileStandardWrapper],
  loadRemoteVersion: [Function: loadRemoteVersion],
  setupMethods: [Function: setupMethods] }
/usr/src/app/node_modules/solc/soljson.js:1
(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"](filename);var ret=nodeFS["readFileSync"](filename);if(!ret&&filename!

AssertionError [ERR_ASSERTION]: Invalid callback specified.

I installed compiler version 0.4.25 and everything works as expected

I looked at the code of wrapper.js both for 0.4.22 and 0.5.0 and it looks like method compile does not point to downloaded compiler version 0.4.22, in face it points to 0.5.0

wrapper.js for version 0.5.0 wrapper.js for version 0 4 22

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

Still not sure why you are passing 1? Documentation says that it takes a JSON and an optional import callback function. Just use compile(JSON.stringify({...})) as suggested in https://github.com/ethereum/solc-js/issues/302#issuecomment-443182849.

This is the documentation of “standard json”: https://solidity.readthedocs.io/en/v0.5.0/using-the-compiler.html#compiler-input-and-output-json-description

You need to pass as the bare minimum:

{
  language: "Solidity",
  sources: {
    "file.sol": {
      "content": "contract A {}"
    }
  },
  settings: {
    outputSelection: {
      "*": {
        "*": [ "*" ]
      }
    }
  }
}