TypeScript Bindings & SDK
Relevant source files
The following files were used as context for generating this wiki page:
The TypeScript Bindings & SDK for Aztec Standards provide a high-level interface for interacting with Aztec-specific smart contracts, including Tokens (AIP-20), NFTs (AIP-721), and Tokenized Vaults (AIP-4626). This SDK leverages @aztec/aztec.js to facilitate private and public state transitions, transaction management, and automated contract deployment within the Aztec Network ecosystem. Sources: README.md:1-40, package.json:28-36
Architecture and Build Pipeline
The SDK architecture is built around a code generation pipeline that transforms Noir contract artifacts into TypeScript classes. This allows developers to interact with contracts using strongly-typed methods.
Build Workflow
The build process follows a specific sequence to ensure artifacts are ready for the TypeScript environment:
- Compilation: Noir contracts are compiled using the Aztec CLI.
- Codegen: TypeScript classes are generated from the compiled JSON artifacts.
- Packaging: The generated artifacts are compiled into JS/TS files and prepared for distribution.
The diagram above illustrates the transformation from Noir source code to distributed TypeScript bindings. Sources: scripts/build-package.sh:1-40
Testing and Development Utilities
The SDK includes a comprehensive suite of utilities in src/ts/test/utils.ts to manage the lifecycle of an Aztec environment during development.
Test Suite Orchestration
The setupTestSuite function initializes the Aztec Sandbox, creates a PXE client, and registers initial accounts. Sources: src/ts/test/utils.ts:60-95
| Function | Purpose | Key Parameters |
|---|---|---|
setupTestSuite | Initializes node, wallet, and accounts for testing. | proverEnabled: boolean |
deployTokenWithMinter | Deploys a standard token with a designated minter. | wallet: Wallet, deployer: AztecAddress |
setPrivateAuthWit | Generates a private Authentication Witness for actions. | caller: AztecAddress, action: Interaction |
waitForSandbox | Polls the sandbox URL until the node is responsive. | url: string |
Sources: src/ts/test/utils.ts:133-143, src/ts/test/utils.ts:221-231, scripts/start-sandbox.ts:10-25
Sandbox Management
The startSandbox utility manages the execution of the Aztec Sandbox as a child process, ensuring the development environment is ready before tests execute. Sources: scripts/start-sandbox.ts:31-50
This flow ensures the TypeScript environment only attempts to deploy contracts once the local node is fully operational. Sources: scripts/start-sandbox.ts:31-69
Contract Interaction Patterns
The SDK facilitates complex Aztec interactions, specifically handling Authentication Witnesses (AuthWits) for third-party actions and partial notes for private transfers.
Authentication Witnesses (AuthWits)
AuthWits allow a user (the authorizer) to permit another party (the caller) to execute a specific function on their behalf, such as spending tokens. This is critical for contracts like Escrow and Vault. Sources: src/ts/test/token.test.ts:143-165, src/ts/test/tokenized_vault.test.ts:36-55
Private Transfer Commitments
The SDK provides utilities to initialize "partial notes." This pattern allows a sender to create a commitment for a recipient without the recipient being online at the exact moment of the transfer.
The initializeTransferCommitment function facilitates this by decrypting private logs to retrieve the commitment hash required for the finalization step. Sources: src/ts/test/utils.ts:253-278, src/ts/test/token.test.ts:101-130
Benchmark Framework
The project includes a benchmarking suite that uses the SDK to measure performance across different contract operations.
| Contract | Benchmarked Operations |
|---|---|
| Token | mint_to_private, transfer_private_to_public, burn_private |
| NFT | mint_to_private, transfer_public_to_private, burn_public |
| Vault | deposit_public_to_private, issue_private_to_public_exact, redeem_private_to_public |
| Escrow | withdraw (tokens), withdraw_nft |
Sources: benchmarks/token_contract.benchmark.ts:63-120, benchmarks/tokenized_vault_contract.benchmark.ts:103-180, benchmarks/escrow_contract.benchmark.ts:85-110
Summary
The TypeScript Bindings & SDK serve as the essential bridge between the Noir smart contracts and the application layer. By providing automated codegen, specialized testing utilities for private state, and standardized patterns for AuthWits and commitments, the SDK enables robust development of privacy-preserving applications on Aztec. Sources: README.md:1-10, src/ts/test/utils.ts:1-58