[英]Problem while compiling smart contract in VScode ( No response in temrinal )
我在編譯我的第一個智能合約時遇到了問題:
在收件箱.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;
}
}
在 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,
};
我的 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": ""
}
當我在終端中鍵入( node compile.js )時,什么也沒有發生(沒有返回字節碼)
終端輸出:
macbookpro@macs-MBP-2 inbox % node compile.js
macbookpro@macs-MBP-2 inbox %
我的問題:
知道我使用與 pragma solidity (0.8.9) 相同的編譯器版本,我如何編譯該文件?
remix.ethereum.org 是否與 Visual Code Studio 相同來創建 dApp?
謝謝..
幫助我的一件事是確保在我運行 node compile.js 之前保存了 inbox.sol 和 compile.js 文件。 但是不顯示字節碼和其他數據。 只是這個
{
contracts: {},
sourceList: [ '' ],
sources: { '': { AST: [Object] } }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.