Smart Contract Code Issue

Does anyone know why when I deposit 5 in the deposit window and click ‘getBalance’ it says 0: uint256: 0

i’m expecting it to say uint256: 5

pragma solidity ^0.4.19;

contract Contract {

address owner;    // current owner of the contract




function deposit(uint amount) public payable {
    require(msg.value == amount);
}

function getBalance() public view returns (uint256) {
    return address(this).balance;
}

}

Hey @Eric_Lam, hope you are.

the problem comes from your deposit function, you have an amount parameter which is not need it, because the amount deposited is managed through msg.value, if you remove that parameter, it works as expected.

image

Carlos Z

1 Like

how come mine doesn’t show the getBalance function after launch?Screen Shot 2021-08-25 at 5.02.56 PM

it was not set to auto-compile smh. my fault. now how do I get the 5 ether to show up in the contract when I hit deposit 5 ether and then getBalance?Screen Shot 2021-08-25 at 5.18.25 PM

Screen Shot 2021-08-25 at 5.18.36 PM