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.
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.
Use the msg.sender variable. It's automatically available in the contract:
function hello() {
address from = msg.sender;
}
More information in the solidity docs
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)
msg.senderwould 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 https://ethereum.stackexchange.com/a/28977/23579 – Gleichmut Dec 22 '22 at 09:40