contract BlankContract {
function ReturnSender() external view returns (address) {
return msg.sender;
}
}
Hey, guys. Assume there's such contract. When the contract is deployed in Remix VM, it returns my address. When the same contract is on etherscan, it returns 0x0000. Why is that? Etherscan can't see msg.sender in view functions?
Oct 13, 2022, 12:37 PM
A deployment is a real transactions, and therefore it gives your wallet (deployer) address. But reading data is not a transaction and does not have a msg.sender value.
Oct 13, 2022, 12:40 PM
try using some random from address in the call
Oct 13, 2022, 12:43 PM
Etherscan doesn't connect a wallet on the view section
Oct 13, 2022, 12:45 PM
I also tested this code using Truffle and Ganache, and it returned real address. I both tried accounts[0], accounts[1], and they returned addresses.
Yeah, that's what I thought
Oct 13, 2022, 12:46 PM
It does have a msg.sender, but etherscan doesn't set a "from", on a web3/ethers call it would work
Oct 13, 2022, 12:46 PM
I guess using msg.sender in view functions doesn't make a lot of sense? At least you won't be able to use them on etherscan. So feels like it's better to pass address as an explicit param.
Oct 13, 2022, 12:48 PM
Ah so it's only a matter of whether you set the "from" value or not. Nice to know, thanks
Oct 13, 2022, 12:51 PM
There're a lot. Find some dapp and look for its contract on etherscan.
Oct 13, 2022, 1:40 PM