0

I have an ERC721 project using pragma solidity ^0.8.2. It drags in several open zeppelin imports that specify 0.8.0. It compiles in Remix with no errors or warnings and I am able to call the contract methods and get good results.

Then I go to the command line and try to compile the same contract; the compile.js begins with

const path = require("path");
const solc = require("solc");
const fs   = require("fs"); 

const remitanoPath = path.resolve(__dirname, "contracts", "remitanoNFT.sol");
const source = fs.readFileSync(remitanoPath, "utf8");

console.log("source = ", source.length);

const compiledFile = solc.compile(source, 1);

The compilation always fails at the same place, without ever doing anything with the file:

node:assert:412
    throw err;
    ^

AssertionError [ERR_ASSERTION]: Invalid callback object specified.
    at runWithCallbacks (D:\Development\Solidity\RemitanoNFT\node_modules\solc\wrapper.js:97:7)
    at compileStandard (D:\Development\Solidity\RemitanoNFT\node_modules\solc\wrapper.js:207:14)
    at Object.compileStandardWrapper [as compile] (D:\Development\Solidity\RemitanoNFT\node_modules\solc\wrapper.js:214:
14)
    at Object.<anonymous> (D:\Development\Solidity\RemitanoNFT\compile.js:10:27)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Module.load (node:internal/modules/cjs/loader:989:32)
    at Function.Module._load (node:internal/modules/cjs/loader:829:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='

I've looked at the solc code and it appears to be early in the solc initialization. I have seen many references to this exact same assertion but they are years old, which is eons in the solidity world, and most suggest rolling back to an earlier version of solc, which I can't do because the imported open zeppelin modules code for solc 0.8.0.

I have tried pasting in the zeppelin code and going back to an earlier solc but it still throws assertions.

I remember when releasing breaking changes was a disciplinary offense or even a termination. Now it seems to have become the standard.

1
  • It seems you are using the old syntax to invoke solc.
    – Ismael
    Jan 1, 2022 at 21:50

1 Answer 1

0

You use of solc.compile is not correct. The second parameter is supposed to be a callback, therefore passing 1 is considered invalid and throws an error.

A working example is available in the official solc-js GitHub Readme

Note to the breaking changes: Solidity is following semantic versioning.

Major version zero (0.y.z) is for initial development. Anything MAY change at any time. The public API SHOULD NOT be considered stable.

The Solidity developers put great work in communicating breaking changes and keeping them to a minimum, but to evolve the language for the future into a stable version breaking changes will be required.

1
  • They can give it a new name as COM gave changed binaries a new GUID.
    – Chris Fox
    Jan 1, 2022 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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