SDK

Setup

Setting up the SDK.

This explainer will frequently reference code snippets from the CLI reference repository. You can pull this repo and follow along to run the examples yourself.

If you are building a web app, check out the create react app reference repo.

The following examples are written in Typescript and assumes users will be creating keys using Metamask in a browser.

Install

yarn add @aztec/sdk

Once the SDK is installed, import it into your project. Using Typescript is highly recommended.

import { createAztecSdk } from "@aztec/sdk";

Provider Setup

You need to set up a connection to an Ethereum network and import a private key. Since this is assuming a Nodejs context there is no direct access to an Ethereum wallet.

Import EthersAdapter from @aztec/sdk and JsonRpcSigner from @ethersproject/providers.

const ethersProvider = new ethers.providers.JsonRpcProvider("http://localhost:24012/rpc") // local connection to metamask
const ethereumProvider = new EthersAdapter(ethersProvider);

SDK setup

Once the provider is set up you can create an instance of the Aztec SDK, specifying the rollup host. When working on the mainnet fork local development environment, the corresponding sequencer endpoint is:

http://localhost:8081

You can connect to the Aztec sequencer that is connected to Ethereum at:

https://api.aztec.network/aztec-connect-prod/falafel
const setupSdk = async () => {
  sdk = await createAztecSdk(ethereumProvider, {
    serverUrl: "http://localhost:8081", // local devnet
    pollInterval: 1000,
    memoryDb: true,            // set to false to save chain data
    debug: "bb:*",             // print debug logs
    flavour: SdkFlavour.PLAIN, // Use PLAIN with Nodejs
    minConfirmation: 1,        // ETH block confirmations
  });

  await sdk.run();
  await sdk.awaitSynchronised();
};

Debug

Run export DEBUG=bb:* in your terminal before running a Nodejs script to also turn on the debug logs.

Browser debugging

If you have the debug flag set to bb:* to log output during development, make sure the browser console log level includes "verbose" to be able to see all of the output.


You can enable debugging when you create the SDK instance.

const sdk = await createAztecSdk(ethereumProvider, {
  serverUrl: "http://localhost:8081", // local devnet
  pollInterval: 1000,
  memoryDb: true,     // set to false to save DB in a project file rather than memory
  debug: "bb:*",
  minConfirmation: 1, // ETH block confirmations
});
Previous
Overview
Next
CLI