> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/provablehq/leo/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick Start

> Create, build, and run your first Leo program in minutes

# Quick Start

This guide will walk you through creating your first Leo program. You'll learn how to create a new project, understand the project structure, write Leo code, and run your program.

<Note>
  Make sure you have [installed Leo](/installation) before continuing with this guide.
</Note>

## Create Your First Program

<Steps>
  <Step title="Create a new Leo project">
    Use the Leo CLI to create a new project:

    ```bash theme={null}
    leo new helloworld
    ```

    This creates a new directory called `helloworld` with a complete Leo project structure.
  </Step>

  <Step title="Navigate to the project directory">
    ```bash theme={null}
    cd helloworld
    ```
  </Step>

  <Step title="Explore the project structure">
    Your new Leo project has the following structure:

    ```
    helloworld/
    ├── src/
    │   └── main.leo          # Your program source code
    ├── program.json          # Program configuration
    └── README.md            # Project documentation
    ```
  </Step>
</Steps>

## Understanding the Default Program

Let's look at the default program created in `src/main.leo`:

```leo theme={null}
program helloworld.aleo {
    // The 'helloworld' main function.
    fn main(public a: u32, b: u32) -> u32 {
        return a + b;
    }
}
```

### Program Structure

* **Program declaration**: `program helloworld.aleo` defines the program name
* **Function**: `fn main` is the entry point of the program
* **Parameters**: `a` and `b` are inputs (both public `u32` unsigned 32-bit integers)
* **Return type**: `-> u32` specifies the function returns a 32-bit unsigned integer
* **Logic**: The function simply adds the two inputs and returns the result

<Info>
  All Leo programs must have the `.aleo` suffix in their program declaration.
</Info>

## Run Your Program

Leo makes it easy to run your program with a single command:

```bash theme={null}
leo run main 0u32 1u32
```

This command:

1. Compiles the program into Aleo instructions
2. Executes the `main` function with inputs `0u32` and `1u32`
3. Displays the output

<CodeGroup>
  ```bash Output theme={null}
  Leo ✅ Compiled 'helloworld.aleo' into Aleo instructions

  ⛓  Constraints
   - 'helloworld.aleo/main' - 0 constraints (0 public, 0 private)

  ➡️  Output
   - 1u32

  ✅ Executed 'helloworld.aleo/main'
  ```
</CodeGroup>

<Note>
  The `leo run` command automatically builds your program before running it, so you don't need to run `leo build` separately.
</Note>

## Try Different Inputs

Let's experiment with different inputs:

```bash theme={null}
leo run main 42u32 18u32
```

The output should be `60u32`.

## Build Your Own Program

Now let's modify the program to do something more interesting.

<Steps>
  <Step title="Create a Fibonacci function">
    Edit `src/main.leo` to implement a Fibonacci calculator:

    ```leo theme={null}
    program helloworld.aleo {
        // Calculate fibonacci number at position n
        fn fibonacci(public n: u8) -> u128 {
            assert(n <= 64u8);

            let f0: u128 = 0u128;
            let f1: u128 = 1u128;
            let c: u8 = 0u8;

            let z: u8 = reverse_bits(n);

            for i:u8 in 0u8..8u8 {
                if n > 0u8 {
                    let f2i1: u128 = f1 * f1 + f0 * f0;
                    let f2i: u128 = f0 * (2u128 * f1 - f0);
                    if z & 1u8.shl(c) == 0u8 {
                        f0 = f2i;
                        f1 = f2i1;
                    } else {
                        f0 = f2i1;
                        f1 = f2i + f2i1;
                    }
                    c = c + 1u8;
                    n = n >> 1u8;
                }
            }

            return f0;
        }
    }

    fn reverse_bits(n: u8) -> u8 {
        let reverse: u8 = 0u8;

        for i:u8 in 0u8..8u8 {
            if n > 0u8 {
                reverse = reverse << 1u8;

                if n & 1u8 == 1u8 {
                    reverse ^= 1u8;
                }

                n = n >> 1u8;
            }
        }

        return reverse;
    }
    ```
  </Step>

  <Step title="Run the Fibonacci program">
    ```bash theme={null}
    leo run fibonacci 10u8
    ```

    This calculates the 10th Fibonacci number.
  </Step>
