Skip to main content

Add Spending Keys

Add spending keys to a registered Aztec account.

The Accounts page contains helpful context if you are unfamiliar with how Aztec accounts work.

There is no limit to the number of spending keys that can be added to an Aztec account. This decreases the need for insecure key sharing between devices. For example, you can register a unique spending key on each one of your devices for the same Aztec account, so you don't have to copy and paste private keys.

You can also use the AddSpendingKeyController to add additional recovery public keys to an account after it has been registered. Read more about account recovery here.

Setup

AztecSdk.createAddSpendingKeyController(
userId: GrumpkinAddress,
userSigner: Signer,
spendingPublicKey1: GrumpkinAddress,
spendingPublicKey2: GrumpkinAddress | undefined,
fee: AssetValue):
AddSpendingKeyController;
ArgumentsTypeDescription
userIdGrumpkinAddressThe public key of the account registering the new signing keys.
userSignerSignerA signer associated with the userId.
spendingPublicKey1GrumpkinAddressThe public key of a new spending key.
spendingPublicKey2GrumpkinAddressThe public key of a new spending key.
feeAssetValueThe Aztec transaction fee.

Returns

Return TypeDescription
AddSpendingKeyControllerA user instance with apis bound to the user's account id.

Usage

The follow code is an example of how you could set up and use the AddSpendingKeyController. Obviously, you'll want to save the the spending key private keys to use them later or generate them using a different method.

const newSpendingKey1 = await sdk.createSchnorrSigner(randomBytes(32));
const newSpendingKey2 = await sdk.createSchnorrSigner(randomBytes(32));

const fee = (await sdk.getAddSpendingKeyFees(
sdk.getAssetIdBySymbol("ETH")))[TxSettlementTime.NEXT_ROLLUP];

const controller = sdk.createAddSpendingKeyController(
user,
signer,
newSpendingKey1.getPublicKey(),
newSpendingKey2.getPublicKey(),
fee
);
await controller.createProof();
let txId = await controller.send();

Transaction Fees

The transaction fee can be paid in ETH or DAI.

The settlement time can either be NEXT_ROLLUP or INSTANT. Refer to the fees section on the registration page for a more detailed explanation.