How can a contract method find the address which invoked it?
Suppose I have a contract A
with method B
. I used xyz
address to call method B
then how can method B
see xyz
address.
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityUse the msg.sender
variable. It's automatically available in the contract:
function hello() {
address from = msg.sender;
}
More information in the solidity docs
msg.sender
would only return address of the direct caller, but if this caller a proxy contract it would not return an initial caller. The best suggestion so far is to to pass initial caller as a parameter ethereum.stackexchange.com/a/28977/23579
Dec 22, 2022 at 9:40
Inside the contract you can use msg.sender
to get the address of the caller. See Block and Transaction Properties for the list of global variables.
msg.sender (address): sender of the message (current call)