Skip to main content

This is a contract I made when the latest version of solidity was 0.4.0, it was working then, but now it shows error in the remixRemix, so I updated it to 0.5.0. now Now it shows errors in the transfer function and keccak256 function.

The errors are:

Typeerror: member balance not found or not visible argument-dependent lookup in contractLottery. Use "address(this).balance" to access this address member.players[index].transfer(this.balance);
 

TypeError: Wrong argument count for function call: 3 arguments given but 
expected 1. This function requires a single bytes argument. Use 
abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) 
to use ABI encoding.
return uint(keccak256(block.difficulty,now,players));

CONTRACT

pragma solidity ^0.5.0;

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

    constructor() public {
manager=msg        manager = msg.sender;
    } 

    function enter() public payable {
        require(msg.value > .01 ether);
        players.push(msg.sender);
    }

    function random() private view returns(uint) {
        return uint(keccak256(block.difficulty, now, players));
    }

    function winner() public restricted {
        uint index=randomindex = random() % players.length;
        players[index].transfer(this.balance);
 players=new       players = new address[](0);
    }
 

    function allplayers() public {
        return players;
    }

    modifier restricted() {
        require(msg.sender==managersender == manager);
        _;
    }
}

This is a contract I made when the latest version of solidity was 0.4.0, it was working then, but now it shows error in the remix, so I updated it to 0.5.0. now it shows errors in the transfer function and keccak256 function.

errors are:

Typeerror: member balance not found or not visible argument-dependent lookup in contractLottery. Use "address(this).balance" to access this address member.players[index].transfer(this.balance);
 

TypeError: Wrong argument count for function call: 3 arguments given but 
expected 1. This function requires a single bytes argument. Use 
abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) 
to use ABI encoding.
return uint(keccak256(block.difficulty,now,players));

CONTRACT

pragma solidity ^0.5.0;

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

constructor() public{
manager=msg.sender;
}
function enter() public payable{
require(msg.value > .01 ether);
players.push(msg.sender);
}

function random() private view returns(uint){
return uint(keccak256(block.difficulty,now,players));
}

function winner() public restricted {
uint index=random() % players.length;
 players[index].transfer(this.balance);
 players=new address[](0);
}
 

function allplayers() public {
return players;
 }

 modifier restricted(){
 require(msg.sender==manager);
 _;
}
}

This is a contract I made when the latest version of solidity was 0.4.0, it was working then, but now it shows error in Remix, so I updated it to 0.5.0. Now it shows errors in the transfer function and keccak256 function.

The errors are:

Typeerror: member balance not found or not visible argument-dependent lookup in contractLottery. Use "address(this).balance" to access this address member.players[index].transfer(this.balance);

TypeError: Wrong argument count for function call: 3 arguments given but 
expected 1. This function requires a single bytes argument. Use 
abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) 
to use ABI encoding.
return uint(keccak256(block.difficulty,now,players));

CONTRACT

pragma solidity ^0.5.0;

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

    constructor() public {
        manager = msg.sender;
    } 

    function enter() public payable {
        require(msg.value > .01 ether);
        players.push(msg.sender);
    }

    function random() private view returns(uint) {
        return uint(keccak256(block.difficulty, now, players));
    }

    function winner() public restricted {
        uint index = random() % players.length;
        players[index].transfer(this.balance);
        players = new address[](0);
    }

    function allplayers() public {
        return players;
    }

    modifier restricted() {
        require(msg.sender == manager);
        _;
    }
}
Source Link

version compatibility issues in solidity 0.5.0 and 0.4.0

This is a contract I made when the latest version of solidity was 0.4.0, it was working then, but now it shows error in the remix, so I updated it to 0.5.0. now it shows errors in the transfer function and keccak256 function.

errors are:

Typeerror: member balance not found or not visible argument-dependent lookup in contractLottery. Use "address(this).balance" to access this address member.players[index].transfer(this.balance);


TypeError: Wrong argument count for function call: 3 arguments given but 
expected 1. This function requires a single bytes argument. Use 
abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) 
to use ABI encoding.
return uint(keccak256(block.difficulty,now,players));

CONTRACT

pragma solidity ^0.5.0;

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


constructor() public{
manager=msg.sender;
}
function enter() public payable{
require(msg.value > .01 ether);
players.push(msg.sender);
}

function random() private view returns(uint){
return uint(keccak256(block.difficulty,now,players));
}

function winner() public restricted {
uint index=random() % players.length;
 players[index].transfer(this.balance);
 players=new address[](0);
}


function allplayers() public {
return players;
 }

 modifier restricted(){
 require(msg.sender==manager);
 _;
}
}