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;
}
}
Actual balance of caller
115792089237316195423570985008687907853269984665640564039457581007913129639935
_getMyBalance methodhttps://github.com/ethereum/remix/issues/1430
https://github.com/ethereum/solidity/issues/8545
web3js: 1.2.6
@Aniket-Engg Thanks for reporting, will investigate...
@Aniket-Engg Copying over a summary of the discussion in ethereumjs gitter...
@ryanio identified the cause of this as a Geth 1.9.12 breaking change.
From: https://github.com/ethereum/go-ethereum/releases/tag/v1.9.12
One small breaking change in the release is that eth_call will not default to
your first account any more if you don't explicitly specify a sender. This was done
to avoid the same input behaving differently in different environments. You should
never do eth_call without explicitly setting a sender in the first place.
The question now is whether or not Web3 should (try to) set an account for eth_call by default.
IMHO, Web3 can explain the situation in the documentation and recommend to explicitly define a fromaddress but in case, address is not provided, Web3 should set it to first address by default.
With time, when users are aware about it, default support can be deprecated and removed.
This also affects any .estimateGas request and any state changing method invoked with .call.
Re-opening for visibility because it looks like Geth just published this change to their docker stable tag.
In our unit tests, when calling estimateGas without specifying a from address in the options, the error is:
gas required exceeds allowance (4000000) or always failing transaction
Also happens to me
.estimateGas works properly against Infura in Rinkeby and event against Geth node in Mainnet. But same code doesn't work for one smart contract function against Geth in Mainnet.
Specifying all the parameters: from, nonce and even tried with gas
Is there any update on this?
@GregTheGreek there were some notes added to the docs in #3467. a similar note could be added for estimateGas.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.