Skip to main content

How to Create a New Account

This guide explains how to create a new account using Aztec.js.

Relevant imports

You will need to import these libraries:

create_account_imports
import { getSchnorrAccount } from '@aztec/accounts/schnorr';
import { getDeployedTestAccountsWallets } from '@aztec/accounts/testing';
import { Fr, GrumpkinScalar, createPXEClient } from '@aztec/aztec.js';
Source code: yarn-project/end-to-end/src/composed/docs_examples.test.ts#L2-L6

Define arguments needed

define_account_vars
const PXE_URL = process.env.PXE_URL || 'http://localhost:8080';
const pxe = createPXEClient(PXE_URL);
const secretKey = Fr.random();
const signingPrivateKey = GrumpkinScalar.random();
Source code: yarn-project/end-to-end/src/composed/docs_examples.test.ts#L18-L23

Create the wallet with these args

create_wallet
// Use a pre-funded wallet to pay for the fees for the deployments.
const wallet = (await getDeployedTestAccountsWallets(pxe))[0];
const newAccount = await getSchnorrAccount(pxe, secretKey, signingPrivateKey);
await newAccount.deploy({ deployWallet: wallet }).wait();
const newWallet = await newAccount.getWallet();
Source code: yarn-project/end-to-end/src/composed/docs_examples.test.ts#L25-L31

Now you have a new wallet in your PXE! To learn how to use this wallet to deploy a contract, read this guide.