Well, here we are once again.. It seems like there is literally NO docs for the usage of the Solidity compiler in Node.js.. Here is my question.
Context : I want to load a specific version of the Solidity compiler in my Node.js program. In order to do so, I installed the Solidity compiler through npm install solc . Then in my code I declared the solc variable, as follows : var solc = require('solc'). Until there no problem whatsoever.
Problem #1 : solc.loadRemoteVersion(version,callback) seems not to work correctly since this call instantly throw the following error: Error retrieving binaries: not found. Even tho this function is supposed to reach a remote folder on GitHub where all (or almost all) versions of the solidity compiler are stored it seems like it's not even trying to fetch the remote versions (it should at least look take some time before failing miserably)
Problem #2 : solc.useVersion(version) throw another error, more interesting in this case: solc.useVersion() is not a function. This call should go under the folder node_modules/solc/bin/solcjs-version.js and look for the desired version of the compiler but insted it decided to completely not work,
Any help is appriciated. I'm literally stuck on this since two days ago.
CodePudding user response:
The package looks for the full version string, including the commit ID - not just the version number. See the wrapper.ts source.
You can find the specific full version strings in list.json that is mentioned in the docs.
And here is a working example:
solc.loadRemoteVersion("v0.8.0 commit.c7dfd78e", (err, solcSnapshot) => {
// prints: 0.8.0 commit.c7dfd78e.Emscripten.clang
console.log(solcSnapshot.version());
});