### Install and Setup React Integration for Leo App Source: https://context7.com/context7/leo-lang/llms.txt Guides users through setting up a new Leo project with a React template. This involves creating the project using npm, navigating into the project directory, installing dependencies, and starting the development server. ```bash # Create new project with React template npm create leo-app@latest # Navigate and setup cd aleo-project npm install npm run install-leo npm run dev # Opens http://localhost:5173 ``` -------------------------------- ### Install and Run Leo Project - Shell Source: https://docs.leo-lang.org/sdk/create-leo-app/tutorial Commands to install project dependencies, setup Leo, and run the React development server. This process ensures all necessary modules and the Leo environment are ready for development. ```shell cd aleo-project npm install npm run install-leo npm run dev ``` -------------------------------- ### Run Leo Executable Source: https://docs.leo-lang.org/getting_started/installation Command to execute the Leo language interpreter or compiler after installation. ```bash leo ``` -------------------------------- ### Install Leo Pre-built Binary on macOS Source: https://docs.leo-lang.org/getting_started/installation Installs the Leo executable from pre-built binaries for macOS. This involves downloading a zip file, extracting it, making the executable, and moving it to a system-wide directory. ```bash mv leo /usr/local/bin ``` -------------------------------- ### Verify Git and Cargo Installation Source: https://docs.leo-lang.org/getting_started/installation Commands to verify that Git and Cargo (Rust's package manager) are installed correctly. These are prerequisites for building Leo from source. ```bash git --version ``` ```bash cargo --version ``` -------------------------------- ### Build Leo from Source Code Source: https://docs.leo-lang.org/getting_started/installation Clones the Leo source code repository from GitHub and builds/installs it using Cargo. This method allows users to access the latest features. The executable will be available at `~/.cargo/bin/leo`. ```bash # Download the source code git clone https://github.com/ProvableHQ/leo cd leo # Build and install cargo install --path . ``` -------------------------------- ### Install Leo using Cargo Source: https://docs.leo-lang.org/getting_started/installation Installs the Leo language executable using the Cargo package manager. This is the recommended method for most users. The executable will be available at `~/.cargo/bin/leo`. ```bash cargo install leo-lang ``` -------------------------------- ### Run Basic Bank Example Script Source: https://docs.leo-lang.org/leo_by_example/basic_bank This script navigates to the basic bank example directory and executes the run script. Ensure Leo is installed and follow the installation instructions before running. This script is used to execute Leo program functions locally for issuing, depositing, and withdrawing tokens. ```bash cd leo/examples/basic_bank ./run.sh ``` -------------------------------- ### Run Token Example Script Source: https://docs.leo-lang.org/leo_by_example/token Executes the token program to mint and transfer tokens publicly and privately. Requires Leo installation and depends on a .env file for private key and network configuration. ```bash cd leo/examples/token ./run.sh ``` -------------------------------- ### Lint Leo Code with Clippy Source: https://docs.leo-lang.org/language/style Runs Clippy, a Rust linter, on the entire project, including all features, examples, and benchmarks. This helps identify potential code errors and style issues. ```bash cargo clippy --all-features --examples --all --benches ``` -------------------------------- ### Install Leo from Pre-Built Binaries (MacOS) Source: https://context7.com/context7/leo-lang/llms.txt Installs Leo on MacOS by downloading and extracting pre-built binaries. This method is suitable if you prefer not to build from source or use Cargo. It involves downloading a zip file, making the binary executable, and moving it to a system path, followed by verification. ```bash # Download and extract the .zip file containing leo binary chmod +x leo sudo mv leo /usr/local/bin # Verify installation leo --version ``` -------------------------------- ### Install Leo via Cargo Source: https://context7.com/context7/leo-lang/llms.txt Installs the Leo programming language using the Rust package manager, Cargo. This method ensures you get the latest stable version. It first installs Rust if not already present, then installs Leo, and finally verifies the installation. ```bash # Install latest stable Rust first curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Install Leo cargo install leo-lang # Verify installation leo --version ``` -------------------------------- ### Build Leo from Source Source: https://context7.com/context7/leo-lang/llms.txt Builds and installs the Leo programming language from its source code repository on GitHub. This requires Git and Cargo to be installed. It clones the repository, navigates into the directory, and then installs Leo using Cargo. ```bash # Prerequisites: git and cargo git clone https://github.com/ProvableHQ/leo cd leo cargo install --path . # Verify installation leo --version ``` -------------------------------- ### Install Rusty Hook Source: https://docs.leo-lang.org/language/style Installs the Rusty Hook tool using Cargo, a package manager for Rust. This tool is likely used for managing pre-commit hooks or other development workflow enhancements. ```bash cargo install rusty-hook ``` -------------------------------- ### Leo: Valid Board Configuration Example (u64) Source: https://docs.leo-lang.org/leo_by_example/battleship Presents an example of a valid Battleship board configuration represented as a u64 bitstring. This configuration demonstrates a possible arrangement of ships that adheres to placement rules. ```Leo 17870284429256033024u64 ``` -------------------------------- ### Debugging Timelocked Credits with Leo Debugger Source: https://docs.leo-lang.org/guides/debuggin Guides users to navigate to the 'timelocked_credits' example and use the Leo debugger to simulate depositing and withdrawing credits, including managing the state of the 'account' mapping and advancing block height. ```bash cd workshop/learn_to_debug/timelocked_credits leo debug ``` -------------------------------- ### Start Leo Interactive Debugger Source: https://docs.leo-lang.org/cli/overview Initiates the interactive debugger for a Leo project. Once started, users can interact with the debugger using commands like `#help`. ```bash > leo debug ``` -------------------------------- ### Leo: Complex Valid Board Configuration Example (u64) Source: https://docs.leo-lang.org/leo_by_example/battleship Illustrates a more complex valid Battleship board configuration represented by a u64 bitstring. This example helps visualize how multiple ships can be validly placed on the board. ```Leo 2157505700798988545u64 ``` -------------------------------- ### Run Specific Leo Program Functions - Shell Source: https://docs.leo-lang.org/sdk/create-leo-app/tutorial Commands to execute specific functions within a Leo program, providing input variables. These examples demonstrate running the 'main' function with integer inputs. ```shell leo run main 1u32 2u32 leo execute main 1u32 2u32 ``` -------------------------------- ### Install tmux on Ubuntu Source: https://docs.leo-lang.org/testing/devnet Installs the `tmux` terminal multiplexer on Ubuntu and other Debian-based systems using the `apt` package manager. This is necessary for managing the devnet environment. ```bash sudo apt update sudo apt install tmux ``` -------------------------------- ### Checksum-Driven Constructor in Leo (Vote Example) Source: https://docs.leo-lang.org/guides/upgradability Implements a checksum-driven upgrade policy where authority is delegated to a governance program managing approved code checksums. The 'constructor' uses mapping and key fields to look up the approved checksum from another Leo program. ```leo // The 'vote_example' program. program vote_example.aleo { // This constructor is for the "checksum" mode. @checksum(mapping="basic_voting.aleo/approved_checksum", key="true") async constructor() { // The Leo compiler automatically generates the constructor logic. } transition main(public a: u32, b: u32) -> u32 { let c: u32 = a + b; return c; } } ``` ```avm constructor: branch.eq edition 0u16 to end; get basic_voting.aleo/approved_checksum[true] into r0; assert.eq checksum r0; position end; ``` -------------------------------- ### Initialize Leo Debugger Source: https://docs.leo-lang.org/guides/debuggin Starts the Leo interpreter in a REPL mode, allowing standalone Leo code execution and interaction. ```bash leo debug ``` -------------------------------- ### Execute start_battleship with player offers Source: https://docs.leo-lang.org/leo_by_example/battleship This snippet demonstrates how to execute the `start_battleship` function using Leo's command-line interface. It takes two records as input: one representing player offers and another for the opponent's offer. The function updates the game state, marking the game as started and preparing Player 1 to make their first move. ```leo leo run start_battleship "{ owner: aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry.private, hits_and_misses: 0u64.private, played_tiles: 0u64.private, ships: 9044591273705727u64.private, player_1: aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry.private, player_2: aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy.private, game_started: false.private, _nonce: 677929557867990662961068737825412945684193990901139603462104629310061710321group.public }" "{ owner: aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry.private, incoming_fire_coordinate: 0u64.private, player_1: aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy.private, player_2: aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry.private, prev_hit_or_miss: 0u64.private, _nonce: 6306786918362462465996698473371289503655844751914031374264794338640697795225group.public }" ``` -------------------------------- ### Run Tic-Tac-Toe Game Script Source: https://docs.leo-lang.org/leo_by_example/tictactoe This bash script executes the Leo Tic-Tac-Toe program locally. It navigates to the project directory and runs the main script to start a game. Ensure Leo is installed and the tictactoe program is set up. ```bash cd tictactoe ./run.sh ``` -------------------------------- ### Aleo Devnet .env Configuration Source: https://docs.leo-lang.org/testing/devnet Example `.env` file configuration required for deploying programs to a local Aleo devnet. It specifies the network, private key, and API endpoint. ```dotenv NETWORK=testnet PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH ENDPOINT=http://localhost:3030 ``` -------------------------------- ### Leo: Another Valid Board Configuration Example (u64) Source: https://docs.leo-lang.org/leo_by_example/battleship Provides another example of a valid Battleship board configuration using a u64 bitstring. This showcases a different valid ship placement, reinforcing the concept of proper board states. ```Leo 16383u64 ``` -------------------------------- ### Install tmux on macOS Source: https://docs.leo-lang.org/testing/devnet Installs the `tmux` terminal multiplexer on macOS using the Homebrew package manager. This is a prerequisite for running the Aleo local devnet. ```bash # Once Homebrew is installed, run: brew install tmux ``` -------------------------------- ### Running Leo Tests by Substring Source: https://docs.leo-lang.org/testing/test_framework Command to run multiple Leo tests that match a given substring. This example demonstrates running tests related to addition by using the substring 'addition' or 'simple'. ```bash leo test simple ``` ```bash leo test addition ``` -------------------------------- ### Leo Program Structure Example Source: https://docs.leo-lang.org/language/structure Demonstrates the complete structure of a Leo program, including imports, program declaration, constants, mappings, records, structs, async transition functions, and helper functions. This serves as a comprehensive template for Leo program development. ```leo import foo.aleo; program hello.aleo { const FOO: u64 = 1u64; mapping account: address => u64; record Token { owner: address, amount: u64, } struct Message { sender: address, object: u64, } async transition mint_public( public receiver: address, public amount: u64, ) -> (Token, Future) { return (Token { owner: receiver, amount, }, update_state(receiver, amount)); } async function update_state( public receiver: address, public amount: u64, ) { let current_amount: u64 = Mapping::get_or_use(account, receiver, 0u64); Mapping::set(account, receiver, current_amount + amount); } function compute(a: u64, b: u64) -> u64 { return a + b + FOO; } } ``` -------------------------------- ### Run All Project Tests Source: https://docs.leo-lang.org/language/style Executes all tests for the Leo project, including those that might be skipped in a CI environment, and continues running tests even if one fails. This is crucial for verifying new functionality. ```bash cargo test --all --features ci_skip --no-fail-fast ``` -------------------------------- ### Deploy Programs with Local Dependencies Recursively Source: https://context7.com/context7/leo-lang/llms.txt Shows how to deploy Aleo programs that have local dependencies. The `--recursive` flag ensures that all dependencies are deployed in order. The example includes a typical project structure with a local dependency. ```bash # Project structure with dependency: # example_program/ # ├── local_dependency/ # │ ├── src/main.leo # │ ├── .env # │ └── program.json # ├── src/main.leo # ├── .env # └── program.json # Deploy all dependencies recursively leo deploy --recursive # Prompts for each program: # ? Do you want to submit deployment of program `local_dependency.aleo` # to network testnet via endpoint http://localhost:3030 # using address aleo1...? (y/n) ``` -------------------------------- ### Run Leo Voting Program Example (Bash) Source: https://docs.leo-lang.org/leo_by_example/vote This bash script executes the Leo voting program functions locally. It sets up the environment by configuring the `.env` file with network type and private key, then runs the `propose` transition function. ```bash cd leo/examples/vote ./run.sh ``` ```bash echo " NETWORK=testnet PRIVATE_KEY=APrivateKey1zkp8wKHF9zFX1j4YJrK3JhxtyKDmPbRu9LrnEW8Ki56UQ3G " > .env leo run propose "{ title: 2077160157502449938194577302446444field, content: 1452374294790018907888397545906607852827800436field, proposer: aleo1rfez44epy0m7nv4pskvjy6vex64tnt0xy90fyhrg49cwe0t9ws8sh6nhhr }" ``` -------------------------------- ### Leo: Program Structure with Imports and Declarations Source: https://docs.leo-lang.org/language/style Demonstrates the correct layout for a Leo program, including import statements, blank lines for separation, and the order of program declarations like structs and functions. This follows the recommended structure for readability and maintainability. ```leo import std.io.Write; import std.math.Add; program prog.aleo { struct A { // ... } function foo() { // ... } } ``` -------------------------------- ### Save Aleo Account to .env File Source: https://context7.com/context7/leo-lang/llms.txt Creates a new Aleo account and automatically saves its private key and network configuration to a `.env` file. This is convenient for project setup, ensuring that deployment and execution commands can access the necessary credentials. ```bash # Create account and write to .env leo account new --write # .env file content: # NETWORK=testnet # PRIVATE_KEY=APrivateKey1zkp... ``` -------------------------------- ### Leo: Struct and Transition Syntax Source: https://docs.leo-lang.org/language/style Illustrates the Leo syntax for defining structs and transitions, including the placement of opening braces on the same line as the declaration. This adheres to the standard brace style in Leo. ```leo struct A { // ... } transition main() { // ... } let a: A = A { }; ``` -------------------------------- ### Send Aleo Credits via Discord - Shell Source: https://docs.leo-lang.org/sdk/create-leo-app/tutorial Example command format for requesting Aleo credits from the faucet via Discord. This requires specifying the Aleo public address and the amount of credits to request. Usage is limited to one request every 20 minutes and 50 credits per hour. ```shell /sendcredits aleo1k53lck74r93q70ftjvpkmnl5h9uwcna5wqyt80ggmz5w7lck8syskpxj46 20 ``` -------------------------------- ### Format Leo Code with Cargo Source: https://docs.leo-lang.org/language/style Formats all code within the project using the nightly version of the Rust toolchain. This ensures consistent code style across the project. ```bash cargo +nightly fmt --all ``` -------------------------------- ### Offer Battleship Game (Leo) Source: https://docs.leo-lang.org/leo_by_example/battleship Executes the 'offer_battleship' function to initiate a game for player 2. It takes a record as input, representing the current game state, and returns updated game state records. The primary output indicates that the game has started. ```leo leo run offer_battleship "{ owner: aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy.private, hits_and_misses: 0u64.private, played_tiles: 0u64.private, ships: 1157459741006397447u64.private, player_1: aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy.private, player_2: aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry.private, game_started: false.private, _nonce: 605849623036268790365773177565562473735086364071033205649960161942593750353group.public }" ``` -------------------------------- ### Initialize and Commit Leo Application to Git Source: https://docs.leo-lang.org/sdk/create-leo-app/tutorial This code block demonstrates the basic Git commands to initialize a new repository, add all project files, and make the first commit for a Leo application. ```bash cd aleo-project git init -b main git add . git commit -m "first commit, new aleo app" ``` -------------------------------- ### Leo Record Definition Source: https://docs.leo-lang.org/testing/test_framework Defines a Leo record named `Example` with fields for an owner (address) and a value (field). This structure is used to demonstrate testing of record fields. ```leo record Example { owner: address, x: field, } ``` -------------------------------- ### Leo Transition Function to Mint Record Source: https://docs.leo-lang.org/testing/test_framework A Leo transition function that mints an `Example` record. It takes a field value and sets the owner to the current signer, returning the newly created record. ```leo transition mint_record(x: field) -> Example { return Example { owner: self.signer, x, }; } ``` -------------------------------- ### Run Parser Tests with Expectations Reset Source: https://docs.leo-lang.org/language/style Runs all project tests, specifically targeting parser tests, while ensuring that test expectations are cleared before execution. This is useful for updating expected test outputs. ```bash CLEAR_LEO_TEST_EXPECTATIONS=true cargo test --all --features ci_skip --no-fail-fast ``` -------------------------------- ### Build a Leo Project Source: https://docs.leo-lang.org/getting_started/hello Compile the Leo program into Aleo instructions. This command generates `/build` and `output/` directories containing compiled code and intermediate artifacts. ```bash leo build ``` -------------------------------- ### Initialize a New Leo Project Source: https://docs.leo-lang.org/getting_started/hello Use the Leo Command Line Interface (CLI) to create a new project directory. This command initializes a standard project structure. ```bash leo new hello cd hello ``` -------------------------------- ### Create New Leo Project Source: https://context7.com/context7/leo-lang/llms.txt Initializes a new Leo project, setting up the basic file structure required for a Leo application. It creates a new project directory, navigates into it, and generates essential files like `.gitignore`, `.env`, `program.json`, and `src/main.leo`. ```bash # Create new Leo project leo new hello cd hello # Project structure created: # hello/ # ├── .gitignore # ├── .env # Contains NETWORK and PRIVATE_KEY # ├── program.json # Project manifest # └── src/ # └── main.leo # Main source code ``` -------------------------------- ### Leo Program Entry Point Source: https://docs.leo-lang.org/getting_started/hello The `src/main.leo` file contains the entry point for a Leo project, typically defining a `main` transition function. It specifies program name, transition inputs, outputs, and logic. ```leo // The 'hello' program. program hello.aleo { transition main(public a: u32, b: u32) -> u32 { let c: u32 = a + b; return c; } } ``` -------------------------------- ### Valid and Invalid Leo Program IDs Source: https://docs.leo-lang.org/language/structure Illustrates the correct format for Leo program IDs, specifying that the name must start with a lowercase letter and can only contain lowercase letters, numbers, and underscores. It shows examples of valid and invalid program ID declarations. ```leo program hello.aleo; // valid program Foo.aleo; // invalid program baR.aleo; // invalid program 0foo.aleo; // invalid program 0_foo.aleo; // invalid program _foo.aleo; // invalid ``` -------------------------------- ### Run a Leo Program Source: https://docs.leo-lang.org/getting_started/hello Compile and execute a Leo program with specified arguments. The output shows compilation status, constraint usage, and the program's result. ```bash leo run main 1u32 2u32 ``` -------------------------------- ### Run Battleship 'play' Transition for Player 1 (Leo) Source: https://docs.leo-lang.org/leo_by_example/battleship This snippet demonstrates how to configure the .env file for Player 1 and execute the 'play' transition in the Leo Battleship game. It includes setting the network, private key, and providing the initial game state and move records as inputs to the transition. The output shows the updated game states for both players after Player 1's move. ```bash echo " NETWORK=testnet PRIVATE_KEY=APrivateKey1zkpGKaJY47BXb6knSqmT3JZnBUEGBDFAWz2nMVSsjwYpJmm " > .env leo run play "{ owner: aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy.private, hits_and_misses: 0u64.private, played_tiles: 0u64.private, ships: 1157459741006397447u64.private, player_1: aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy.private, player_2: aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry.private, game_started: true.private, _nonce: 6313341191294792052861773157032837489809107102476040695601777954897783350080group.public }" "{ owner: aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy.private, incoming_fire_coordinate: 0u64.private, player_1: aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry.private, player_2: aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy.private, prev_hit_or_miss: 0u64.private, _nonce: 2798663115519921626400765401803177719929914180089719334947022448579691220488group.public }" 1u64 ``` -------------------------------- ### Custom Logic Constructor in Leo (Time-lock Example) Source: https://docs.leo-lang.org/guides/upgradability Enforces a time delay before an upgrade is allowed using custom logic within the constructor. This pattern requires the developer to write the entire constructor logic, including a block height condition for upgrades. ```leo // The 'timelock_example' program. program timelock_example.aleo { @custom async constructor() { // For upgrades (edition > 0), enforce a block height condition on when the constructor can be called successfully if self.edition > 0u16 { assert(block.height >= 1300u32); } } transition main(public a: u32, b: u32) -> u32 { let c: u32 = a + b; return c; } } ``` ```avm constructor: gt edition 0u16 into r0; branch.eq r0 false to end_then_0_0; gte block.height 1300u32 into r1; assert.eq r1 true; branch.eq true true to end_otherwise_0_1; position end_then_0_0; position end_otherwise_0_1; ``` -------------------------------- ### Leo Interpreted Test for State Modeling Source: https://docs.leo-lang.org/testing/test_framework An example of a Leo interpreted test using the `script` keyword instead of `transition`. This script simulates on-chain state interactions, including awaiting futures, setting and getting values from mappings, and generating random fields. ```leo @test script test_async() { const VAL: field = 12field; let fut: Future = example_program.aleo/set_mapping(VAL); fut.await(); assert_eq(Mapping::get(example_program.aleo/map, 0field), VAL); let rand_val: field = ChaCha::rand_field(); Mapping::set(example_program.aleo/map, VAL, rand_val); let value: field = Mapping::get(example_program.aleo/map, VAL); assert_eq(value, rand_val); } ``` -------------------------------- ### Deploy Program to Network using Leo CLI Source: https://context7.com/context7/leo-lang/llms.txt Demonstrates deploying Aleo programs to a network using the Leo CLI. It covers deployment using a .env file and deployment with command-line parameters for endpoint and private key. ```bash # Deploy using .env configuration leo deploy # Deploy with command-line parameters leo deploy --endpoint "https://api.explorer.provable.com/v1" --private-key "APrivateKey1z..." ``` -------------------------------- ### Configure Leo Project Environment - Environment Variables Source: https://docs.leo-lang.org/sdk/create-leo-app/tutorial Configuration for the Leo project's `.env` file. This includes setting the network to 'testnet' and providing the user's private key for account access and program deployment. ```dotenv NETWORK=testnet PRIVATE_KEY=APrivateKey1zkp2FCZZ7ucNVx5hoofizpq18mvCZNKTpqKMTt1wTahmxSf ``` -------------------------------- ### Create and Navigate New Leo Project - Shell Source: https://docs.leo-lang.org/sdk/create-leo-app/tutorial Commands to generate a new Leo project with a unique suffix and navigate into its directory. This is part of the process to create a custom Leo program for deployment, replacing existing ones. ```shell leo new helloworld_[randomsuffix] cd helloworld_[randomsuffix] ``` -------------------------------- ### Deploy Leo Program from Directory Source: https://docs.leo-lang.org/cli/deploy This command initiates the deployment of a Leo program from its root directory. It assumes that configuration details like network, private key, and endpoint are already set, typically via a `.env` file. ```bash leo deploy ``` -------------------------------- ### Create .env file for Deployment Parameters Source: https://context7.com/context7/leo-lang/llms.txt This snippet shows how to create a .env file to store deployment parameters like network, private key, and endpoint. These parameters are used by the 'leo deploy' command. ```bash cat > .env << EOF NETWORK=testnet PRIVATE_KEY=APrivateKey1z...GPWH ENDPOINT=https://api.explorer.provable.com/v1 EOF ``` -------------------------------- ### Leo Struct Declaration Source: https://docs.leo-lang.org/language/structure Provides an example of declaring a struct in Leo, which is a custom data type composed of named components. This example defines a struct 'Array3' with three 'u32' components. ```leo struct Array3 { a0: u32, a1: u32, a2: u32, } ``` -------------------------------- ### Leo Mapping Operations Source: https://docs.leo-lang.org/language/cheatsheet Illustrates various operations on mappings in Leo. This includes checking for the existence of a key, getting a value, getting a value with a default, setting a value, and removing a key-value pair from the mapping. ```leo mapping balances: address => u64; let contains_bal: bool = Mapping::contains(balances, receiver); let get_bal: u64 = Mapping::get(balances, receiver); let get_or_use_bal: u64 = Mapping::get_or_use(balances, receiver, 0u64); let set_bal: () = Mapping::set(balances, receiver, 100u64); let remove_bal: () = Mapping::remove(balances, receiver); ``` -------------------------------- ### Running the Aleo Devnet Script Source: https://docs.leo-lang.org/testing/devnet Illustrates the interactive prompts when running the `devnet.sh` script for setting up a local Aleo devnet. It shows default values for key configurations like validators, clients, and network ID. ```bash Enter the total number of validators (default: 4): Enter the total number of clients (default: 2): Enter the network ID (mainnet = 0, testnet = 1, canary = 2) (default: 1): Do you want to run 'cargo install --locked --path .' to build the binary? (y/n, default: y): n Do you want to clear the existing ledger history? (y/n, default: n): ``` -------------------------------- ### Execute Leo Program Commands - Shell Source: https://docs.leo-lang.org/sdk/create-leo-app/tutorial Shell commands for interacting with Leo programs. `leo run` compiles and executes program functions with input variables, while `leo execute` compiles, executes, synthesizes the program circuit, and generates keys. `leo help` provides assistance. ```shell leo run ## compiles leo to aleo instructions and executes program functions with input variables leo execute ## compiles leo to aleo instructions, executes a program with input variables, synthesizes the program circuit, and generates proving and verifying keys leo help ## you know what this does ``` -------------------------------- ### Configure Environment for Leo Auction Source: https://docs.leo-lang.org/leo_by_example/auction Sets up the .env file with network, private key, and endpoint configurations necessary for running Leo auction scripts. Ensure you replace 'APrivateKey1zkp5wvamYgK3WCAdpBQxZqQX8XnuN2u11Y6QprZTriVwZVc' with your actual private key. ```bash echo " NETWORK=testnet PRIVATE_KEY=APrivateKey1zkp5wvamYgK3WCAdpBQxZqQX8XnuN2u11Y6QprZTriVwZVc ENDPOINT=https://localhost:3030 " > .env ``` -------------------------------- ### Leo Mapping Operations: Get, Set, and More Source: https://docs.leo-lang.org/language/programs Demonstrates how to use mapping operations like get, get_or_use, set, contains, and remove in Leo. These operations allow for reading from, modifying, and checking the presence of data within mappings. Mapping operations are restricted to async functions. ```leo program test.aleo { mapping counter: address => u64; async transition dubble() -> Future { return update_mappings(self.caller); } async function update_mappings(addr: address) { let current_value: u64 = Mapping::get_or_use(counter, addr, 0u64); Mapping::set(counter, addr, current_value + 1u64); current_value = Mapping::get(counter, addr); Mapping::set(counter, addr, current_value + 1u64); } } ``` -------------------------------- ### Leo For Loop Example Source: https://docs.leo-lang.org/language/control Provides an example of a for loop in Leo, used for iterating over a range of integer values. The loop is defined with a variable, its type, and the inclusive range specified by lower and upper bounds. Both bounds must be integer constants of the same type, and the lower bound must be less than the upper bound. Nested loops are also supported. ```Leo let count: u32 = 0u32; for i: u32 in 0u32..5u32 { count += 1u32; } return count; // returns 5u32 ``` -------------------------------- ### Run Battleship Play Function with Player 2 Turn Source: https://docs.leo-lang.org/leo_by_example/battleship This snippet demonstrates setting up the .env file for Player 2 and executing the 'play' transition function in Leo. It includes the input parameters for the game state and the incoming fire coordinate, followed by the expected output game state and fire coordinate records. ```bash echo " NETWORK=testnet PRIVATE_KEY=APrivateKey1zkp86FNGdKxjgAdgQZ967bqBanjuHkAaoRe19RK24ZCGsHH " > .env leo run play "{ owner: aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry.private, hits_and_misses: 0u64.private, played_tiles: 2048u64.private, ships: 9044591273705727u64.private, player_1: aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry.private, player_2: aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy.private, game_started: true.private, _nonce: 591128247205636061702123861968396246163831838278146623498909560875485861872group.public }" "{ owner: aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry.private, incoming_fire_coordinate: 2u64.private, player_1: aleo15g9c69urtdhvfml0vjl8px07txmxsy454urhgzk57szmcuttpqgq5cvcdy.private, player_2: aleo1wyvu96dvv0auq9e4qme54kjuhzglyfcf576h0g3nrrmrmr0505pqd6wnry.private, prev_hit_or_miss: 0u64.private, _nonce: 4871574741887919250014604645502780786361650856453535231083359604148337116539group.public }" 4u64 ``` -------------------------------- ### Leo Return Statement Example Source: https://docs.leo-lang.org/language/control Illustrates how to use return statements in Leo to exit a function and optionally return a value. The example shows return statements within an if/else if/else structure, indicating that the function will terminate and return the result of the expression upon the first true condition. The return type must match the function's declared return type. ```Leo let a: u8 = 1u8; if a == 1u8 { return a + 1u8; } else if a == 2u8 { return a + 2u8; } else { return a + 3u8; } ``` -------------------------------- ### Link and Push Leo Application to Github Source: https://docs.leo-lang.org/sdk/create-leo-app/tutorial This snippet shows how to link a local Git repository to a remote Github repository and push the initial commit. Replace `` with the actual URL of your Github repository. ```bash git remote add origin git remote -v git push -u origin main ``` -------------------------------- ### Looping Over Arrays in Leo Source: https://docs.leo-lang.org/language/cheatsheet Shows how to iterate over arrays in Leo using a for loop. This example calculates the sum of elements in an array. ```aleo let numbers: [u32; 3] = [5u32, 10u32, 15u32]; let sum: u32 = 0u32; for i: u8 in 0u8..3u8 { sum += numbers[i]; } ``` -------------------------------- ### Deposit Tokens using Leo CLI Source: https://docs.leo-lang.org/leo_by_example/basic_bank This command executes the 'deposit' transition function via the Leo CLI, acting as the user. It requires the user's private key to be set in the .env file. The function takes the user's existing record (from issuance) and the deposit amount as inputs. Ensure the .env file is correctly configured and the input record is valid. ```bash echo " NETWORK=testnet PRIVATE_KEY=APrivateKey1zkp75cpr5NNQpVWc5mfsD9Uf2wg6XvHknf82iwB636q3rtc " > .env leo run deposit "{ owner: aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg.private, amount: 100u64.private, _nonce: 4668394794828730542675887906815309351994017139223602571716627453741502624516group.public }" 50u64 ``` -------------------------------- ### Execute Leo Program and Generate Transaction Source: https://docs.leo-lang.org/getting_started/hello Executes a Leo program and outputs a transaction object, which can be broadcast to the Aleo network. It compiles the program, checks constraints, and produces a JSON transaction. ```bash leo execute main 1u32 2u32 ``` -------------------------------- ### Leo For Loop Example Source: https://docs.leo-lang.org/language/cheatsheet Demonstrates the usage of a for loop in Leo. This loop iterates a specified number of times, incrementing a counter variable within the loop body. ```leo let count: u32 = 0u32; for i: u32 in 0u32..5u32 { count += 1u32; } ``` -------------------------------- ### Leo Assertion Functions Source: https://docs.leo-lang.org/language/operators Provides examples of using `assert` and `assert_eq` in Leo to enforce conditions within transitions. If an assertion fails, the program execution will halt. ```leo program test.aleo { transition matches() { assert(true); assert_eq(1u8, 1u8); } } ``` -------------------------------- ### Issue Tokens using Leo CLI Source: https://docs.leo-lang.org/leo_by_example/basic_bank This command uses the Leo CLI to run the 'issue' transition function. It requires setting the private key in the .env file to the bank's key. The function takes the recipient's address and the amount of tokens to issue as arguments. Ensure the .env file is correctly configured with the network and private key. ```bash echo " NETWORK=testnet PRIVATE_KEY=APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD " > .env leo run issue aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg 100u64 ``` -------------------------------- ### Transition Functions in Leo Source: https://context7.com/context7/leo-lang/llms.txt Explains transition functions in Leo, which form the public interface of a program. It shows an example of a transition function with public inputs and its corresponding execution command. ```leo program functions.aleo { // Transition with public and private inputs transition foo(public a: field, b: field) -> field { return a + b; } } // Execution: // leo run foo 5field 10field ``` -------------------------------- ### Deploy Aleo Program Source: https://docs.leo-lang.org/testing/devnet Command to deploy an Aleo program to the configured local devnet. Assumes the `.env` file is correctly set up with network and private key details. ```bash leo deploy ``` -------------------------------- ### Field Elements in Leo Source: https://context7.com/context7/leo-lang/llms.txt Shows the declaration and usage of field elements in Leo, which are fundamental for cryptographic operations in Aleo. It includes examples of initializing field elements and performing addition. ```leo program fields.aleo { transition field_example() -> field { let a: field = 0field; let b: field = 8444461749428370424248824938781546531375899335154063827935233455917409239040field; return a + b; } } ``` -------------------------------- ### Load Program into Leo Debugger Source: https://docs.leo-lang.org/guides/debuggin Navigates to a specific Leo program directory and then initializes the Leo debugger to analyze that program. ```bash cd workshop/learn_to_debug/point_math leo debug ``` -------------------------------- ### Record Definition and Usage in Leo Source: https://docs.leo-lang.org/language/cheatsheet Shows how to define and create records in Leo, which are used to structure data with named fields. Examples include defining a 'Token' record and a 'User' record. ```aleo record Token { owner: address, amount: u64, } let user: User = User { owner: aleo1ezamst4pjgj9zfxqq0fwfj8a4cjuqndmasgata3hggzqygggnyfq6kmyd4, balance: 1000u64, }; let user_address: address = user.owner; let user_balance: u64 = user.balance; ``` -------------------------------- ### Leo Test for Record Field Verification Source: https://docs.leo-lang.org/testing/test_framework A Leo test function that mints an `Example` record and then asserts that the `x` field of the minted record contains the expected value (0field). ```leo @test transition test_record_maker() { let r: example_program.aleo/Example = example_program.aleo/mint_record(0field); assert_eq(r.x, 0field); } ``` -------------------------------- ### Leo Transition Function for Addition Source: https://docs.leo-lang.org/testing/test_framework A simple Leo transition function that takes two unsigned 32-bit integers and returns their sum. This function serves as an example for testing logic. ```leo transition simple_addition(public a: u32, b: u32) -> u32 { let c: u32 = a + b; return c; } ``` -------------------------------- ### Leo Mapping Declaration Source: https://docs.leo-lang.org/language/structure Illustrates the declaration of a mapping in Leo, which stores key-value pairs on the blockchain. This example shows a mapping named 'account' with 'address' as the key type and 'u64' as the value type. ```leo // On-chain storage of an `account` mapping, // with `address` as the type of keys, // and `u64` as the type of values. mapping account: address => u64; ```