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 @aztec/wallets@4.2.0 @aztec/noir-contracts.js@4.2.0
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 FPC:
// 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 more details on the Sponsored FPC and what this snippet means.
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.
Create a new Schnorr account for this path:
// `feeJuiceAccount` is just another Schnorr account — the same kind as
// `newAccount` above. It gets its own name here so both deploy paths
// can coexist in one example; in your own code, pick whichever name fits.
const feeJuiceSecret = Fr.random();
const feeJuiceSalt = Fr.random();
const feeJuiceAccount = await wallet.createSchnorrAccount(
feeJuiceSecret,
feeJuiceSalt,
);
Claim the bridged Fee Juice and deploy in one step:
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 },
});
Source code: docs/examples/ts/aztecjs_connection/index.ts#L152-L165
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. Substitute the account variable for whichever path you used above (newAccount for the Sponsored FPC path, feeJuiceAccount for the Fee Juice path):
// `newAccount` refers to whichever account you just deployed —
// either the Sponsored FPC account or `feeJuiceAccount` from the Fee Juice path.
const metadata = await wallet.getContractMetadata(newAccount.address);
console.log("Account deployed:", metadata.initializationStatus);
Source code: docs/examples/ts/aztecjs_connection/index.ts#L167-L170
Next steps
- Deploy contracts with your new account
- Send transactions from an account
- Learn about account abstraction
- Implement authentication witnesses