owanhunte / ethereum-solidity-course-updated-code

Up-to-date Solidity / web3.js / Node.js / React / Next.js code for the udemy.com course Ethereum and Solidity: The Complete Developer's Guide.
183 stars 82 forks source link

Getting 'TypeError: Cannot read property 'Inbox.sol' of undefined' when running compile.js on Inbox.sol #4

Closed razsa closed 1 year ago

razsa commented 4 years ago

{ "name": "inbox", "version": "1.0.0", "description": "", "main": "compile.js", "scripts": { "test": "" }, "author": "", "license": "ISC", "dependencies": { "solc": "^0.5.15" } }

Any ideas?

owanhunte commented 4 years ago

hi @razsa can you please show your Inbox.sol smart contract and your accompanying compile.js Node script?

razsa commented 4 years ago

Inbox.sol

pragma solidity >=0.5.0 <0.7.0;

contract Inbox {
    string public message;

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

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

compile.js

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

const input = {
    langauge: 'Solidity',
    sources: {
        'Inbox.sol' :{
            content: source
        }
    },
    settings: {
        outputSelection: {
            '*':{
                '*': ['*']
            }
        }
    }
};

const output = JSON.parse(solc.compile(JSON.stringify(input)));
module.exports = output.contracts['Inbox.sol'].Inbox;
owanhunte commented 4 years ago

ok so I see no difference between what you have above for your smart contract and node script compared to what's here and here respectively. Assuming that you specified a 0.5.x version of solc in your package.json (I specified ^0.5.15 in mine as shown here) then your smart contract should compile without error. Can you confirm the solc version requirement you have specified in your package.json?

owanhunte commented 1 year ago

Hi @razsa since you opened this issue, the Inbox smart contract has been updated to Solidity 0.8 and the compile and deploy scripts brought up-to-date with the latest versions of the Node.js libraries they are using. If possible, can you please test things with the code from the current state of this repo and let me know if you get any errors when running compile.js for the Inbox smart contract?

owanhunte commented 1 year ago

Since this issue has had no comments from it's author in well over 2 years now, I'll go ahead and close it due to inactivity.