Creating Accounts
This guide shows you how to create and deploy a new account on Aztec.
Prerequisites
- Connected to a network with a
EmbeddedWalletinstance - Understanding of account concepts
Install dependencies
yarn add @aztec/aztec.js@4.2.0-aztecnr-rc.2 @aztec/wallets@4.2.0-aztecnr-rc.2
Create a new account
Using the wallet from the connection guide, call createSchnorrAccount to create a new account with a random secret and salt:
import { Fr } from "@aztec/aztec.js/fields";
const secret = Fr.random();
const salt = Fr.random();
const newAccount = await wallet.createSchnorrAccount(secret, salt);
console.log("New account address:", newAccount.address.toString());
Source code: docs/examples/ts/aztecjs_connection/index.ts#L47-L54
The secret is used to derive the account's encryption keys, and the salt ensures address uniqueness. The signing key is automatically derived from the secret.
Save the secret and salt values securely. You need both to recover access to your account. If you lose them, you will permanently lose access to the account and any assets it holds.
Deploy the account
New accounts must be deployed before they can send transactions. Deployment requires paying fees.
Using the Sponsored FPC
If your account doesn't have Fee Juice, use the Sponsored Fee Payment Contract:
// Additional imports needed for account deployment examples
import { NO_FROM } from "@aztec/aztec.js/account";
import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee/testing";
import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC";
import { getContractInstanceFromInstantiationParams } from "@aztec/stdlib/contract";
// Set up the Sponsored FPC payment method (see fees guide for details)
const sponsoredFPCInstance = await getContractInstanceFromInstantiationParams(
SponsoredFPCContract.artifact,
{ salt: new Fr(0) },
);
await wallet.registerContract(
sponsoredFPCInstance,
SponsoredFPCContract.artifact,
);
const sponsoredPaymentMethod = new SponsoredFeePaymentMethod(
sponsoredFPCInstance.address,
);
// newAccount is the account created in the previous section
const deployMethod = await newAccount.getDeployMethod();
await deployMethod.send({
from: NO_FROM,
fee: { paymentMethod: sponsoredPaymentMethod },
});
Source code: docs/examples/ts/aztecjs_connection/index.ts#L56-L82
See the guide on fees for setting up the Sponsored FPC.
Using Fee Juice
If your account has Fee Juice from a bridge from L1, you can claim it and deploy in one step using FeeJuicePaymentMethodWithClaim:
import { FeeJuicePaymentMethodWithClaim } from "@aztec/aztec.js/fee";
// claim is from the bridgeTokensPublic step above
// Create a payment method that claims the bridged Fee Juice and uses it to pay
const bridgePaymentMethod = new FeeJuicePaymentMethodWithClaim(feeJuiceAccount.address, claim);
// Use it to pay for any transaction — here we deploy the account in one step
const deployMethodBridged = await feeJuiceAccount.getDeployMethod();
await deployMethodBridged.send({
from: NO_FROM,
fee: { paymentMethod: bridgePaymentMethod },
});
If the account already has Fee Juice on L2 (for example, from a faucet or a previously claimed bridge), no special payment method is needed — just call send({ from: NO_FROM }) and Fee Juice is used automatically.
The from: NO_FROM signals that this transaction should be executed without account contract mediation. The wallet will directly execute it via a default entrypoint with no authorization.
Verify deployment
Confirm the account was deployed successfully:
const metadata = await wallet.getContractMetadata(feeJuiceAccount.address);
console.log("Account deployed:", metadata.initializationStatus);
Source code: docs/examples/ts/aztecjs_connection/index.ts#L157-L160
Next steps
- Deploy contracts with your new account
- Send transactions from an account
- Learn about account abstraction
- Implement authentication witnesses