Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda