I'm trying to use delegate actions with my contract.
From the contract's point of view it's irrelevant whether the action is in a standard transaction, or a delegate one. How can I get the relevant account ID whether the transaction is delegated or not?
I'm using Rust and near-sdk==4.1.1
.
It seems that env::signer_account_id()
in the contract's code returns the outer signer's id, rather than the underlying user's account id. The contract contains a check:
require!(env::signer_account_id() == owner, "ERR: not the owner");
which fails for the wrong reason with the following:
{'ActionError': {'index': 0, 'kind': {'FunctionCallError': {'ExecutionError': 'Smart contract panicked: ERR: not the owner'}}}}
I've read some more documentation and it seems that env::predecessor_account_id()
is the answer. According to https://docs.near.org/build/smart-contracts/anatomy/environment:
env::predecessor_account_id()
: Account ID that called this methodenv::signer_account_id()
: Account ID that signed the transaction leading to this execution.