ethereum / remix-project

Remix is a browser-based compiler and IDE that enables users to build Ethereum contracts with Solidity language and to debug transactions.
https://remix-ide.readthedocs.io
MIT License
2.41k stars 916 forks source link

I cant get Right Address balance #306

Open wktian1987 opened 4 years ago

wktian1987 commented 4 years ago
contract GetMyBalance {

    // below function cant get right result
    // using Remix I get:
    // 0: uint256: 115792089237316195423570985008687907853269984665640564039457581007913129639935
    function _getMyBalance()
        // external
        public
        view
        returns(uint256)
    {
        return msg.sender.balance;
    }

    // Below can get right result
    // by calling getMyBalance()
    // and then get right 
    uint256 public logMyBalance_;
    function getMyBalance()
        external
    {
        logMyBalance_ = _getMyBalance();
    }

    // I can get right result
    uint256 public logMyBalance;
    function writeMyBalance() external {
        logMyBalance = msg.sender.balance;
    }
}
Aniket-Engg commented 4 years ago

I can reproduce it. With VM, it works fine but with testnet, it shows wrong value as OP mentioned.

Aniket-Engg commented 4 years ago

I tested it further. Issue appears with ropsten, rinkeby, and goerli testnets on remix and outside remix too (tested using ethers.js). It works fine with vm on remix and with kovan on or outside remix. This doesn't seem an issue with Remix IDE.

There is a similar issue here too: https://github.com/ethereum/solidity/issues/8545