Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
Solidity TypeError in lottery contract

I'm writing a simple Lottery contract in Solidity, and in the last line I get this error:

TypeError: Return argument type address payable[] storage ref is not
implicitly convertible to expected type (type of first return
variable) address[] memory.
contracts/Lottery.sol:40:16: return players;
                                    ^^^^^^^

I'm compiling on 8.7 with this code:

    //SPDX-License-Identifier: GPL-3.0
    
pragma solidity >=0.4.17 <0.9.0;
//pragma solidity ^0.4.17;
    
contract Lottery {
    address public manager;
    address payable[] public players;

    constructor() {
        manager = msg.sender; 
    }

    function enter() public restricted payable {
        require(msg.value >= .01 ether);    //min. amount to enter the lottery is 0.01 ether in wei
        players.push(payable(msg.sender));
    }
    
    function random() private view restricted returns(uint) {  //picking random number, we use block difficulty, current block time and amount of players to hash with sha3 algorithm
        return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp , players)));          //keccak256 == sha3
    
    }

    function pickWinner() public {
        require(msg.sender == manager);             //only manager can pick winner
            
        uint index = random() % players.length;     //pick winner by using random number and % modulo from it, as player in array
                                                        //players[index].transfer(this.balance);
        players[index].transfer(address(this).balance);                 //player with index number in players array is winner, return address
                                                                        //transfer(amount of lottery reward);
        players = new address payable[](0);        //reseting lottery; '0' means size of dynamic array
    }
    
    modifier restricted() {                 //modifier for repeated functions
        require(msg.sender == manager);
        _;              // _ means run the rest of the code inside this function
    }
    
    function getPlayers() public view returns(address[] memory) {
        return players; 
    }
    
}

What is wrong? Thanks for help!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You must only change return type into getPlayers() function signature instead:

function getPlayers() public view returns(address[] memory) {
    ...
}

change it with this:

function getPlayers() public view returns(address payable[] memory) {
        ...
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!