TransWikia.com

Trying to compile running: 'node compile.js', but get error: "assert.js:350 throw err;" [Udemy 'Complete Developers Guide' Course]

Ethereum Asked by Benzle on December 23, 2021

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 🙂

4 Answers

if you are getting Solidity "AssertionError [ERR_ASSERTION]" then more than likely have installed an unsupported version of solc.

Therefore, it would be important to write this depending on your solidity version!

npm uninstall solc
rm -r node_modules
rm package-lock.json
npm install
npm install [email protected]

Then try for the last time

node compile.js

This had resolved my problem!

Answered by rsc05 on December 23, 2021

@Anurag's answer is correct. You just need to check your versions and please be advised that the version of some libraries in that course are outdated. One big example is 'web3'. The instructor will tell you to install a specific version but you must install the latest version using the command

npm install --save web3

Apart from this, the truffle-hdwallet-provider is also deprecated. So make sure to install the latest one, which I believe is @truffle/hdwallet-provider (the latest version will work perfectly with the course and you will just have to do some minor tweaking into the deploy script.

I have done that course and I can confidently say that it is an amazing course. You will be lost into the wild world of blockchain if you didnt have such good reference material.

Answered by blueTron13 on December 23, 2021

I got into same issue. Check which solc version are you using. Or else follow these steps

npm uninstall solc
npm i --save [email protected]
node delpoy.js

Answered by Anurag Aravind Gharat on December 23, 2021

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.

Answered by Masoud jt on December 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP