Creating Accounts
This guide shows you how to create and deploy a new account contract in Aztec.
Prerequisites
- A running Aztec sandbox or testnet
- Node.js and TypeScript environment
@aztec/aztec.js
package installed- Understanding of account concepts
Import required libraries
Step 1: Install dependencies
yarn add @aztec/aztec.js@3.0.0-nightly.20250927 @aztec/accounts@3.0.0-nightly.20250927
Create account keys
Any account on Aztec just needs a secret, a salt, and a signing key. Let's get them:
import { Fr, GrumpkinScalar } from '@aztec/aztec.js';
const secretKey = Fr.random();
const salt = new Fr(0);
const signingPrivateKey = GrumpkinScalar.random();
These keys will be used to:
secretKey
: Derive encryption keys for private statesigningPrivateKey
: Sign transactions
Create a wallet
We need a Wallet to hold our account contract. Let's use TestWallet
since most of the 3rd party wallets will use the same interface:
import { TestWallet } from '@aztec/test-wallet';
const wallet = new TestWallet(pxe);
Deploy the account
Get some fee juice
On the sandbox, all the test accounts are funded with fee juice and ready to use. Just import them and you're good to go.
On testnet, accounts have no fee juice so you need to sort that out first. Either using an account that has fee-juice, or (probably easiest) just use the Sponsored Fee Payment Contract
Step 2: Deploy the new account
If your account was pre-funded with Fee Juice (ex. on the sandbox, or if you used a faucet), you can deploy the account using its own Fee Juice:
// get the initial test accounts data
const [fundedAccount] = await getInitialTestAccountsData();
// add the funded account to the wallet
const fundedWallet = await wallet.createSchnorrAccount(fundedAccount.secret, fundedAccount.salt);
// add the new account to the wallet
const alice = await wallet.createSchnorrAccount(secretKey, salt, signingPrivateKey);
// deploy the new account from the funded account
await alice.deploy({ deployAccount: fundedAccount.address }).wait()
Or if using the Sponsored FPC:
const alice = await wallet.createSchnorrAccount(secretKey, salt, signingPrivateKey);
await alice.deploy({ fee: { paymentMethod: sponsoredPaymentMethod }}).wait()
On the testnet your account won't be funded with Fee Juice, so you have to use the Sponsored FPC. Check out the guide on fees if you don't know how to set up sponsoredPaymentMethod
yet
Next steps
- Deploy contracts with your new account
- Send transactions from your account
- Learn about account abstraction
- Implement authentication witnesses