'Problem while compiling smart contract in VScode ( No response in temrinal )
I have a problem while compiling my first smart contract:
in Inbox.sol
pragma solidity ^0.8.9;
contract Inbox {
string public message;
function myInbox(string memory initialMessage) public {
message = initialMessage;
}
function setMessage(string memory newMessage) public {
message = newMessage;
}
function getMessage() public view returns (string memory) {
return message;
}
}
In 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");
let input = {
language: "Solidity",
sources: {
[inboxPath]: {
content: source,
},
},
settings: {
outputSelection: {
"*": {
"*": ["*"],
},
},
},
};
var output = JSON.parse(solc.compile(JSON.stringify(input)));
module.exports = {
abi: output.contracts[[inboxPath]]["Inbox"].abi,
bytecode: output.contracts[[inboxPath]]["Inbox"].evm.bytecode.object,
};
My package.json
{
"name": "inbox",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "Zahraa",
"license": "ISC",
"dependencies": {
"@truffle/hdwallet-provider": "^2.0.6",
"ganache-cli": "^6.12.2",
"mocha": "^9.1.2",
"solc": "^0.8.9",
"web3": "^1.6.0"
},
"directories": {
"test": "test"
},
"keywords": [],
"description": ""
}
when I type ( node compile.js ) in terminal nothing happens (No bytecode returned)
Output in terminal:
macbookpro@macs-MBP-2 inbox % node compile.js
macbookpro@macs-MBP-2 inbox %
My questions:
How can I compile the file knowing that I used the same compiler version as pragma solidity (0.8.9) ?
Is remix.ethereum.org same as Visual Code Studio to create dApps?
Thank you..
Solution 1:[1]
One thing that helped me was making sure the inbox.sol and compile.js file were saved before i ran node compile.js. However the bytecode and other data isn't displayed. Just this
{
contracts: {},
sourceList: [ '' ],
sources: { '': { AST: [Object] } }
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | FilipDjo |