Skip to main content
Version: v3.0.0-nightly.20251018

Creating Accounts

This guide walks you through creating and deploying a new account contract in Aztec.

Prerequisites

  • Running Aztec sandbox or testnet
  • Node.js and TypeScript environment
  • @aztec/aztec.js package installed
  • Understanding of account concepts

Install dependencies

yarn add @aztec/aztec.js@3.0.0-nightly.20251018 @aztec/accounts@3.0.0-nightly.20251018

Create account keys

Every account on Aztec requires a secret, a salt, and a signing key.

import { Fr, GrumpkinScalar } from "@aztec/aztec.js";

const secretKey = Fr.random();
const salt = new Fr(0);
const signingPrivateKey = GrumpkinScalar.random();

These keys serve the following purposes:

  • secretKey: Derives encryption keys for private state
  • signingPrivateKey: Signs transactions

Create a wallet

You need a Wallet to hold your account contract. Use TestWallet since most third-party wallets implement the same interface:

import { TestWallet } from "@aztec/test-wallet/server";

const wallet = new TestWallet(pxe);

Deploy the account

Get Fee Juice

On the sandbox, all test accounts come pre-funded with Fee Juice. Import them to start using them immediately.

On testnet, accounts start without Fee Juice. You can either use an account that has Fee Juice or use the Sponsored Fee Payment Contract.

Register and deploy accounts

Test accounts on the Sandbox are already deployed but need to be registered in the wallet and the PXE (Private eXecution Environment):

// on the Sandbox, you can get the initial test accounts data using getInitialTestAccountsData
const [initialAccountData] = await getInitialTestAccountsData();
// add the funded account to the wallet
const initialAccount = await wallet.createSchnorrAccount(initialAccountData.secret, initialAccountData.salt);

Other accounts require deployment. To deploy an account that already has Fee Juice:

const anotherAccount = await wallet.createSchnorrAccount(accountWithFeeJuice.secret, accountWithFeeJuice.salt);
const deployMethod = await anotherAccount.getDeployMethod();

// using the default fee payment method (Fee Juice)
await deployMethod.send({
from: AztecAddress.ZERO, // the zero address is used because there's no account to send from: the transaction itself will create the account!
}).wait()

To deploy using the Sponsored FPC:

// deploy an account with random salt and secret
const anotherAccount = await wallet.createSchnorrAccount(Fr.random(), Fr.random());
const deployMethod = await anotherAccount.getDeployMethod();
await deployMethod.send({
from: AztecAddress.ZERO,
fee: { paymentMethod: sponsoredPaymentMethod }
}).wait()
info

See the guide on fees for setting up sponsoredPaymentMethod.

Next steps