</Steps>

## Understanding Leo Commands

Here are the essential Leo CLI commands:

<CodeGroup>
  ```bash Create New Project theme={null}
  leo new <PROJECT_NAME>
  ```

  ```bash Build Program theme={null}
  leo build
  ```

  ```bash Run Function theme={null}
  leo run <FUNCTION_NAME> <INPUTS>
  ```

  ```bash Run Tests theme={null}
  leo test
  ```

  ```bash Deploy to Network theme={null}
  leo deploy
  ```

  ```bash Format Code theme={null}
  leo fmt
  ```
</CodeGroup>

## Working with Different Data Types

Leo supports various data types. Here's a more comprehensive example:

```leo theme={null}
program datatypes.aleo {
    record Token {
        owner: address,
        amount: u64,
    }

    // Create a new token record
    fn mint(receiver: address, amount: u64) -> Token {
        return Token {
            owner: receiver,
            amount: amount,
        };
    }

    // Transfer tokens
    fn transfer(sender: Token, receiver: address, amount: u64) -> (Token, Token) {
        let difference: u64 = sender.amount - amount;

        let remaining: Token = Token {
            owner: sender.owner,
            amount: difference,
        };

        let transferred: Token = Token {
            owner: receiver,
            amount: amount,
        };

        return (remaining, transferred);
    }
}
```

### Key Data Types

* **Integers**: `u8`, `u16`, `u32`, `u64`, `u128`, `i8`, `i16`, `i32`, `i64`, `i128`
* **Boolean**: `bool`
* **Field elements**: `field`
* **Group elements**: `group`
* **Address**: `address`
* **Records**: Custom data structures that represent program state

<Info>
  Records in Leo are special data types that represent ownership and can be used to manage state privately on the Aleo blockchain.
</Info>

## Network Configuration

When creating a new project, you can specify the network:

```bash theme={null}
leo new myproject --network testnet --endpoint https://api.explorer.provable.com/v1
```

Available networks:

* `testnet` (default)
* `mainnet`
* `canary`

## Common Command Options

### Run with specific network

```bash theme={null}
leo run main 5u32 10u32 --network testnet
```

### Build with offline mode

```bash theme={null}
leo build --offline
```

### Run with debug output

```bash theme={null}
leo run main 1u32 2u32 --debug
```

### Quiet mode (suppress output)

```bash theme={null}
leo run main 1u32 2u32 --quiet
```

## Next Steps

Congratulations! You've just run your first Leo program. Here's what to explore next:

<CardGroup cols={2}>
  <Card title="Language Reference" icon="book" href="https://developer.aleo.org/leo/language">
    Learn Leo syntax and language features
  </Card>

  <Card title="Example Programs" icon="code" href="/examples/overview">
    Explore more complex Leo programs
  </Card>

  <Card title="Deploy Programs" icon="rocket" href="/cli/deploy">
    Learn how to deploy to the Aleo network
  </Card>

  <Card title="Testing Guide" icon="flask" href="/development/testing">
    Write tests for your Leo programs
  </Card>
</CardGroup>

## Troubleshooting

### Program won't compile

Make sure:

* Your program name matches the directory name
* All functions have proper type annotations
* Syntax is correct (check semicolons, braces, etc.)

### "Failed to execute" errors

Common causes:

* Incorrect input types (e.g., using `1` instead of `1u32`)
* Wrong number of inputs
* Input values that cause assertion failures

### Network connection issues

If you're having trouble connecting to the network:

```bash theme={null}
leo run main 1u32 2u32 --endpoint http://localhost:3030
```

This uses a local endpoint instead of the default remote endpoint.
