I am a newbie and have just started building contracts. I am getting this error for this contract. Kindly help in solving thisenter image description here


For 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'];

For 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);
    function random() private view returns (uint){
        return uint(keccak256(block.difficulty, now, players));
    function pickWinner() public restricted{
        uint index = random() % players.length;
        players = new address[](0);
    modifier restricted(){
        require(msg.sender == manager);
    function getPlayers() public view returns (address[] memory){
        return players;
  • Are we supposed to guess what your code looks like????? Sep 21 '20 at 20:35
  • BTW, your question says "during deployment", but the screenshot shows "npm run test", which is a different thing, so please get your stuff straight together! Sep 21 '20 at 20:37
  • Do migrations run?
    – Ismael
    Sep 22 '20 at 2:14
  • I am sorry... I am a newbie, And I have just added my code. Thanks for pointing out the mistake Sep 22 '20 at 4:40

Had the same issue, try this:

Instead of:

module.exports = solc.compile(source, 1).contracts[‘:Lottery’];

Do this:

compiledContracts = solc.compile(source, 1).contracts;
extractedLottery = compiledCon[:Lottery];
module.exports = extractedLottery;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.