Connecting to the Sandbox
This guide shows you how to connect your application to the Aztec sandbox and interact with the network.
Prerequisites
- Running Aztec sandbox (see Quickstart) on port 8080
- Node.js installed
- TypeScript project set up
Install Aztec.js
Install the Aztec.js package
yarn add @aztec/aztec.js@3.0.0-devnet.4
Create a Node Client
The sandbox is essentially a one-node network. Just like on a real network, you need to interface with it:
const node = createAztecNodeClient("http://localhost:8080");
const l1Contracts = await node.getL1ContractAddresses();
As the name implies, we want to know the L1 Contracts addresses for our wallet.
Create a TestWallet
You will need to create your own TestWallet to connect accounts. Let's create a TestWallet:
import { createAztecNodeClient } from "@aztec/aztec.js/node";
import { TestWallet } from "@aztec/test-wallet/server";
export async function setupWallet(): Promise<TestWallet> {
const nodeUrl = "http://localhost:8080";
const node = createAztecNodeClient(nodeUrl);
const wallet = await TestWallet.create(node);
return wallet;
}
Verify the connection
Get node information to confirm your connection:
const nodeInfo = await node.getNodeInfo();
console.log("Connected to sandbox version:", nodeInfo.nodeVersion);
console.log("Chain ID:", nodeInfo.l1ChainId);
Get sandbox accounts
The sandbox has some accounts pre-funded with fee-juice to pay for gas. You can import them and create accounts:
import { getInitialTestAccountsData } from "@aztec/accounts/testing";
const [aliceAccount, bobAccount] = await getInitialTestAccountsData();
await wallet.createSchnorrAccount(aliceAccount.secret, aliceAccount.salt);
await wallet.createSchnorrAccount(bobAccount.secret, bobAccount.salt);
Check account balances
Verify that the accounts have fee juice for transactions:
import { getFeeJuiceBalance } from "@aztec/aztec.js/utils";
const aliceBalance = await getFeeJuiceBalance(aliceAccount.address, node);
console.log(`Alice's fee juice balance: ${aliceBalance}`);
Next steps
- Create an account - Deploy new accounts on the network
- Deploy a contract - Deploy your smart contracts
- Send transactions - Execute contract functions