question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

loadRemoteVersion in solc-js 0.5.0 returns corrupted compiler

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
axiccommented, Dec 3, 2018

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: {
      "*": {
        "*": [ "*" ]
      }
    }
  }
}
0reactions
daniyarchambylovcommented, Dec 3, 2018

@axic

Tried this as you suggested:

solc.loadRemoteVersion('v0.4.22+commit.4cb486ee', function (err, solcSnapshot) {
  let ret = solcSnapshot.compile(JSON.stringify({
    sources: {
      "contract.sol": "pragma solidity ^0.4.22; contract t { function g() {} }"
    }
  }), 1)
})

and got this

/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.
    at wrapCallback (/usr/src/app/node_modules/solc/wrapper.js:16:5)
    at runWithReadCallback (/usr/src/app/node_modules/solc/wrapper.js:37:42)
    at compileStandard (/usr/src/app/node_modules/solc/wrapper.js:72:14)
    at Object.compileStandardWrapper (/usr/src/app/node_modules/solc/wrapper.js:85:14)
    at /usr/src/app/index.js:103:35
    at IncomingMessage.<anonymous> (/usr/src/app/node_modules/solc/wrapper.js:242:13)
    at IncomingMessage.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1098:12)
    at process.internalTickCallback (internal/process/next_tick.js:72:19)

Could you please provide working example?

@ToJen Nope 😦 Still trying to figure things out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found