2
const path=require('path');
const fs=require('fs');
const solc=require('solc');
const InboxPath=path.resolve(__dirname,'contracts','Inbox.sol');
const source=fs.readFileSync(InboxPath,'utf8');
solc.compile(source,1);

Here is my error:

kowsik@kowsik:~/Desktop/etherium_project$ node compile.js
assert.js:43
  throw new errors.AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: Invalid callback specified.
    at wrapCallback (/home/kowsik/Desktop/etherium_project/node_modules/solc/wrapper.js:16:5)
    at runWithReadCallback (/home/kowsik/Desktop/etherium_project/node_modules/solc/wrapper.js:42:26)
    at compileStandard (/home/kowsik/Desktop/etherium_project/node_modules/solc/wrapper.js:83:14)
    at Object.compileStandardWrapper (/home/kowsik/Desktop/etherium_project/node_modules/solc/wrapper.js:90:14)
    at Object.<anonymous> (/home/kowsik/Desktop/etherium_project/compile.js:7:6)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
Ismael
  • 30,570
  • 21
  • 53
  • 96

2 Answers2

1

If you are using new version of solidity (currently mine is 0.6.1): Then the below code should work for you!

Here simply data format is changes as the format you are using is not supported in newer version soo we defined the datatype for o/p and convert json data to string.

 module.exports = solc.compile(
  JSON.stringify({
    language: "Solidity",
    sources: {
      "lottery.sol": {
        content: source
      }
    },
    settings: {
      outputSelection: {
        "*": {
          "*": ["evm", "bytecode"]
        }
      }
    }
  })
);
Redmen Ishab
  • 125
  • 5
0

Use an older solc version for example "solc": "^0.4.25"

Lomo
  • 103
  • 1
  • 7