3

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 Answers 2

3

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.

0

For anyone else coming across this issue now, since solidity v0.8.0 you also need to declare msg.sender as payable:

manager = payable(msg.sender)

or

players.push(payable(msg.sender));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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