1

I'm trying to add the manager address to the playes array. I get the following error:

TypeError: Member "push" not found or not visible after argument-dependent lookup in address payable[] storage ref.

This is my code:

pragma solidity ^0.7.1;

contract Lottery{
    address public manager;
    uint public value;
    address payable[] private players;
    
    constructor() payable {
            manager = msg.sender;
            value = msg.value;
    }
    
    function enter() public payable {
            require(value > 0.01 ether);
            players.push(manager);
    }
    
    function random() private view returns (uint){
            return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, players)));
    }
    
    function pickWinner() public{
            uint index = random() % players.length;
            players[index].transfer(address(this).balance);
    }
}

Any ideas? Thanks!

2

You're trying to push a non-payable address to the array: manager is not payable. You'll need to change the type of manager to address payable:

address payable public manager;

function enter() public payable {
  require(value > 0.01 ether);
  players.push(manager);
}

Simply adding msg.sender (e.g. players.push(msg.sender)) to the array will work fine, since it's already payable.

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.