ethereum-solidity-course-updated-code icon indicating copy to clipboard operation
ethereum-solidity-course-updated-code copied to clipboard

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

Open razsa opened this issue 5 years ago • 3 comments

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

Any ideas?

razsa avatar Jan 25 '20 09:01 razsa

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

owanhunte avatar Jan 28 '20 02:01 owanhunte

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;

razsa avatar Jan 28 '20 08:01 razsa

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 avatar Jan 30 '20 01:01 owanhunte

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 avatar Feb 22 '23 01:02 owanhunte

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.

owanhunte avatar Mar 25 '23 18:03 owanhunte