0

I have just started building contracts. Kindly help me in resolving this error. Attached image of error.enter image description here

Lottery/contract/Lottery.sol:

pragma solidity ^0.4.17; 


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;
    }
}

Lottery/test/lottery_test.js:

const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');

const web3 = new Web3(ganache.provider());

const {interface, bytecode} = require('../compile');

let lottery;
let account;

beforeEach(async()=> {
    account = await web3.eth.getAccounts();

    lottery = await new web3.eth.Contract(JSON.parse(interface))
        .deploy({data: bytecode})
        .send({from: accounts[0], gas: '1000000'});
});

describe('Lottery Contract',() => {
it('deploys a contract', () => {
    assert.ok(lottery.options.address);
    });
});

Lottery/compile.js:

const path = require('path');
const fs = require('fs');
const solc = require('solc');



const lotteryPath = path.resolve(__dirname, 'contract', 'Lottery.sol');
const source = fs.readFileSync(lotteryPath, 'utf-8');

module.exports = solc.compile(source,1).contracts[':Lottery'];
2
  • You declared 'account' and then used 'accounts' (plural). – clement Sep 27 '20 at 17:47
  • Thanks buddy! Thanks a lot – Siddharth Gargava Sep 27 '20 at 17:51

Your Answer

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

Browse other questions tagged or ask your own question.