Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In the statement players.push(msg.sender); I am getting following error:

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

Thus I cannot push to address payable array in solidity. What's the workaround here?

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0;

contract Lottery {
    address public manager;
    address payable[] public players;

    constructor() {
        manager = msg.sender;
    }

    function enter() public payable {
        players.push(msg.sender);            // ERROR IN THIS LINE
    }
}
like image 464
Ayan Avatar asked Mar 25 '21 12:03

Ayan


1 Answers

If you're compiling with Solidity 0.7, everything works fine.

This error shows in Solidity 0.8, and it's because in 0.8 msg.sender is not automatically payable anymore. So you need to make it payable first:

players.push(payable(msg.sender));
like image 169
Petr Hejda Avatar answered Oct 12 '22 14:10

Petr Hejda