### Wallet Setup Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/README.md Example of setting up an ephemeral EmbeddedWallet. ```typescript import { setupWallet } from './src/utils/setup_wallet.js'; const wallet = await setupWallet(); ``` -------------------------------- ### Fee Payment Setup Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/README.md Example of setting up Sponsored Fee Payment Method. ```typescript import { getSponsoredFPCInstance } from './src/utils/sponsored_fpc.js'; import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee'; const fpc = await getSponsoredFPCInstance(); const paymentMethod = new SponsoredFeePaymentMethod(fpc.address); ``` -------------------------------- ### Test setup Source: https://github.com/aztecprotocol/aztec-starter/blob/next/docs/ONBOARDING.src.md Setup utilities for tests. ```rust #include_code test-setup /src/test/utils.nr rust ``` -------------------------------- ### Example .env file Source: https://github.com/aztecprotocol/aztec-starter/blob/next/docs/ONBOARDING.src.md Example format for the .env file to store deployment credentials. ```bash SECRET="0x..." SIGNING_KEY="0x..." SALT="0x..." AZTEC_ENV=local-network ``` -------------------------------- ### Workflow 3: Setup Fee Payment Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/README.md Example of setting up a fee payment method using the Sponsored Fee Payment Contract (FPC). ```typescript import { getSponsoredFPCInstance } from './src/utils/sponsored_fpc.js'; import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee'; const sponsoredFPC = await getSponsoredFPCInstance(); await wallet.registerContract(sponsoredFPC, SponsoredFPCContractArtifact); const paymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address); ``` -------------------------------- ### setupWallet() Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/wallet-utilities.md Example demonstrating how to use setupWallet() to create an EmbeddedWallet and then use it to create a Schnorr account. ```typescript import { setupWallet } from './src/utils/setup_wallet.js'; async function main() { // Create wallet const wallet = await setupWallet(); // Use wallet to deploy contracts or create accounts const account = await wallet.createSchnorrAccount(secretKey, salt, signingKey); } main().catch(console.error); ``` -------------------------------- ### Run Example Contract Deployment Profile Source: https://github.com/aztecprotocol/aztec-starter/blob/next/README.md Run an example contract deployment profile. ```bash yarn profile ``` -------------------------------- ### Validate configuration on startup Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/configuration.md Example of validating configuration settings when the application starts, exiting if there are errors. ```typescript try { const config = ConfigManager.getInstance(); console.log(`Running on ${config.getConfig().name}`); } catch (error) { console.error(`Configuration error: ${error.message}`); process.exit(1); } ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/aztecprotocol/aztec-starter/blob/next/README.md Installs all project dependencies using Yarn. ```bash yarn install ``` -------------------------------- ### Transaction Profiling Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/ONBOARDING.md Example of profiling a contract deployment transaction. ```typescript const profileTx = await PodRacingContract.deploy(wallet, address).profile({ profileMode: "full", from: address }); console.dir(profileTx, { depth: 2 }); ``` -------------------------------- ### getEnv() example usage Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/configuration-manager.md Example of how to use the getEnv function. ```typescript import { getEnv } from '../config/config.js'; const envName = getEnv(); console.log(`Current environment: ${envName}`); ``` -------------------------------- ### Workflow 2: Get FPC and Setup Fee Payment Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/fpc-utilities.md Retrieves a pre-deployed FPC instance and sets up a SponsoredFeePaymentMethod. ```typescript import { getSponsoredFPCInstance } from './src/utils/sponsored_fpc.js'; import { SponsoredFPCContractArtifact } from '@aztec/noir-contracts.js/SponsoredFPC'; import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee'; async function setupFeePayment(wallet) { // Get pre-deployed FPC instance const sponsoredFPC = await getSponsoredFPCInstance(); // Register with wallet await wallet.registerContract(sponsoredFPC, SponsoredFPCContractArtifact); // Create payment method using the address const paymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address); return { sponsoredFPC, paymentMethod }; } ``` -------------------------------- ### Wallet Setup Pattern Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/scripts-reference.md TypeScript code snippet demonstrating how to set up a wallet. ```typescript import { setupWallet } from './src/utils/setup_wallet.js'; const wallet = await setupWallet(); ``` -------------------------------- ### Install Aztec Toolkit Source: https://github.com/aztecprotocol/aztec-starter/blob/next/README.md Installs the Aztec toolkit (local network, CLI, and other tooling) at a specified version using a curl command. ```bash export VERSION=4.3.0 curl -fsSL "https://install.aztec.network/${VERSION}" | VERSION="${VERSION}" bash -s ``` -------------------------------- ### AZTEC_ENV Usage Examples Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/configuration.md Provides command-line examples for setting and using the AZTEC_ENV variable. ```bash # In terminal export AZTEC_ENV=testnet yarn deploy # Or inline with command AZTEC_ENV=testnet yarn deploy # Or in .env file echo "AZTEC_ENV=testnet" >> .env ``` -------------------------------- ### Full Game Lifecycle Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/README.md An example demonstrating the full lifecycle of a game, from creation to finalization, including joining, playing rounds, and revealing scores. ```typescript import { setupWallet } from './src/utils/setup_wallet.js'; import { createAccountFromEnv } from './src/utils/create_account_from_env.js'; import { getSponsoredFPCInstance } from './src/utils/sponsored_fpc.js'; import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee'; import { PodRacingContract } from './src/artifacts/PodRacing.js'; import { Fr } from '@aztec/aztec.js/fields'; import { getTimeouts } from './config/config.js'; async function playGame() { // Setup const wallet = await setupWallet(); const player1 = await createAccountFromEnv(wallet); const player2 = /* another account */; const sponsoredFPC = await getSponsoredFPCInstance(); const paymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address); const timeouts = getTimeouts(); // Get contract const contract = await PodRacingContract.at(contractAddress, wallet); // contractAddress is not defined in this snippet const gameId = Fr.random(); // 1. Create game await contract.methods.create_game(gameId) .simulate({ from: player1.address }); await contract.methods.create_game(gameId) .send({ from: player1.address, fee: { paymentMethod }, wait: { timeout: timeouts.txTimeout } }); // 2. Join game await contract.methods.join_game(gameId) .simulate({ from: player2.address }); await contract.methods.join_game(gameId) .send({ from: player2.address, fee: { paymentMethod }, wait: { timeout: timeouts.txTimeout } }); // 3. Play rounds for (let round = 1; round <= 3; round++) { // Player 1 await contract.methods .play_round(gameId, round, 3, 2, 2, 1, 1) .simulate({ from: player1.address }); await contract.methods .play_round(gameId, round, 3, 2, 2, 1, 1) .send({ from: player1.address, fee: { paymentMethod }, wait: { timeout: timeouts.txTimeout } }); // Player 2 await contract.methods .play_round(gameId, round, 1, 1, 3, 2, 2) .simulate({ from: player2.address }); await contract.methods .play_round(gameId, round, 1, 1, 3, 2, 2) .send({ from: player2.address, fee: { paymentMethod }, wait: { timeout: timeouts.txTimeout } }); } // 4. Reveal scores await contract.methods.finish_game(gameId) .simulate({ from: player1.address }); await contract.methods.finish_game(gameId) .send({ from: player1.address, fee: { paymentMethod }, wait: { timeout: timeouts.txTimeout } }); await contract.methods.finish_game(gameId) .simulate({ from: player2.address }); await contract.methods.finish_game(gameId) .send({ from: player2.address, fee: { paymentMethod }, wait: { timeout: timeouts.txTimeout } }); // 5. Finalize (after 300 blocks) // ... wait for game to expire ... await contract.methods.finalize_game(gameId) .simulate({ from: player1.address }); await contract.methods.finalize_game(gameId) .send({ from: player1.address, fee: { paymentMethod }, wait: { timeout: timeouts.txTimeout } }); console.log('Game complete!'); } playGame().catch(console.error); ``` -------------------------------- ### get-block Source: https://github.com/aztecprotocol/aztec-starter/blob/next/ONBOARDING.md Example script to query the Aztec node for block information. ```typescript const nodeUrl = getAztecNodeUrl(); const node = createAztecNodeClient(nodeUrl); let block = await node.getBlock(BlockNumber(1)); console.log(block?.header) ``` -------------------------------- ### getAztecNodeUrl() example usage Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/configuration-manager.md Example of how to use the getAztecNodeUrl function. ```typescript import { getAztecNodeUrl } from '../config/config.js'; const nodeUrl = getAztecNodeUrl(); const node = createAztecNodeClient(nodeUrl); ``` -------------------------------- ### Account Deployment Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/README.md Example of deploying a Schnorr account to the network. ```typescript import { deploySchnorrAccount } from './src/utils/deploy_account.js'; const account = await deploySchnorrAccount(wallet); ``` -------------------------------- ### Start Local Network Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/wallet-utilities.md Command to start a local Aztec network for development and testing. ```bash aztec start --local-network ``` -------------------------------- ### interaction_existing_contract.ts Example Usage Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/scripts-reference.md Example commands to set up environment variables and interact with the contract. ```bash # Save contract info echo "POD_RACING_CONTRACT_ADDRESS=0x..." >> .env echo "CONTRACT_SALT=0x..." >> .env echo "CONTRACT_DEPLOYER=0x..." >> .env echo "CONTRACT_CONSTRUCTOR_ARGS='["0x..."]'" >> .env # Interact with contract yarn interaction-existing-contract ``` -------------------------------- ### getSponsoredFPCInstance() Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/fpc-utilities.md Example of how to retrieve the Sponsored FPC instance, register it with a wallet, and create a payment method. ```typescript import { getSponsoredFPCInstance } from './src/utils/sponsored_fpc.js'; import { SponsoredFPCContractArtifact } from '@aztec/noir-contracts.js/SponsoredFPC'; import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee'; async function setupFeePayment(wallet) { const sponsoredFPC = await getSponsoredFPCInstance(); // Register contract with wallet await wallet.registerContract(sponsoredFPC, SponsoredFPCContractArtifact); // Create payment method const paymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address); return paymentMethod; } ``` -------------------------------- ### Account Creation Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/README.md Example of creating a Schnorr account from environment variables. ```typescript import { createAccountFromEnv } from './src/utils/create_account_from_env.js'; const account = await createAccountFromEnv(wallet); ``` -------------------------------- ### config/local-network.json Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/configuration-manager.md Example JSON configuration file for local development. ```json { "name": "local-network", "environment": "local", "network": { "nodeUrl": "http://localhost:8080", "l1RpcUrl": "http://localhost:8545", "l1ChainId": 31337 }, "settings": { "skipLocalNetwork": false, "version": "4.3.0" }, "timeouts": { "deployTimeout": 120000, "txTimeout": 60000, "waitTimeout": 30000 } } ``` -------------------------------- ### Configuration Access Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/README.md Example of accessing node URL and timeouts from configuration. ```typescript import { getAztecNodeUrl, getTimeouts } from './config/config.js'; const nodeUrl = getAztecNodeUrl(); // http://localhost:8080 const { txTimeout } = getTimeouts(); // 60000 ``` -------------------------------- ### Integration with Contract Deployment Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/wallet-utilities.md Example demonstrating contract deployment using a wallet. ```typescript import { setupWallet } from './src/utils/setup_wallet.js'; import { PodRacingContract } from './src/artifacts/PodRacing.js'; const wallet = await setupWallet(); const adminAddress = account.address; const deployRequest = PodRacingContract.deploy(wallet, adminAddress); await deployRequest.simulate({ from: adminAddress }); const { contract } = await deployRequest.send({ from: adminAddress, fee: { paymentMethod }, wait: { timeout } }); ``` -------------------------------- ### Basic Deployment Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/account-utilities.md Example demonstrating the basic deployment of a Schnorr account. ```typescript import { deploySchnorrAccount } from './src/utils/deploy_account.js'; async function main() { const account = await deploySchnorrAccount(); console.log(`Account deployed at: ${account.address}`); console.log('Save the SECRET, SIGNING_KEY, and SALT values logged above'); } main().catch(console.error); ``` -------------------------------- ### getSponsoredFPCAddress() Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/fpc-utilities.md Example of how to get only the address of the Sponsored FPC and use it to create a payment method. ```typescript import { getSponsoredFPCAddress } from './src/utils/sponsored_fpc.js'; import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee'; const fpcAddress = await getSponsoredFPCAddress(); const paymentMethod = new SponsoredFeePaymentMethod(fpcAddress); ``` -------------------------------- ### AccountManager getDeployMethod Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/account-utilities.md Example of getting and simulating a deployment request for an account. ```typescript const deployMethod = await account.getDeployMethod(); await deployMethod.simulate({ from: NO_FROM }); await deployMethod.send({ from: NO_FROM, fee: { paymentMethod } }); ``` -------------------------------- ### getAccountFromEnv() Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/account-utilities.md Alias for createAccountFromEnv(). Creates and returns an account from environment variables. ```typescript import { setupWallet } from './src/utils/setup_wallet.js'; import { getAccountFromEnv } from './src/utils/create_account_from_env.js'; const wallet = await setupWallet(); const account = await getAccountFromEnv(wallet); ``` -------------------------------- ### Using Convenience Functions Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/configuration.md Example of using convenience functions to access configuration in TypeScript. ```typescript import { getAztecNodeUrl, getL1RpcUrl, getEnv, getTimeouts } from './config/config.js'; const nodeUrl = getAztecNodeUrl(); const l1Url = getL1RpcUrl(); const env = getEnv(); // 'local-network' or 'testnet' const { deployTimeout } = getTimeouts(); ``` -------------------------------- ### Full Game Lifecycle Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/scripts-reference.md Demonstrates the sequence of commands to deploy an account, deploy a contract, configure environment variables, interact with the contract, and read game state logs. ```bash # 1. Deploy account yarn deploy-account # 2. Update .env with SECRET, SIGNING_KEY, SALT # 3. Deploy contract yarn deploy # 4. Update .env with POD_RACING_CONTRACT_ADDRESS, etc. # 5. Interact with contract yarn interaction-existing-contract # 6. Read game state with logs LOG_LEVEL='info; debug:contract_log' yarn read-logs ``` -------------------------------- ### Local Network Setup for E2E Tests Source: https://github.com/aztecprotocol/aztec-starter/blob/next/CLAUDE.md Commands to start a local Aztec network and clear the PXE store, required before running TypeScript E2E tests. ```bash aztec start --local-network # Start local network first rm -rf ./store # Always clear store after network restart ``` -------------------------------- ### Load Configuration from Environment Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/README.md Example showing how to load configuration based on the environment. ```typescript import { getAztecNodeUrl } from './config/config.js'; const nodeUrl = getAztecNodeUrl(); // Returns http://localhost:8080 for local-network // Returns https://testnet.aztec.network for testnet ``` -------------------------------- ### Error Handling for Sponsored FPC Instance Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/fpc-utilities.md Example of how to safely get the Sponsored FPC instance and handle potential errors. ```typescript import { getSponsoredFPCInstance } from './src/utils/sponsored_fpc.js'; async function safeGetFPC() { try { const sponsoredFPC = await getSponsoredFPCInstance(); return sponsoredFPC; } catch (error) { console.error(`Failed to get Sponsored FPC: ${error.message}`); if (error.message.includes('artifact')) { console.error('SponsoredFPC artifact not available'); } else if (error.message.includes('address')) { console.error('Could not compute contract address'); } throw error; } } ``` -------------------------------- ### Complete Deployment Flow Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/pod-racing-contract.md Example of the complete deployment flow for the Pod Racing contract, including wallet setup, fee payment, simulation, and sending the deployment transaction. ```typescript import { setupWallet } from './src/utils/setup_wallet.js'; import { deploySchnorrAccount } from './src/utils/deploy_account.js'; import { getSponsoredFPCInstance } from './src/utils/sponsored_fpc.js'; import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee'; import { SponsoredFPCContractArtifact } from '@aztec/noir-contracts.js/SponsoredFPC'; import { PodRacingContract } from './src/artifacts/PodRacing.js'; import { getTimeouts } from './config/config.js'; async function deployPodRacing() { const wallet = await setupWallet(); const admin = await deploySchnorrAccount(wallet); // Setup fee payment const sponsoredFPC = await getSponsoredFPCInstance(); await wallet.registerContract(sponsoredFPC, SponsoredFPCContractArtifact); const paymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address); // Deploy contract const deployRequest = PodRacingContract.deploy(wallet, admin.address); // Always simulate before sending await deployRequest.simulate({ from: admin.address }); // Send deployment const { contract, receipt } = await deployRequest.send({ from: admin.address, fee: { paymentMethod }, wait: { timeout: getTimeouts().deployTimeout } }); console.log(`Contract deployed at: ${contract.address}`); return contract; } ``` -------------------------------- ### Workflow 1: Deploy Account and Contract Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/README.md Steps to deploy an account and then deploy the contract. ```bash # 1. Deploy account (generates keys) yarn deploy-account # 2. Save keys to .env echo "SECRET=0x..." >> .env echo "SIGNING_KEY=0x..." >> .env echo "SALT=0x..." >> .env # 3. Deploy contract yarn deploy # 4. Save contract info to .env echo "POD_RACING_CONTRACT_ADDRESS=0x..." >> .env ``` -------------------------------- ### Minimal Setup Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/fpc-utilities.md Sets up the wallet and deploys the Sponsored FPC with a default logger. ```typescript import { setupWallet } from './src/utils/setup_wallet.js'; import { setupSponsoredFPC } from './src/utils/sponsored_fpc.js'; import { createLogger } from '@aztec/foundation/log'; const logger = createLogger('my-app'); const wallet = await setupWallet(); await setupSponsoredFPC(wallet, logger.info.bind(logger)); console.log('Sponsored FPC deployed'); ``` -------------------------------- ### Run Profile with Faster Native Proving Source: https://github.com/aztecprotocol/aztec-starter/blob/next/README.md Specify the bb binary path for faster native proving. ```bash BB_BINARY_PATH="/home/user/.bb/bb" BB_WORKING_DIRECTORY="/tmp/bb" CRS_PATH="/tmp/bb" yarn profile ``` -------------------------------- ### getTimeouts() example usage Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/configuration-manager.md Example of how to use the getTimeouts function. ```typescript import { getTimeouts } from '../config/config.js'; const { deployTimeout, txTimeout } = getTimeouts(); await contract.deploy(wallet, args).send({ from: address, wait: { timeout: deployTimeout } }); ``` -------------------------------- ### Higher-level setup helpers Source: https://github.com/aztecprotocol/aztec-starter/blob/next/ONBOARDING.md Includes helper functions for setting up games, playing rounds with specific allocations, and playing all rounds with a given strategy. ```Rust // Helper to setup a game with two players pub unconstrained fn setup_two_player_game( env: &mut TestEnvironment, contract_address: AztecAddress, player1: AztecAddress, player2: AztecAddress, game_id: Field ) { env.call_public(player1, PodRacing::at(contract_address).create_game(game_id)); env.call_public(player2, PodRacing::at(contract_address).join_game(game_id)); } // Helper to play a round with specific allocations pub unconstrained fn play_round_with_allocation( env: &mut TestEnvironment, contract_address: AztecAddress, player: AztecAddress, game_id: Field, round: u8, allocation: (u8, u8, u8, u8, u8) ) { let (t1, t2, t3, t4, t5) = allocation; env.call_private( player, PodRacing::at(contract_address).play_round(game_id, round, t1, t2, t3, t4, t5) ); } // Helper to play all 3 rounds with the same strategy pub unconstrained fn play_all_rounds_with_strategy( env: &mut TestEnvironment, contract_address: AztecAddress, player: AztecAddress, game_id: Field, allocations: [(u8, u8, u8, u8, u8); 3] ) { for i in 0..3 { let round = (i + 1) as u8; play_round_with_allocation(env, contract_address, player, game_id, round, allocations[i]); } } ``` -------------------------------- ### getL1RpcUrl() example usage Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/configuration-manager.md Example of how to use the getL1RpcUrl function. ```typescript import { getL1RpcUrl } from '../config/config.js'; const l1RpcUrl = getL1RpcUrl(); const client = createExtendedL1Client([l1RpcUrl], mnemonic, chainInfo); ``` -------------------------------- ### Querying Blocks Source: https://github.com/aztecprotocol/aztec-starter/blob/next/docs/ONBOARDING.src.md Demonstrates how to query the Aztec node directly. ```typescript #include_code get-block /scripts/get_block.ts typescript ``` ```bash yarn get-block ``` -------------------------------- ### AztecAddress Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/types.md Example of creating and comparing AztecAddresses. ```typescript import { AztecAddress } from '@aztec/aztec.js/addresses'; const zeroAddr = AztecAddress.zero(); const adminAddr = AztecAddress.fromString('0xabc...'); const isSameAddr = adminAddr.equals(otherAddr); ``` -------------------------------- ### GrumpkinScalar Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/types.md Example of generating a random GrumpkinScalar. ```typescript import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin'; const signingKey = GrumpkinScalar.random(); ``` -------------------------------- ### Deploy Contract Source: https://github.com/aztecprotocol/aztec-starter/blob/next/docs/ONBOARDING.src.md This script demonstrates the process of deploying a smart contract on the Aztec network, including wallet setup, fee registration, account deployment, and the contract deployment itself. It emphasizes the importance of simulating transactions before sending them. ```typescript import { AztecAddress, AztecNodeClient, Contract, ContractDeployer, Fr, Point, Wallet } from "@aztec/aztec.js"; import { TestWallet } from "@aztec/aztec.js/wallet"; import { computeSecret, setup } from "@aztec/aztec.js/testing"; import { SponsoredFPC } from "@aztec/noir-contracts/dest/sponsored_fpc"; import { SchnorrAccount } from "@aztec/noir-contracts/dest/schnorr_account"; import { PodRacingContract } from "../contract_artifacts/PodRacingContract"; async function deploy_contract(wallet: TestWallet, node: AztecNodeClient) { const deployer = new ContractDeployer(PodRacingContract.abi, PodRacingContract.bytecode); const constructorArgs = [ wallet.getCompleteAddress().address, new Fr(3), new Fr(9), ]; const deployTx = deployer.deploy(wallet, constructorArgs); // Register the SponsoredFPC for fee payment const fpc = await SponsoredFPC.deploy(wallet); await fpc.methods.transfer(wallet.getCompleteAddress().address, 1000000000000000000n).send().wait(); // Deploy a Schnorr account (or use one from env) const schnorrAccount = await SchnorrAccount.deploy(wallet, wallet.getCompleteAddress().address); // Deploy the contract const instance = await deployTx.send().wait(); console.log(`Contract deployed to: ${instance.address}`); console.log(`Admin address: ${instance.adminAddress}`); console.log(`Instantiation data: ${JSON.stringify(instance.constructorArgs)}`); return instance; } async function main() { const { wallet, node } = await setup(true); await deploy_contract(wallet, node); } main(); ``` -------------------------------- ### Fr Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/types.md Example usage of Fr class. ```typescript import { Fr } from '@aztec/aztec.js/fields'; const secret = Fr.random(); const salt = Fr.fromString('0x1234...'); const gameId = Fr.random(); ``` -------------------------------- ### SponsoredFeePaymentMethod Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/types.md Example of using SponsoredFeePaymentMethod for transaction fees. ```typescript import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee'; const paymentMethod = new SponsoredFeePaymentMethod(fpcAddress); await contract.methods.someFunc().send({ from: address, fee: { paymentMethod }, wait: { timeout: 60000 } }); ``` -------------------------------- ### Deploy Account to Testnet Source: https://github.com/aztecprotocol/aztec-starter/blob/next/README.md Deploys an account contract to the Aztec testnet. ```bash yarn deploy-account::testnet ``` -------------------------------- ### Integration with Account Creation Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/wallet-utilities.md Example showing how the wallet is used to create an account from environment variables. ```typescript import { setupWallet } from './src/utils/setup_wallet.js'; import { createAccountFromEnv } from './src/utils/create_account_from_env.js'; const wallet = await setupWallet(); const account = await createAccountFromEnv(wallet); const address = account.address; ``` -------------------------------- ### test-setup Source: https://github.com/aztecprotocol/aztec-starter/blob/next/ONBOARDING.md Setup function for pod racing contract tests. Returns: (TestEnvironment, contract_address, admin_address). Note: Create player accounts in individual tests to avoid oracle errors. ```rust // Setup function for pod racing contract tests // Returns: (TestEnvironment, contract_address, admin_address) // Note: Create player accounts in individual tests to avoid oracle errors pub unconstrained fn setup() -> (TestEnvironment, AztecAddress, AztecAddress) { let mut env = TestEnvironment::new(); let admin = env.create_light_account(); let initializer_call_interface = PodRacing::interface().constructor(admin); let contract_address = env.deploy("PodRacing").with_public_initializer(admin, initializer_call_interface); (env, contract_address, admin) } ``` -------------------------------- ### finalize_game() Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/pod-racing-contract.md Example of how to simulate and send a transaction to finalize a game. ```typescript // Simulate first await contract.methods.finalize_game(gameId).simulate({ from: anyAddress }); // Then send (can be called by anyone after game expires) await contract.methods.finalize_game(gameId).send({ from: anyAddress, fee: { paymentMethod }, wait: { timeout: 60000 } }); ``` -------------------------------- ### join_game() Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/pod-racing-contract.md Example of how to simulate and send a transaction to join a game. ```typescript // Simulate first await contract.methods.join_game(gameId).simulate({ from: player2Address }); // Then send await contract.methods.join_game(gameId).send({ from: player2Address, fee: { paymentMethod }, wait: { timeout: 60000 } }); ``` -------------------------------- ### Workflow 2: Interact with Deployed Contract Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/README.md Example of loading an account, connecting to a deployed contract, and playing the game. ```typescript // Load account from .env const wallet = await setupWallet(); const account = await createAccountFromEnv(wallet); // Connect to contract const contract = await PodRacingContract.at(contractAddress, wallet); // Play game await contract.methods.create_game(gameId).send({ from: account.address, fee: { paymentMethod } }); ``` -------------------------------- ### create_game() Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/pod-racing-contract.md Example of how to simulate and send a transaction to create a game. ```typescript import { Fr } from '@aztec/aztec.js/fields'; const gameId = Fr.random(); // Simulate first await contract.methods.create_game(gameId).simulate({ from: player1Address }); // Then send await contract.methods.create_game(gameId).send({ from: player1Address, fee: { paymentMethod }, wait: { timeout: 60000 } }); ``` -------------------------------- ### LogFn Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/types.md Example of defining and using a simple logging function type. ```typescript function myLog(message: string) { console.log(`[App] ${message}`); } await setupSponsoredFPC(wallet, myLog); ``` -------------------------------- ### Deploy an Account Source: https://github.com/aztecprotocol/aztec-starter/blob/next/docs/ONBOARDING.src.md Command to deploy an Aztec account. ```bash yarn deploy-account ``` -------------------------------- ### Deploy to Testnet Source: https://github.com/aztecprotocol/aztec-starter/blob/next/README.md Deploys contracts to the Aztec testnet. ```bash yarn deploy::testnet ``` -------------------------------- ### Troubleshooting: Set Up .env for Account Creation Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/scripts-reference.md Solution for 'Missing environment variable: SECRET' error, guiding the user to set up the .env file for account creation. ```bash # First deploy account to generate keys yarn deploy-account # Then add to .env: echo "SECRET=0x..." >> .env echo "SIGNING_KEY=0x..." >> .env echo "SALT=0x..." >> .env ``` -------------------------------- ### SponsoredFPCContractArtifact Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/types.md Example demonstrating how to register a Sponsored FPC contract artifact with the wallet. ```typescript import { SponsoredFPCContractArtifact } from '@aztec/noir-contracts.js/SponsoredFPC'; const sponsoredFPC = await getSponsoredFPCInstance(); await wallet.registerContract(sponsoredFPC, SponsoredFPCContractArtifact); ``` -------------------------------- ### Deploy to Local Network Source: https://github.com/aztecprotocol/aztec-starter/blob/next/README.md Deploys contracts to the local Aztec network. ```bash yarn deploy ``` -------------------------------- ### Logger Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/types.md Example demonstrating the creation and usage of a logger instance for structured logging. ```typescript import { createLogger } from '@aztec/foundation/log'; const logger = createLogger('my-component'); logger.info('Application started'); logger.error('An error occurred'); ``` -------------------------------- ### BlockNumber Example Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/types.md Example showing how to create a BlockNumber type and use it to fetch a block. ```typescript import { BlockNumber } from '@aztec/foundation/branded-types'; const blockNum = BlockNumber(1); const block = await node.getBlock(blockNum); ``` -------------------------------- ### deploy_account.ts Next Steps Source: https://github.com/aztecprotocol/aztec-starter/blob/next/_autodocs/api-reference/scripts-reference.md Instructions to save account keys to .env file. ```bash cat >> .env <