我试图在Enthereum网络上运行我的第一个HelloWorld智能合约。这是我的HelloWorld.sol合同。
pragma solidity ^ 0.5.0;
合约HelloWorld { bytes32消息; 构造函数(…
问题是,你我不能把原始的可靠性智能合约纳入其中 solc.compile() 功能。必须有 Compiler Standard Input JSON 。基于我的 另一个线程 我发现这个解决方案:
solc.compile()
Compiler Standard Input JSON
> var Web3 = require('web3'); > var solc = require('solc'); > var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); > var CONTRACT_FILE = 'HelloWorld.sol' > var content =fs.readFileSync(CONTRACT_FILE).toString() > var input = { language: 'Solidity', sources: { [CONTRACT_FILE]: { content: content } }, settings: { outputSelection: { '*': { '*': ['*'] } } } } > var compiled = solc.compile(JSON.stringify(input)) > var output = JSON.parse(compiled) > var abi = output.contracts[CONTRACT_FILE]['HelloWorld'].abi > var bytecode = output.contracts[CONTRACT_FILE]['HelloWorld'].evm.bytecode.object > var HelloWorld = new web3.eth.Contract(abi); > var HelloWorldTx = HelloWorld.deploy({data: bytecode, arguments: [web3.utils.asciiToHex('Hello')]}); > web3.eth.estimateGas(HelloWorldTx).then(console.log); //this does not work, because it can not connect to the localhost:8545. I don't know why. > HelloWorldTx.send({from: '0x99d54a45f2cd3b9c6443d623003416aaf944338e', gas: 1000000}).then(console.log);