Chahat
Chahat

Reputation: 39

Solidity Error: member balance not found or not visible after argument-dependent lookup in contract

I'm getting this error in Solidity for the following code snippet:

member balance not found or not visible after argument-dependent lookup in contract

function pickWinner() public {
    uint index = random() % players.length;
    players[index].transfer(address(this).balance); // error here
}

What's the problem?

Upvotes: 0

Views: 614

Answers (1)

user16483582
user16483582

Reputation:

Is your players array payable? Your code works for me:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

contract PickWinner {
    address payable[] players;
    function pickWinner() public {
        uint256 winnerIndex = 80 % players.length; // I chose 80 as a "random" value
        players[winnerIndex].transfer(address(this).balance); 
    }
}

Upvotes: 1

Related Questions