Account Creation

Accounts can be created by calling the AuthAccount constructor and passing the account that should pay for the account creation for the payer parameter.

The payer must have enough funds to be able to create an account. If the account does not have the required funds, the program aborts.

To authorize access to the account, keys can be added using the addPublicKey function. Keys can also later be removed using the removePublicKey function.

For example, to create an account and have the signer of the transaction pay for the account creation, and authorize one key to access the account:

transaction(key: [UInt8]) {
    prepare(signer: AuthAccount) {
        let account = AuthAccount(payer: signer)
        account.addPublicKey(key)
    }
}

Last updated