Well, I fixed it. But how I did it… yeah… i can’t really explain.
I know I had to remove “Memory” because we don’t want de the contract to forget the new balance after the function was called. And then i just rewrote the code in a way that seemed logic considering the other code that was used in the contract. Maybe someone else can enlighten me why my code fixed the problem. (or how it can be written in a better way)
pragma solidity 0.5.1;
contract MemoryAndStorage {
mapping(uint => User) users;
struct User{
uint id;
uint balance;
}
function addUser(uint id, uint balance) public {
users[id] = User(id, balance);
}
function updateBalance(uint id, uint balance) public {
users[id] = User(id, balance);
users[id].balance = balance;
}
function getBalance(uint id) view public returns (uint) {
return users[id].balance;
}
}