### Initialize a New DokoJS Project Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/cli/template/README.md Initializes a new DokoJS project with the specified project name. This command sets up the basic project structure and installs necessary dependencies. ```bash dokojs init ``` -------------------------------- ### Build and Install DokoJS from Source Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/cli/template/README.md Clones the DokoJS repository, installs dependencies using pnpm, builds the project, and then installs the CLI. Requires Git, Node.js, npm, and pnpm. ```bash # Download the source file git clone https://github.com/venture23-aleo/doko-js cd doko-js # Install the dependencies pnpm install # Build the project npm run build # Install dokojs npm run install:cli ``` -------------------------------- ### Install DokoJS CLI from NPM Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/cli/template/README.md Installs the DokoJS command-line interface globally using npm. Ensure Node.js and npm are installed. ```bash npm install -g @doko-js/cli@latest ``` -------------------------------- ### DokoJS Aleo Configuration Example Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/cli/template/README.md Configuration file for DokoJS, specifying Aleo accounts, execution mode, and network settings for testnet3 and mainnet. Requires environment variables for private keys. ```javascript import dotenv from 'dotenv'; dotenv.config(); export default { accounts: [process.env.ALEO_PRIVATE_KEY], mode: 'execute', mainnet: {}, networks: { testnet3: { endpoint: 'http://localhost:3030', accounts: [process.env.ALEO_PRIVATE_KEY_TESTNET3, process.env.ALEO_DEVNET_PRIVATE_KEY2] priorityFee: 0.01 }, mainnet: { endpoint: 'https://api.explorer.aleo.org/v1', accounts: [process.env.ALEO_PRIVATE_KEY_MAINNET], priorityFee: 0.001 } }, defaultNetwork: 'testnet3' }; ``` -------------------------------- ### DOKOJS CLI Usage Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Provides command-line interface instructions for the DokoJS tool, including options for displaying version information and help messages. ```bash dokojs [options] [command] Options: -V, --version output the version number -h, --help display help for command ``` -------------------------------- ### Get DokoJS Command Help Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Displays help information for DokoJS commands. Users can request general help or specific details about a particular command by providing the command name. ```bash dokojs help [command] ``` ```bash dokojs help deploy ``` -------------------------------- ### Initialize DokoJS Project Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Initializes a new DokoJS project. Optionally, a specific template can be used for project creation. This command sets up the basic structure for a new DokoJS application. ```bash dokojs init [--template ] ``` ```bash dokojs init my-project --template basic ``` -------------------------------- ### DokoJS CLI Help Output Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/cli/template/README.md Displays the help information for the DokoJS CLI, listing available commands and options. This output is generated when running `dokojs` without any arguments. ```bash ____ _ _ ____ | _ \ ___ | | _____ | / ___| | | | |/ _ \| |/ / _ \ _ | \___ \ | |_| | (_) | | (_) | |_| |___) | |____/ \___/|_|\_\___/ \___/|____/ Usage: dokojs [options] [command] DokoJS CLI Options: -V, --version output the version number -h, --help display help for command Commands: init [options] Initialize your DokoJS project add Add a new component or resource compile Compile your DokoJS project unflatten Create leo build for programs autogen Generate ts types for contracts - use only after the build has been generated run [options] Run file deploy [options] Deploy program execute Execute script help [command] display help for command ``` -------------------------------- ### DokoJS CLI Usage Help Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Displays the help information for the DokoJS CLI, outlining available commands and options. This is the primary interface for interacting with DokoJS functionalities. ```bash dokojs ``` -------------------------------- ### Install wasm-pack for WebAssembly Builds Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/wasm/README.md Provides the command to install `wasm-pack`, a toolchain manager for Rust and WebAssembly, which is necessary for building WebAssembly packages from Rust source code. ```bash curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh ``` -------------------------------- ### Run All Tests Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/cli/template/README.md Executes all tests defined in the project after successful compilation. This command utilizes npm to run the test suite, ensuring all components function as expected. ```bash npm run test ``` -------------------------------- ### Deploy DokoJS Program Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Deploys a DokoJS program to a specified network. Users can choose the target network (e.g., mainnet, testnet) using an option. This command facilitates the process of making programs live on the Aleo blockchain. ```bash dokojs deploy [--network ] ``` ```bash dokojs deploy my-program --network testnet ``` -------------------------------- ### BaseContract: Deploy Program (TypeScript) Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Deploys the Aleo program to the configured network using the snarkDeploy method. This is a core function of the BaseContract class. ```typescript const tx = await contract.deploy(); ``` -------------------------------- ### Compile DokoJS Project Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Compiles the DokoJS project into deployable or executable formats. An optional output directory can be specified to control where the compiled files are stored. This is a crucial step before deployment or further processing. ```bash dokojs compile [--output ] ``` ```bash dokojs compile --output ./dist ``` -------------------------------- ### BaseContract: Get Default Account (TypeScript) Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Fetches the address of the default account configured for the program. This is determined by the private key specified in the DokoJS configuration for the current environment. ```typescript const user1 = contract.getDefaultAccount(); ``` -------------------------------- ### Add Component/Resource to DokoJS Project Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Adds a new component or resource to an existing DokoJS project. This command simplifies the process of extending project functionality by creating necessary files and configurations. ```bash dokojs add ``` ```bash dokojs add my-program ``` -------------------------------- ### Run Specific Test File (Shorthand) Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/cli/template/README.md A more flexible way to run test files by providing a partial name. npm will execute all test files whose names match the provided string. ```bash npm run test -- sample ``` -------------------------------- ### Run Specific Test File Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/cli/template/README.md Allows running a specific test file by providing its name as an argument to the npm test command. This is useful for targeted testing and debugging. ```bash npm run test -- sample_program.test.ts ``` -------------------------------- ### DokoJS Network Configuration Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Defines network configurations for different environments (e.g., testnet, mainnet) including endpoint URLs, private keys, and priority fees. It allows specifying multiple accounts per network and setting a default network for local testing. ```javascript networks: { testnet: { endpoint: 'http://localhost:3030', accounts: [ process.env.ALEO_PRIVATE_KEY_TESTNET3, process.env.ALEO_DEVNET_PRIVATE_KEY2 ], priorityFee: 0.01 }, mainnet: { endpoint: 'https://api.explorer.aleo.org/v1', accounts: [process.env.ALEO_PRIVATE_KEY_MAINNET], priorityFee: 0.001 } } defaultNetwork: 'testnet' ``` -------------------------------- ### BaseContract: Get All Network Accounts (TypeScript) Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Retrieves an array of all Aleo account addresses associated with the program's configured network. These addresses are derived from the private keys specified in the network configuration. ```typescript const [admin, user1] = contract.getAccounts(); ``` -------------------------------- ### BaseContract: Get Private Key by Address (TypeScript) Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Searches for and returns the private key corresponding to a given Aleo account address. This is useful for operations requiring explicit key management. ```typescript const adminPrivateKey = contract.getPrivateKey(admin); ``` -------------------------------- ### Execute Specific Test File Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/cli/template/README.md This command executes a specific test file, ensuring that tests run in sequence and do not interfere with each other. It's useful for isolating test runs. ```bash npm test -- --runInBand token.test.ts ``` -------------------------------- ### DokoJS Configuration File (aleo-config.js) Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md A JavaScript configuration file for DokoJS, defining network endpoints, accounts, and execution modes. It supports multiple networks like testnet and mainnet, and allows for environment variable integration via dotenv. ```javascript import dotenv from 'dotenv'; dotenv.config(); export default { accounts: [process.env.ALEO_PRIVATE_KEY], mode: 'execute', mainnet: {}, networks: { testnet: { endpoint: 'http://localhost:3030', accounts: [process.env.ALEO_PRIVATE_KEY_TESTNET3, process.env.ALEO_DEVNET_PRIVATE_KEY2] priorityFee: 0.01 }, mainnet: { endpoint: 'https://api.explorer.aleo.org/v1', accounts: [process.env.ALEO_PRIVATE_KEY_MAINNET], priorityFee: 0.001 } }, defaultNetwork: 'testnet' }; ``` -------------------------------- ### Generate Leo Build Files Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Creates the necessary build files for Leo programs within a DokoJS project. This command is typically used after compilation to prepare Leo programs for deployment or execution on the Aleo network. ```bash dokojs unflatten ``` -------------------------------- ### Add or Modify a DokoJS Program Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/cli/template/README.md Command to add a new program file within the 'programs/' directory or to modify an existing one. Used in conjunction with creating new files manually. ```bash dokojs add [PROGRAM_NAME] ``` -------------------------------- ### Advanced Token Contract Testing (JavaScript) Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/cli/template/README.md This JavaScript code demonstrates advanced testing for the Token contract. It covers deployment, minting (public and private), and private transfers, utilizing Doko JS core functionalities and Aleo SDK for key management and decryption. ```javascript import { ExecutionMode } from '@doko-js/core'; import { TokenContract } from '../artifacts/js/token'; import { decrypttoken } from '../artifacts/js/leo2js/token'; import { PrivateKey } from '@provablehq/sdk'; const TIMEOUT = 200_000; // Available modes are evaluate | execute (Check README.md for further description) const mode = ExecutionMode.SnarkExecute; // Contract class initialization const contract = new TokenContract({ mode }); // This maps the accounts defined inside networks in aleo-config.js and return array of address of respective private keys const [admin] = contract.getAccounts(); const recipient = process.env.ALEO_DEVNET_PRIVATE_KEY3; describe('deploy test', () => { test('deploy', async () => { if ((mode as ExecutionMode) == ExecutionMode.SnarkExecute) { const tx = await contract.deploy(); await tx.wait(); } }, 10000000); test('mint public', async () => { const actualAmount = BigInt(100000); const tx = await contract.mint_public(admin, actualAmount); await tx.wait(); const expected = await contract.account(admin); expect(expected).toBe(actualAmount); }, 10000000); test('mint private', async () => { const actualAmount = BigInt(100000); const tx = await contract.mint_private( 'aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px', actualAmount ); const [record1] = await tx.wait(); // @NOTE Only decrypt in SnarkExecute use JSON.parse in LeoRun const decryptedRecord = decrypttoken( record1, process.env.ALEO_PRIVATE_KEY_TESTNET3 ); expect(decryptedRecord.amount).toBe(actualAmount); }, 10000000); test( 'private transfer to user', async () => { const account = contract.config.privateKey; const amount1 = BigInt(1000000000); const amount2 = BigInt(100000000); const mintTx = await contract.mint_private(admin, amount1); const [result] = await mintTx.wait(); const decryptedRecord = decrypttoken(result, account); const receiptAddress = PrivateKey.from_string(recipient) .to_address() .to_string(); const tx = await contract.transfer_private( decryptedRecord, receiptAddress, amount2 ); const [record1, record2] = await tx.wait(); const decryptedRecord2 = decrypttoken(record1, account); expect(decryptedRecord2.amount).toBe(amount1 - amount2); }, TIMEOUT ); }); ``` -------------------------------- ### Compile Doko JS Project Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/cli/template/README.md This command compiles the Doko JS project, creating an 'artifacts' folder containing compiled Leo packages and JavaScript type definitions and conversion utilities. It is essential for generating the necessary files for testing and deployment. ```bash dokojs compile ``` -------------------------------- ### Generate TypeScript Types for Contracts Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Generates TypeScript type definitions for smart contracts in the DokoJS project. This command should be run after the project has been compiled and the build artifacts are available, aiding in frontend or backend integration. ```bash dokojs autogen ``` -------------------------------- ### BaseContract: Check if Program is Deployed (TypeScript) Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Asynchronously checks if a program is currently deployed on the Aleo network. This method is part of the BaseContract class and returns a boolean promise. ```typescript let flag = await contract_name.isDeployed() ``` -------------------------------- ### Execute DokoJS Script Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Executes a script file located at a given path. This command is distinct from 'run' and may be used for specific script execution workflows, such as deployment scripts or batch operations. ```bash dokojs execute ``` ```bash dokojs execute scripts/deploy.js ``` -------------------------------- ### Run DokoJS File Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Executes a specified JavaScript file within the DokoJS environment. This command is useful for running scripts, tests, or utility functions defined in the project. Debug mode is often implied or configurable. ```bash dokojs run ``` ```bash dokojs run scripts/example.js ``` -------------------------------- ### BaseContract: Connect to Account (TypeScript) Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Updates the contract's active configuration to use the private key associated with a specified account address. This allows switching the context of subsequent operations. ```typescript contract.connect(admin); ``` -------------------------------- ### Get Aleo Accounts from Configuration with TypeScript Source: https://context7.com/venture23-aleo/doko-js/llms.txt Retrieves all account addresses defined in the network configuration using the TokenContract class. It requires the contract to be initialized. Dependencies include '@doko-js/core'. ```typescript import { TokenContract } from './artifacts/js/token'; import { ExecutionMode } from '@doko-js/core'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const [admin, user1, user2] = contract.getAccounts(); console.log('Admin address:', admin); console.log('User addresses:', user1, user2); ``` -------------------------------- ### Get Default Aleo Account with TypeScript Source: https://context7.com/venture23-aleo/doko-js/llms.txt Returns the default account address, which is derived from the configured private key, using the TokenContract class. Dependencies include '@doko-js/core'. ```typescript import { TokenContract } from './artifacts/js/token'; import { ExecutionMode } from '@doko-js/core'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const defaultAddress = contract.getDefaultAccount(); console.log('Default account:', defaultAddress); ``` -------------------------------- ### BaseContract: Wait for Transaction (TypeScript) Source: https://github.com/venture23-aleo/doko-js/blob/main/README.md Waits for a given transaction to complete on the Aleo network and resolves with the transaction response. Note: This method is deprecated in favor of using transaction receipts directly. ```typescript const tx = await contract.deploy(); await tx.wait(); ``` -------------------------------- ### Get Aleo Contract Address with TypeScript Source: https://context7.com/venture23-aleo/doko-js/llms.txt Retrieves the Aleo program address for a deployed contract using the TokenContract class. It requires the contract to be initialized. Dependencies include '@doko-js/core'. ```typescript import { TokenContract } from './artifacts/js/token'; import { ExecutionMode } from '@doko-js/core'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const programAddress = contract.address(); console.log('Contract address:', programAddress); // Output: aleo1xxx...xxx (program address) ``` -------------------------------- ### Get Private Key for Aleo Address with TypeScript Source: https://context7.com/venture23-aleo/doko-js/llms.txt Retrieves the private key corresponding to a specific account address using the TokenContract class. It requires the contract to be initialized and an account address. Dependencies include '@doko-js/core'. ```typescript import { TokenContract } from './artifacts/js/token'; import { ExecutionMode } from '@doko-js/core'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const [admin] = contract.getAccounts(); const privateKey = contract.getPrivateKey(admin); console.log('Admin private key:', privateKey); ``` -------------------------------- ### Initialize DokoJS Project CLI Command Source: https://context7.com/venture23-aleo/doko-js/llms.txt Initializes a new DokoJS project with a default or custom program structure. Supports verbose logging for debugging. This command sets up the basic project files and directories. ```bash dokojs init my-token-project dokojs init my-project --program custom_token dokojs init my-project --verbose debug ``` -------------------------------- ### Run Tests CLI Command Source: https://context7.com/venture23-aleo/doko-js/llms.txt Executes test files for DokoJS projects. Allows specifying a particular test file and network for execution. ```bash dokojs run test/token.test.ts dokojs run test/token.test.ts --network testnet ``` -------------------------------- ### Deploy Program to Aleo Network CLI Command Source: https://context7.com/venture23-aleo/doko-js/llms.txt Deploys a compiled Leo program to the Aleo network. Supports specifying the network (testnet, mainnet) and using different private keys from the configuration. ```bash dokojs deploy token dokojs deploy token --network mainnet dokojs deploy token --private-key-index 1 --network testnet ``` -------------------------------- ### Add Leo Program CLI Command Source: https://context7.com/venture23-aleo/doko-js/llms.txt Creates a new Leo program file within the 'programs' directory of a DokoJS project. This is used to structure and add new smart contracts to the project. ```bash dokojs add nft_contract ``` -------------------------------- ### Build WebAssembly Package with wasm-pack Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/wasm/README.md Demonstrates the command to build a Rust project into a WebAssembly package using `wasm-pack`. The `--target bundler` flag is used to configure the output for bundler environments. ```bash wasm-pack build --target bundler ``` -------------------------------- ### DokoJS Project Configuration (aleo-config.js) Source: https://context7.com/venture23-aleo/doko-js/llms.txt Configuration file for DokoJS projects, defining network endpoints, private keys, execution modes, and fee settings. Uses environment variables for sensitive information. ```javascript import dotenv from 'dotenv'; dotenv.config(); export default { accounts: [process.env.ALEO_PRIVATE_KEY], mode: 'execute', networks: { testnet: { endpoint: 'http://localhost:3030', accounts: [ process.env.ALEO_PRIVATE_KEY_TESTNET3, process.env.ALEO_DEVNET_PRIVATE_KEY2 ], priorityFee: 0.01 }, mainnet: { endpoint: 'https://api.explorer.aleo.org/v1', accounts: [ process.env.ALEO_PRIVATE_KEY_MAINNET ], priorityFee: 0.001 } }, defaultNetwork: 'testnet' }; ``` -------------------------------- ### Compile Leo Programs and Generate TypeScript CLI Commands Source: https://context7.com/venture23-aleo/doko-js/llms.txt Compiles Leo smart contracts and generates corresponding TypeScript types and interfaces. Commands include full compilation, Leo-only compilation, TypeScript generation, and debug output. ```bash dokojs compile dokojs unflatten dokojs autogen dokojs compile --verbose debug ``` -------------------------------- ### Execute Script CLI Command Source: https://context7.com/venture23-aleo/doko-js/llms.txt Runs deployment or execution scripts within a DokoJS project. This command is used for automating complex deployment or interaction sequences. ```bash dokojs execute scripts/deploy.ts ``` -------------------------------- ### Encryption and Decryption with @doko-js/wasm Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/wasm/README.md Demonstrates how to encrypt and decrypt values using the `@doko-js/wasm` library. It shows usage with both private keys and view keys for decryption, requiring network specification and Aleo program details. Ensure correct parameters for program, function name, input index, keys, and network. ```javascript import { Encrypter, Decrypter } from '@doko-js/wasm'; // Encryption Example const encryptedValue = Encrypter.get_encrypted_value( "3u32", "types_test.aleo", "sum", 2, // input index "APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH", "4894085870840878070008938887517642593787940398952348563490477594935969679255group", "testnet" // or "mainnet" ); console.log("Encrypted value:", encryptedValue); // Decryption Example const decryptedValuePK = Decrypter.get_decrypted_value( "ciphertext1qyqv5fj8jc4enpvl8xdkxllvdhxe49qz3mn72xmr574ve5n4qtuawpgs4egw3", "types_test.aleo", "sum", 2, // input index "APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH", "4894085870840878070008938887517642593787940398952348563490477594935969679255group", "testnet" // or "mainnet" ); console.log("Decrypted value using private key:", decryptedValuePK); const decryptedValueVK = Decrypter.get_decrypted_value_using_view_key( "ciphertext1qyqv5fj8jc4enpvl8xdkxllvdhxe49qz3mn72xmr574ve5n4qtuawpgs4egw3", "types_test.aleo", "sum", 2, // input index "AViewKey1mSnpFFC8Mj4fXbK5YiWgZ3mjiV8CxA79bYNa8ymUpTrw", "4894085870840878070008938887517642593787940398952348563490477594935969679255group", "testnet" // or "mainnet" ); console.log("Decrypted value using view key:", decryptedValueVK); ``` -------------------------------- ### Transaction and Execution API Source: https://context7.com/venture23-aleo/doko-js/llms.txt This section covers the API for executing contract transitions, including different modes and output handling. ```APIDOC ## Execute contract transition (SnarkExecute mode) Generates proof, broadcasts transaction to blockchain, and returns transaction response with encrypted outputs. ### Method `POST` (Implicit, as part of contract method execution) ### Endpoint N/A (Method on contract instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Parameters are passed to the contract method) ### Request Example ```typescript import { ExecutionMode } from '@doko-js/core'; import { TokenContract } from './artifacts/js/token'; import { decrypttoken } from './artifacts/js/leo2js/token'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const [admin] = contract.getAccounts(); const amount = BigInt(1000000); // Execute transition const tx = await contract.mint_public(admin, amount); // Wait for transaction confirmation await tx.wait(); // Query on-chain mapping const balance = await contract.account(admin); console.log('Balance:', balance); // 1000000n // Get transaction details const transaction = await tx.getTransaction(); console.log('Transaction ID:', transaction?.id); // Get block height const height = await tx.blockHeight(); console.log('Block height:', height); ``` ### Response #### Success Response (200) `TransactionResponse` object containing transaction details and confirmation status. #### Response Example ```json { "id": "txid...", "height": 12345, "status": "success" } ``` ``` ```APIDOC ## Execute with private outputs Handles private record outputs with automatic decryption. ### Method `POST` (Implicit, as part of contract method execution) ### Endpoint N/A (Method on contract instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Parameters are passed to the contract method) ### Request Example ```typescript import { ExecutionMode } from '@doko-js/core'; import { TokenContract } from './artifacts/js/token'; import { decrypttoken } from './artifacts/js/leo2js/token'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const recipient = 'aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px'; const amount = BigInt(500000); // Mint private tokens const tx = await contract.mint_private(recipient, amount); const [encryptedRecord] = await tx.wait(); // Decrypt record const decryptedRecord = decrypttoken( encryptedRecord, process.env.ALEO_PRIVATE_KEY_TESTNET3 ); console.log('Token owner:', decryptedRecord.owner); console.log('Token amount:', decryptedRecord.amount); // Output: Token amount: 500000n ``` ### Response #### Success Response (200) Decrypted private outputs (e.g., records). #### Response Example ```json { "owner": "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "amount": "500000" } ``` ``` ```APIDOC ## Execute with custom output converters Automatically convert transaction outputs using type converters. ### Method `POST` (Implicit, as part of contract method execution) ### Endpoint N/A (Method on contract instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Parameters are passed to the contract method) ### Request Example ```typescript import { ExecutionMode } from '@doko-js/core'; import { TokenContract } from './artifacts/js/token'; import { leo2js } from './artifacts/js/leo2js'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const recipient = 'aleo1xxx...xxx'; const amount = BigInt(100000); // Execute transition const tx = await contract.mint_private(recipient, amount); // Set converter functions for outputs tx.set_converter_fn([ // First output is a record, second is amount leo2js.record, leo2js.u64 ]); // Wait returns converted outputs const [record, confirmedAmount] = await tx.wait(); console.log('Confirmed amount (as bigint):', confirmedAmount); ``` ### Response #### Success Response (200) Converted transaction outputs based on the provided converter functions. #### Response Example ```json // Example output based on the converters used [ { "owner": "aleo1xxx...xxx", "amount": "100000" }, 100000n ] ``` ``` ```APIDOC ## Execute in local evaluation mode (LeoRun) Runs transition locally without generating proofs or broadcasting to network. ### Method `POST` (Implicit, as part of contract method execution) ### Endpoint N/A (Method on contract instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Parameters are passed to the contract method) ### Request Example ```typescript import { ExecutionMode } from '@doko-js/core'; import { TokenContract } from './artifacts/js/token'; const contract = new TokenContract({ mode: ExecutionMode.LeoRun }); const [admin] = contract.getAccounts(); const amount = BigInt(1000000); // Execute locally (no blockchain interaction) const tx = await contract.mint_public(admin, amount); const outputs = await tx.wait(); console.log('Local execution outputs:', outputs); // Transaction not broadcast to network ``` ### Response #### Success Response (200) An array of outputs from the local execution. #### Response Example ```json // Example outputs from local execution [ // ... outputs based on the mint_public transition logic ] ``` ``` -------------------------------- ### Hashing with Keccak256 in Doko-JS Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/wasm/README.md Demonstrates how to use the Hasher utility in Doko-JS to hash an input value using the keccak256 algorithm. It specifies the input value, desired output type, and the network environment (testnet or mainnet). ```javascript const hashedValue = Hasher.hash( "keccak256", // algorithm "{arr: [1u8, 1u8], size: 2u8}", // input value "address", // output type "testnet" // or "mainnet ); console.log("Hashed value:", hashedValue); ``` -------------------------------- ### Execute Contract Transition (SnarkExecute Mode) Source: https://context7.com/venture23-aleo/doko-js/llms.txt Generates a proof, broadcasts a transaction to the Aleo blockchain, and returns the transaction response including encrypted outputs. This mode is used for on-chain execution. ```typescript import { ExecutionMode } from '@doko-js/core'; import { TokenContract } from './artifacts/js/token'; import { decrypttoken } from './artifacts/js/leo2js/token'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const [admin] = contract.getAccounts(); const amount = BigInt(1000000); // Execute transition const tx = await contract.mint_public(admin, amount); // Wait for transaction confirmation await tx.wait(); // Query on-chain mapping const balance = await contract.account(admin); console.log('Balance:', balance); // 1000000n // Get transaction details const transaction = await tx.getTransaction(); console.log('Transaction ID:', transaction?.id); // Get block height const height = await tx.blockHeight(); console.log('Block height:', height); ``` -------------------------------- ### Initialize BaseContract Class in TypeScript Source: https://context7.com/venture23-aleo/doko-js/llms.txt Initializes the base contract class for Aleo smart contracts using DokoJS. Allows specifying execution mode, network name, and a specific private key for contract interactions. ```typescript import { ExecutionMode } from '@doko-js/core'; import { TokenContract } from './artifacts/js/token'; // Initialize with execution mode const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); // Initialize with custom network const contract = new TokenContract({ mode: ExecutionMode.LeoRun, networkName: 'mainnet' }); // Initialize with specific private key const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute, privateKey: process.env.CUSTOM_PRIVATE_KEY }); ``` -------------------------------- ### Complete Token Contract Test Suite with Doko.js Source: https://context7.com/venture23-aleo/doko-js/llms.txt A comprehensive test suite for a token contract, showcasing deployment, public minting, private minting, and private transfers using Doko.js. It includes various test cases with assertions to verify contract functionality. ```typescript import { ExecutionMode } from '@doko-js/core'; import { TokenContract } from '../artifacts/js/token'; import { decrypttoken } from '../artifacts/js/leo2js/token'; import { PrivateKey } from '@provablehq/sdk'; const TIMEOUT = 200_000; const mode = ExecutionMode.SnarkExecute; const contract = new TokenContract({ mode }); const [admin] = contract.getAccounts(); const recipient = process.env.ALEO_DEVNET_PRIVATE_KEY3; describe('Token Contract Tests', () => { test('deploy contract', async () => { if (mode === ExecutionMode.SnarkExecute) { const tx = await contract.deploy(); await tx.wait(); const deployed = await contract.isDeployed(); expect(deployed).toBe(true); } }, 10000000); test('mint public tokens', async () => { const amount = BigInt(100000); const tx = await contract.mint_public(admin, amount); await tx.wait(); const balance = await contract.account(admin); expect(balance).toBe(amount); }, 10000000); test('mint private tokens', async () => { const amount = BigInt(100000); const tx = await contract.mint_private( 'aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px', amount ); const [record] = await tx.wait(); const decryptedRecord = decrypttoken( record, process.env.ALEO_PRIVATE_KEY_TESTNET3 ); expect(decryptedRecord.amount).toBe(amount); }, 10000000); test('transfer private tokens', async () => { const account = contract.config.privateKey; const amount1 = BigInt(1000000000); const amount2 = BigInt(100000000); const mintTx = await contract.mint_private(admin, amount1); const [result] = await mintTx.wait(); const decryptedRecord = decrypttoken(result, account); const recipientAddress = PrivateKey.from_string(recipient) .to_address() .to_string(); const tx = await contract.transfer_private( decryptedRecord, recipientAddress, amount2 ); const [record1, record2] = await tx.wait(); const decryptedRecord2 = decrypttoken(record1, account); expect(decryptedRecord2.amount).toBe(amount1 - amount2); }, TIMEOUT); }); ``` -------------------------------- ### Transfer Private Tokens with Doko.js Source: https://context7.com/venture23-aleo/doko-js/llms.txt Demonstrates consuming input records and producing output records for private token transfers. It involves minting private tokens, then transferring a portion to a recipient address, and finally logging the change amount. ```typescript import { ExecutionMode } from '@doko-js/core'; import { TokenContract } from './artifacts/js/token'; import { decrypttoken } from './artifacts/js/leo2js/token'; import { PrivateKey } from '@provablehq/sdk'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const [admin] = contract.getAccounts(); const recipient = process.env.ALEO_DEVNET_PRIVATE_KEY3; const mintAmount = BigInt(1000000000); const transferAmount = BigInt(100000000); // Mint private tokens const mintTx = await contract.mint_private(admin, mintAmount); const [mintedRecord] = await mintTx.wait(); const decryptedRecord = decrypttoken(mintedRecord, contract.config.privateKey); // Transfer tokens const recipientAddress = PrivateKey.from_string(recipient) .to_address() .to_string(); const transferTx = await contract.transfer_private( decryptedRecord, recipientAddress, transferAmount ); // Wait returns [change_record, recipient_record] const [changeRecord, recipientRecord] = await transferTx.wait(); const change = decrypttoken(changeRecord, contract.config.privateKey); console.log('Change amount:', change.amount); // Output: 900000000n (1000000000 - 100000000) ``` -------------------------------- ### Leo Type Conversion (leo2js) Source: https://context7.com/venture23-aleo/doko-js/llms.txt This section details how to convert Leo-formatted output strings back to JavaScript primitives using the `leo2js` utility. ```APIDOC ## Convert Leo types to JavaScript types (leo2js) Converts Leo-formatted output strings back to JavaScript primitives. ### Method Not applicable (Utility function) ### Endpoints Not applicable (Utility functions) ### Parameters Each `leo2js` function takes a string or array of strings representing Leo types as input. #### Query Parameters None #### Request Body None ### Request Example ```typescript import { leo2js } from './artifacts/js/leo2js'; // Parse unsigned integers const u8Result = leo2js.u8('255u8'); // 255 const u16Result = leo2js.u16('65535u16'); // 65535 const u32Result = leo2js.u32('4294967295u32'); // 4294967295 const u64Result = leo2js.u64('18446744073709551615u64'); // 18446744073709551615n (bigint) const u128Result = leo2js.u128('340282366920938463463374607431768211455u128'); // bigint // Parse signed integers const i32Result = leo2js.i32('-2147483648i32'); // -2147483648 const i64Result = leo2js.i64('-9223372036854775808i64'); // bigint // Parse boolean const boolResult = leo2js.boolean('true'); // true // Parse field elements const fieldResult = leo2js.field('12345field'); // 12345n (bigint) const scalarResult = leo2js.scalar('67890scalar'); // 67890n (bigint) // Parse address const addressResult = leo2js.address('aleo1xxx...xxx.private'); // "aleo1xxx...xxx" // Parse arrays const arrayResult = leo2js.array(['1u32', '2u32', '3u32'], leo2js.u32); // [1, 2, 3] ``` ### Response Returns the corresponding JavaScript primitive type. ``` -------------------------------- ### Execute with Custom Output Converters Source: https://context7.com/venture23-aleo/doko-js/llms.txt Allows automatic conversion of transaction outputs by specifying custom converter functions, such as 'leo2js.record' or 'leo2js.u64'. This simplifies handling complex output types directly from the 'tx.wait()' call. ```typescript import { ExecutionMode } from '@doko-js/core'; import { TokenContract } from './artifacts/js/token'; import { leo2js } from './artifacts/js/leo2js'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const recipient = 'aleo1xxx...xxx'; const amount = BigInt(100000); // Execute transition const tx = await contract.mint_private(recipient, amount); // Set converter functions for outputs tx.set_converter_fn([ // First output is a record, second is amount leo2js.record, leo2js.u64 ]); // Wait returns converted outputs const [record, confirmedAmount] = await tx.wait(); console.log('Confirmed amount (as bigint):', confirmedAmount); ``` -------------------------------- ### Execute in Local Evaluation Mode (LeoRun) Source: https://context7.com/venture23-aleo/doko-js/llms.txt Runs an Aleo transition locally without generating proofs or interacting with the blockchain network. This is useful for rapid testing and debugging of contract logic. ```typescript import { ExecutionMode } from '@doko-js/core'; import { TokenContract } from './artifacts/js/token'; const contract = new TokenContract({ mode: ExecutionMode.LeoRun }); const [admin] = contract.getAccounts(); const amount = BigInt(1000000); // Execute locally (no blockchain interaction) const tx = await contract.mint_public(admin, amount); const outputs = await tx.wait(); console.log('Local execution outputs:', outputs); // Transaction not broadcast to network ``` -------------------------------- ### Execute with Private Outputs and Decryption Source: https://context7.com/venture23-aleo/doko-js/llms.txt Handles execution of Aleo transitions that produce private record outputs. It automatically decrypts these records using provided private keys, enabling access to the private data. ```typescript import { ExecutionMode } from '@doko-js/core'; import { TokenContract } from './artifacts/js/token'; import { decrypttoken } from './artifacts/js/leo2js/token'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const recipient = 'aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px'; const amount = BigInt(500000); // Mint private tokens const tx = await contract.mint_private(recipient, amount); const [encryptedRecord] = await tx.wait(); // Decrypt record const decryptedRecord = decrypttoken( encryptedRecord, process.env.ALEO_PRIVATE_KEY_TESTNET3 ); console.log('Token owner:', decryptedRecord.owner); console.log('Token amount:', decryptedRecord.amount); // Output: Token amount: 500000n ``` -------------------------------- ### Deploy Aleo Contract with TypeScript Source: https://context7.com/venture23-aleo/doko-js/llms.txt Deploys an Aleo contract to the blockchain network using the TokenContract class. It returns a transaction response and waits for the deployment to complete. Dependencies include '@doko-js/core'. ```typescript import { TokenContract } from './artifacts/js/token'; import { ExecutionMode } from '@doko-js/core'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); // Deploy contract const deployTx = await contract.deploy(); await deployTx.wait(); console.log('Contract deployed successfully'); console.log('Program address:', contract.address()); ``` -------------------------------- ### Check Contract Deployment Status in TypeScript Source: https://context7.com/venture23-aleo/doko-js/llms.txt Verifies if a smart contract is deployed on the configured Aleo network using DokoJS. Returns a boolean indicating the deployment status. ```typescript import { TokenContract } from './artifacts/js/token'; import { ExecutionMode } from '@doko-js/core'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const isDeployed = await contract.isDeployed(); if (isDeployed) { console.log('Token contract is deployed'); } else { console.log('Contract not found on network'); } ``` -------------------------------- ### Convert Program ID to Aleo Address using Doko-JS Wasm Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/wasm/README.md Shows how to convert a program ID string to an Aleo blockchain address using the `to_address` function from the Doko-JS WebAssembly module. This function requires the program name and the Aleo network type. ```javascript import init, { to_address } from '@doko-js/wasm'; // Convert Program ID to Address const programName = "credits.aleo"; // Replace with your program ID const ID = to_address(programName, "testnet"); console.log("ID:", address); ``` -------------------------------- ### Switch Aleo Contract Signer with TypeScript Source: https://context7.com/venture23-aleo/doko-js/llms.txt Changes the active private key used for signing transactions by connecting to a different account using the TokenContract class. Dependencies include '@doko-js/core'. ```typescript import { TokenContract } from './artifacts/js/token'; import { ExecutionMode } from '@doko-js/core'; const contract = new TokenContract({ mode: ExecutionMode.SnarkExecute }); const [admin, user1] = contract.getAccounts(); // Initially using admin account console.log('Current account:', contract.getDefaultAccount()); // Switch to user1 contract.connect(user1); console.log('Switched to:', contract.getDefaultAccount()); ``` -------------------------------- ### Hashing with @doko-js/wasm Source: https://github.com/venture23-aleo/doko-js/blob/main/packages/wasm/README.md Utilizes the `Hasher.hash` function from `@doko-js/wasm` to perform cryptographic hashing on input data. Supports a wide range of hashing algorithms and output types, requiring the algorithm, value, output type, and network to be specified. The function returns the hashed value as a string. ```javascript import { Hasher } from '@doko-js/wasm'; // Hashing Example const hashedValue = Hasher.hash( "keccak256", // Hashing algorithm "some_input_data", // Value to hash "address", // Output type "testnet" // Network ); console.log("Hashed value:", hashedValue); ``` -------------------------------- ### Convert Leo Types to JavaScript (leo2js) Source: https://context7.com/venture23-aleo/doko-js/llms.txt Provides functions to parse Leo-formatted output strings back into JavaScript primitive types, including integers, booleans, field elements, addresses, and arrays. It handles conversions to JavaScript numbers, BigInts, and strings as appropriate. ```typescript import { leo2js } from './artifacts/js/leo2js'; // Parse unsigned integers const u8Result = leo2js.u8('255u8'); // 255 const u16Result = leo2js.u16('65535u16'); // 65535 const u32Result = leo2js.u32('4294967295u32'); // 4294967295 const u64Result = leo2js.u64('18446744073709551615u64'); // 18446744073709551615n (bigint) const u128Result = leo2js.u128('340282366920938463463374607431768211455u128'); // bigint // Parse signed integers const i32Result = leo2js.i32('-2147483648i32'); // -2147483648 const i64Result = leo2js.i64('-9223372036854775808i64'); // bigint // Parse boolean const boolResult = leo2js.boolean('true'); // true // Parse field elements const fieldResult = leo2js.field('12345field'); // 12345n (bigint) const scalarResult = leo2js.scalar('67890scalar'); // 67890n (bigint) // Parse address const addressResult = leo2js.address('aleo1xxx...xxx.private'); // "aleo1xxx...xxx" // Parse arrays const arrayResult = leo2js.array(['1u32', '2u32', '3u32'], leo2js.u32); // [1, 2, 3] ```