your SC?
in this case
balances[msg.sender] += msg.value;
i got it, but When I want to withdraw to an address with 0 balance, it gives an error. what can I do address sender; uint256 value; mapping (address => uint256) balances; receive() external payable { balances[msg.sender] = msg.value; } function returnAll(address _address) public view returns (uint256) { return balances[_address]; } function returnBalance() public view returns (uint256) { return address(this).balance; } function withdraw(uint256 amount, address payable to) public { require(balances[msg.sender] >= amount, 'you have no balance'); to.transfer(amount); balances[to] = balances[to] - amount; }
firstly receive() external payable { balances[msg.sender] = msg.value; } you need to change to receive() external payable { balances[msg.sender] += msg.value; } if i send ETH to your contract a few times, in your case the balance will be equal to last value, not a sum of all transactions
function withdraw(uint256 amount, address payable to) public { require(balances[msg.sender] >= amount, 'you have no balance'); to.transfer(amount); if (balances[to] == 0) { balances[to] = balances[to]; } else { balances[to] = balances[to] - amount; } }
not works, why? any idea?
sprry but do you have an idea of what you are doing?
balances[to] = balances[to]; 0 = 0 1 = 1 doesn't make sense ))
Kraken 😆
Anyone help plz
testnet ? mainnet ?
stop asking for help
Bro. I know solidity. The point is, contract is written fine and compiled well. Still I am facing an error.
you know solidity?
Обсуждают сегодня