How can I know what the error says if it is cut in the image

Jan 17, 2022, 7:06 PM
these are the new errors i get
Please help anybody
Jan 17, 2022, 7:13 PM
you don't know what you are doing
do you know solidity?
Jan 17, 2022, 7:17 PM
Why you use users[userAdresses[i]]? Send all the contract.
Jan 17, 2022, 7:18 PM
you are just typing random things from what I see
show me the struct
Jan 17, 2022, 7:18 PM
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
contract Lottery {
//struct used to store the user information
struct User {
address userAddress;
uint tokensBought;
uint[] guess;
}
// a list of the users
mapping (address => User) public users;
address[] public userAddresses;
address public owner;
bytes32 winningGuessSha3;
//contructor function
constructor(uint _winningGuess) public {
// by default the owner of the contract is accounts[0] to set the owner change truffle.js
owner = msg.sender;
winningGuessSha3 = keccak256(_winningGuess);
}
// returns the number of tokens purchased by an account
function userTokens(address _user) public view returns (uint) {
return users[_user].tokensBought;
}
// returns the guess made by user so far
function userGuesses(address _user)public view returns(uint[] memory) {
return users[_user].guess;
}
// returns the winning guess
function winningGuess()public view returns(bytes32) {
return winningGuessSha3;
}
// to add a new user to the contract to make guesses
function makeUser() public{
users[msg.sender].userAddress = msg.sender;
users[msg.sender].tokensBought = 0;
userAddresses.push(msg.sender);
}
// function to add tokens to the user that calls the contract
// the money held in contract is sent using a payable modifier function
// money can be released using selfdestruct(address)
function addTokens()public payable {
uint present = 0;
uint tokensToAdd = msg.value/(10**18);
for(uint i = 0; i < userAddresses.length; i++) {
if(userAddresses[i] == msg.sender) {
present = 1;
break;
}
}
// adding tokens if the user present in the userAddresses array
if (present == 1) {
users[msg.sender].tokensBought += tokensToAdd;
}
}
// to add user guesses
function makeGuess(uint _userGuess)public {
require(_userGuess < 1000000 && users[msg.sender].tokensBought > 0);
users[msg.sender].guess.push(_userGuess);
users[msg.sender].tokensBought--;
}
// doesn't allow anyone to buy anymore tokens
function closeGame()public returns(address){
// can only be called my the owner of the contract
require(owner == msg.sender);
address winner = winnerAddress();
return winner;
}
// returns the address of the winner once the game is closed
function winnerAddress()public returns(address) {
for(uint i = 0; i < userAddresses.length; i++) {
User memory user;
user.userAddress = users[userAddresses[i]];
for(uint j = 0; j < user.guess.length; j++) {
if (keccak256(user.guess[j]) == winningGuessSha3) {
return user.userAddress;
}
}
}
// the owner wins if there are no winning guesses
return owner;
}
// sends 50% of the ETH in contract to the winner and rest of it to the owner
function getPrice()public returns (uint){
require(owner == msg.sender);
address winner = winnerAddress();
if (winner == owner) {
owner.transfer(address(this).balance);
} else {
// returns the half the balance of the contract
uint toTransfer = address(this).balance / 2;
// transfer 50% to the winner
winner.transfer(toTransfer);
// transfer rest of the balance to the owner of the contract
owner.transfer(address(this).balance);
}
return address(this).balance;
}
}
Jan 17, 2022, 7:21 PM
User is a struct
so when you call the users mapping you get a struct, not an address
Jan 17, 2022, 7:24 PM
so what changes should I make?
Jan 17, 2022, 7:25 PM
answer me
do you know solidity?
Jan 17, 2022, 7:25 PM
yes sir
Jan 17, 2022, 7:25 PM
are you sure?
Why are you giving to an address the value of a Struct
Jan 17, 2022, 7:28 PM
sir i did that code 3 years ago and it was working fine then and since then i have not worked on solidity so I don't understand what updated and what not
Jan 17, 2022, 7:29 PM
lol
btw as I said
you should assign to the address an Address
Jan 17, 2022, 7:31 PM
so I should change the mapping from address => User to address => User.userAddress?
Jan 17, 2022, 7:33 PM
no
here you have to add .userAddress
Jan 17, 2022, 7:35 PM
one minute i'll check it out
Jan 17, 2022, 7:36 PM
and guess is an array of uints not bytes32
Jan 17, 2022, 7:37 PM
now its giving me this error
Jan 17, 2022, 7:38 PM
there you should use keccak256(abi.encodePacked(...
oh god
after the mapping
listen
you must learn basics first
Jan 17, 2022, 7:39 PM
thats what i did asked in the first place sir
i was referring to mapping itself here
Jan 17, 2022, 7:39 PM
you can't do division without knowing 2+2
infact you said wrong
add .userAddress after the last ]
Jan 17, 2022, 7:40 PM
yes i have to go back to basics...i've become very rusty😪
ok that's resolved now but still more errors
Jan 17, 2022, 7:45 PM
yes
it is not to insult you but to help
which ones...
I suggest to restart from 0
if it is true that code is very old and outdated
Jan 17, 2022, 7:45 PM
yes yes I get you
Jan 17, 2022, 7:48 PM
what is that extension to vs, that errors show this way? can u share pls?
Jan 17, 2022, 7:53 PM
Error lens
Jan 17, 2022, 8:00 PM
same as I said before
keccak(abi.encodedPacked...
1. when you talk about solidity usually you code contracts
2. if you mean a bot as I think, you should check python or js first
Jan 17, 2022, 8:29 PM
Ok, that’s great help, thank you
Jan 18, 2022, 9:24 AM

© 2024 Draquery.com All rights reserved.