I'm trying to run node compile.js but it's throwing me this error and idea what I am doing wrong:
node:assert:400 throw err; ^ AssertionError [ERR_ASSERTION]: Invalid callback object specified
my inbox.sol
pragma solidity ^0.8.9;
contract Inbox{
string public message;
function Inbox(string intialMessage) public {
message = intialMessage;
}
function setMessage(string newMessage) public {
message = newMessage;
}
}
my package.json
{
"dependencies": {
"ganache-cli": "^6.12.2",
"mocha": "^9.1.3",
"solc": "^0.8.9",
"web3": "^1.6.0"
}
}
Just rewrite your code like this in 'compile.js'.This work fine even in 0.8.0 version of solidity
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, 'UTF-8');
var input = {
language: 'Solidity',
sources: {
'Inbox.sol' : {
content: source
}
},
settings: {
outputSelection: {
'*': {
'*': [ '*' ]
}
}
}
};
var output = JSON.parse(solc.compile(JSON.stringify(input)));
// console.log(output.contracts['Inbox.sol']['Inbox']);
// exports.abi = output.contracts['Inbox.sol']['Inbox'].abi;
// exports.bytecode = output.contracts['Inbox.sol']['Inbox'].evm.bytecode.object;