3

I'm trying to load another version of solc using the following code

var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
var solc = require('solc');
var fs = require('fs');
// getting a legacy version 
const input = fs.readFileSync('contracts/Token.sol').toString();

solc.loadRemoteVersion('0.4.4+commit.4633f3de.Darwin.appleclang', function(err, solcV044) {
    if (err) {
        // An error was encountered, display and quit
    }

    var output = solcV044.compile(input);
    console.log(output);
});

but am getting an error TypeError: solc.loadRemoteVersion is not a function and I am not understanding why, what am I missing?

EDIT: Not sure what this means but may help identify the issue. When I console.log(solc) I get back

{ version: [Function],
  compile: [Function: compile],
  useVersion: [Function: useVersion] }
/Users/mcansado/node_modules/solc/bin/soljson-latest.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
  • have you installed solcjs? npm install -g solc – Badr Bellaj Jul 19 '17 at 20:18
  • I have yes. solcjs --version returns 0.4.13+commit.0fb4cb1a.Emscripten.clang – mcansado Jul 19 '17 at 20:23
1

The reason is that the version parameter is not correct. How solc handles loadRemoteVersioncall can be found in yourwrap.js:

  loadRemoteVersion: function (versionString, cb) {
  var mem = new MemoryStream(null, {readable: false});
  var url = 'https://ethereum.github.io/solc-bin/bin/soljson-' + versionString + '.js';
  https.get(url, function (response) {
    if (response.statusCode !== 200) {
      cb('Error retrieving binary: ' + response.statusMessage);
    } else {
      response.pipe(mem);
      response.on('end', function () {
        cb(null, setupMethods(requireFromString(mem.toString(), 'soljson-' + versionString + '.js')));
      });
    }
  }).on('error', function (error) {
    cb(error);
  });
},

So, to answer your question first, your version should be 'v0.4.4+commit.4633f3de', if you replace your '0.4.4+commit.4633f3de.Darwin.appleclang' with this, everything should work out.

Now for future reference:

one quick way to find out is actually type in: "https://ethereum.github.io/solc-bin/bin/soljson-YOUR_VERSION_PARAMETER.js" and then see whether such resource exist (if it doesn't, you will see 404 not found error).

Of course, a better way is to find out all released solc version here: https://ethereum.github.io/solc-bin/bin/list.json

For the convenience for people who doesn't like hyperlink, here is a list of all solc:

"releases": {
"0.4.16": "soljson-v0.4.16+commit.d7661dd9.js",
"0.4.15": "soljson-v0.4.15+commit.bbb8e64f.js",
"0.4.14": "soljson-v0.4.14+commit.c2215d46.js",
"0.4.13": "soljson-v0.4.13+commit.fb4cb1a.js",
"0.4.12": "soljson-v0.4.12+commit.194ff033.js",
"0.4.11": "soljson-v0.4.11+commit.68ef5810.js",
"0.4.10": "soljson-v0.4.10+commit.f0d539ae.js",
"0.4.9": "soljson-v0.4.9+commit.364da425.js",
"0.4.8": "soljson-v0.4.8+commit.60cc1668.js",
"0.4.7": "soljson-v0.4.7+commit.822622cf.js",
"0.4.6": "soljson-v0.4.6+commit.2dabbdf0.js",
"0.4.5": "soljson-v0.4.5+commit.b318366e.js",
"0.4.4": "soljson-v0.4.4+commit.4633f3de.js",
"0.4.3": "soljson-v0.4.3+commit.2353da71.js",
"0.4.2": "soljson-v0.4.2+commit.af6afb04.js",
"0.4.1": "soljson-v0.4.1+commit.4fc6fc2c.js",
"0.4.0": "soljson-v0.4.0+commit.acd334c9.js",
"0.3.6": "soljson-v0.3.6+commit.3fc68da.js",
"0.3.5": "soljson-v0.3.5+commit.5f97274.js",
"0.3.4": "soljson-v0.3.4+commit.7dab890.js",
"0.3.3": "soljson-v0.3.3+commit.4dc1cb1.js",
"0.3.2": "soljson-v0.3.2+commit.81ae2a7.js",
"0.3.1": "soljson-v0.3.1+commit.c492d9b.js",
"0.3.0": "soljson-v0.3.0+commit.11d6736.js",
"0.2.2": "soljson-v0.2.2+commit.ef92f56.js",
"0.2.1": "soljson-v0.2.1+commit.91a6b35.js",
"0.2.0": "soljson-v0.2.0+commit.4dc2445.js",
"0.1.7": "soljson-v0.1.7+commit.b4e666c.js",
"0.1.6": "soljson-v0.1.6+commit.d41f8b7.js",
"0.1.5": "soljson-v0.1.5+commit.23865e3.js",
"0.1.4": "soljson-v0.1.4+commit.5f6c3cd.js",
"0.1.3": "soljson-v0.1.3+commit.28f561.js",
"0.1.2": "soljson-v0.1.2+commit.d0d36e3.js",
"0.1.1": "soljson-v0.1.1+commit.6ff4cd6.js"
},
 "latestRelease": "0.4.16"
}

Hope it helps! Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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