0

This is the first contract with this Udemy course.

Trying to compile by running: "node compile.js" but get the following error:

iii@iii:~/inbox$ node compile.js 

assert.js:350 
throw err; ^ 

AssertionError [ERR_ASSERTION]: Invalid callback object specified. 
at runWithCallbacks (/home/iii/Digital Ledger/inbox/node_modules/solc/wrapper.js:97:7) 
at compileStandard (/home/iii/Digital Ledger/inbox/node_modules/solc/wrapper.js:207:14) 
at Object.compileStandardWrapper [as compile] (/home/iii/Digital Ledger/inbox/node_modules/solc/wrapper.js:214:14) 
at Object.<anonymous> (/home/iii/Digital Ledger/inbox/compile.js:9:6) 
at Module._compile (internal/modules/cjs/loader.js:689:30) 
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) 
at Module.load (internal/modules/cjs/loader.js:599:32) 
at tryModuleLoad (internal/modules/cjs/loader.js:538:12) 
at Function.Module._load (internal/modules/cjs/loader.js:530:3) 
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)

This is my "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, 'utf8');

module.exports = solc.compile(source, 1);

And the simple contract:

pragma solidity ^0.4.17;

contract Inbox {
    string public message;

    function Inbox(string iniMess) public {
        message = iniMess;
    }

    function setMess(string newMess) public {
        message = newMess;
    }
} 

And this is the file structure:

-inbox
    -node_modules
    -contracts
        -inbox.sol
        -package.json
        -package-lock.json
    -compile.js

Thank you for any help :)

  • 1
    You should ask for a refund. The version used in the example solc 0.4.17 was released 3 years ago. Every serious development is with solc 0.5, and new project started to use 0.6. – Ismael Apr 29 at 19:26
2

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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