Contract-Deployment
TypeError:無法讀取未定義的屬性“:Lottery.sol”。請幫助解決這個問題!
我是新手,剛剛開始建立契約。我收到此契約的此錯誤。請幫助解決這個問題
程式碼-
對於compile.js
const path = require('path'); const fs = require('fs'); const solc = require('solc'); const lotteryPath = path.resolve(__dirname, 'contracts', 'Lottery.sol'); const source = fs.readFileSync(lotteryPath, 'utf-8'); module.exports = solc.compile(source,1).contracts[':Lottery'];
彩票.sol
pragma solidity ^0.4.25; contract Lottery{ address public manager; address[] public players; function lottery() public{ manager = msg.sender; } function enter() public payable{ require(msg.value > 0.01 ether); players.push(msg.sender); } function random() private view returns (uint){ return uint(keccak256(block.difficulty, now, players)); } function pickWinner() public restricted{ uint index = random() % players.length; players[index].transfer(this.balance); players = new address[](0); } modifier restricted(){ require(msg.sender == manager); _; } function getPlayers() public view returns (address[] memory){ return players; } }
遇到同樣的問題,試試這個:
代替:
module.exports = solc.compile(source, 1).contracts[‘:Lottery’];
做這個:
compiledContracts = solc.compile(source, 1).contracts; extractedLottery = compiledCon[:Lottery]; module.exports = extractedLottery;