7

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.

11

Use the msg.sender variable. It's automatically available in the contract:

function hello() {
  address from = msg.sender;
}

More information in the solidity docs

3

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.