Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda