Home > Mobile >  node:assert:400 throw err; ^ AssertionError [ERR_ASSERTION]: Invalid callback object specified
node:assert:400 throw err; ^ AssertionError [ERR_ASSERTION]: Invalid callback object specified

Time:11-13

trying to run node compile.js but it thrwing me the above mentioned error and idea wahat wrong i am doing enter image description here

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"
  }
}

i am beginner to this technology, so thank you for your time

CodePudding user response:

Just add memory after both string which are present in function's parameters.

function Inbox(string memory initialMessage)... AND function setMessage(string memory newMessage)...

CodePudding user response:

That course is outdated, solidity version 0.6.6 is released and you better update your code to that version. if you are not a good programmer you better refund that course, cause you will encounter many problems later on, you will see some errors using meta mask and Web3. that course teachs you a lot, so i really recommend you to keep learning that course and update yourself throughout the course. this is the first problem and the solution to the updated version is this.

this will be your "inbox.sol" code:

pragma solidity ^0.6.6;

contract Inbox{
string public message;

constructor (string memory initialMessage) public{
    message = initialMessage;
}

function setMessage(string memory newMessage) public{
    message = newMessage;
}
}

and this will be your "compile.js" code:

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)));

exports.abi = output.contracts['Inbox.sol']['Inbox'].abi;
exports.bytecode = output.contracts['Inbox.sol'] ['Inbox'].evm.bytecode.object;

in the new solidity the compiler will give you another version of compiled code compared to old compiler, so you'll need to pass the json file to your compiler and in order to access to abi(interface) and bytecode you need to do like i did in here.

  • Related