Search code examples
nearprotocol

How to add an initial access key for account


Suppose I want to add an initial access key for a new account. CreateAccountAction requires receiver_id to be the ID of the new account. AddKeyAction requires receiver_id = signer_id. How it's possible to have CreateAccountAction and AddKeyAction in the same transaction?


Solution

  • We use a special permission which we call actor_id. When a new account is created using CreateAccount, all subsequent actions use actor_id == receiver_id. This is the cause until you execute DeleteAccount action, which changes actor_id back to predecessor_id.