To access the message sender, you need to import the msg_sender function from the std library . Then you can use msg_sender() to get a Result with an Identity .
use std::auth::{AuthError, msg_sender};
let sender: Result<Identity, AuthError> = msg_sender();
- If the caller is a contract, then
Result::Ok(Sender)is returned with theContractIdsender variant. - If the caller is external (i.e. from a script), then all coin input owners in the transaction are checked. If all owners are the same, then
Result::Ok(Sender)is returned with theAddresssender variant. - If the caller is external and coin input owners are different, then the caller cannot be determined and a
Result::Err(AuthError)is returned.