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.jspackage installed- Understanding of account concepts
 
Install dependencies
yarn add @aztec/aztec.js@3.0.0-devnet.2 @aztec/accounts@3.0.0-devnet.2
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 statesigningPrivateKey: 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:
// for use in the browser
import { TestWallet } from "@aztec/test-wallet/client/lazy";
// for use on a server
import { TestWallet } from "@aztec/test-wallet/server";
import { createAztecNodeClient } from "@aztec/aztec.js/node";
const nodeUrl = process.env.AZTEC_NODE_URL || "http://localhost:8080";
const node = createAztecNodeClient(nodeUrl);
const wallet = await TestWallet.create(node);
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:
// 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();
See the guide on fees for setting up sponsoredPaymentMethod.
Next steps
- Deploy contracts with a new account
 - Send transactions from an account
 - Learn about account abstraction
 - Implement authentication witnesses