Signer

The signer type can also be used to implement "only owner" checks. In this example, the sensitive_function takes the owner: &signer as its first argument, and ownership checks are implemented. The address of the module and the address of the owner are the same and can be accessed as @module_address, similar to address(this) in Solidity. The signer arguments are automatically passed by VM.

To convert the &signer type to the address type, the signer module from the standard library is used.


module module_address::only_owner_example {
use std::signer;
public entry fun sensitive_function(owner: &signer) {
only_owner(owner);
/// ...
}
fun only_owner(owner: &signer) {
assert!(signer::address_of(owner) == @module_address, 1);
}
}