Skip to main content
The leo execute command executes Leo programs on the Aleo network, generating cryptographic proofs and optionally broadcasting transactions.

Syntax

Arguments

string
default:"main"
The function to execute. Can be:
  • Function name only: main
  • Qualified name: hello_world.aleo/main
string[]
Program inputs in Aleo format:
  • Literals: 1u32, true, 5field
  • Records (plaintext): { owner: aleo1..., gates: 5u64 }
  • Records (ciphertext): record1... (automatically decrypted)

Options

Network Options

string
required
Network type: mainnet, testnet, or canary.
string
required
Network endpoint URL. Examples:
  • Mainnet: https://api.explorer.provable.com/v1
  • Testnet: https://api.explorer.provable.com/v1
  • Devnet: http://localhost:3030
string
required
Private key to sign the transaction.
Never use test private keys on mainnet. Keep your private keys secure.
boolean
default:false
Whether the network is a devnet.
string
Custom consensus heights (comma-separated). For custom devnets only.

Fee Options

string
Priority fee in microcredits, delimited by |. Use default for automatic calculation.Example: 1000|2000|default
string
Records to pay fees privately, delimited by |. Use default for public fees.Example: record1abc...|default

Transaction Actions

boolean
default:false
Broadcast the transaction to the network.
boolean
default:false
Print the transaction JSON to stdout.
string
Save the transaction to the specified directory.

Additional Options

boolean
default:false
Skip proof generation. Generates transaction without proof (for testing).
boolean
default:false
Skip confirmation prompts. Use with caution.
number
Consensus version to use (1-13). Auto-detected if not provided.
number
default:8
Seconds to wait for block confirmation.
number
default:12
Number of blocks to check for transaction confirmation.

Build Options

boolean
default:false
Don’t use the dependency cache.
boolean
default:false
Use network versions of dependencies.

Examples

Execute and Print

Generates the transaction and prints it without broadcasting:

Execute and Broadcast

Output:

Execute with Priority Fee

Priority fees increase the likelihood of faster transaction inclusion by validators.

Execute with Private Fee

Use a record to pay fees privately instead of public credits.

Execute and Save

Saves the transaction to ./transactions/transaction.execution.json.

Execute Remote Program

Executes a program deployed on the network.

Skip Proof Generation (Testing)

Transactions without proofs cannot be broadcast to the network. Use --skip-execute-proof for testing only.

Execute with Custom Consensus Version

Execute Without Confirmation

Use --yes with caution. It skips all confirmation prompts.

Execution Flow

  1. Build Phase:
    • Compiles the program if in a Leo project
    • Resolves and downloads dependencies
  2. VM Initialization:
    • Creates VM with consensus store
    • Initializes query interface for network state
  3. Program Loading:
    • Loads local or remote programs
    • Adds programs to VM in dependency order
  4. Authorization:
    • Generates authorization for function execution
    • Creates proof (unless --skip-execute-proof)
  5. Cost Estimation:
    • Calculates storage and execution costs
    • Displays cost summary
  6. Fee Authorization:
    • Generates fee authorization (public or private)
    • Uses provided priority fee if specified
  7. Transaction Creation:
    • Combines execution and fee
    • Produces final transaction
  8. Broadcasting (if --broadcast):
    • Confirms fee with user
    • Broadcasts to network
    • Monitors for confirmation

Cost Breakdown

Execution costs consist of:

Storage Cost

Cost to store transaction data on-chain:
  • Proportional to transaction size
  • Measured in microcredits

Execution Cost

Cost to execute the program:
  • Based on computational complexity
  • Number of constraints in the circuit

Priority Fee

Optional fee to prioritize transaction:
  • Higher fees increase inclusion likelihood
  • Goes to block validators

Total Cost

Transaction Confirmation

After broadcasting, Leo monitors the transaction:
Confirmation process:
  1. Broadcasts transaction to mempool
  2. Waits for inclusion in a block (up to --max-wait seconds per block)
  3. Checks recent blocks (up to --blocks-to-check blocks)
  4. Reports success or timeout

JSON Output Format

With --print or --save, transactions are in JSON format:

Warnings

Leo displays warnings for:

Program Mismatch

Resolution:
  • Deploy your local version, or
  • Use --no-local to use the network version

Program Not on Network

Resolution:

Consensus Version Mismatch

Resolution:
  • Verify your endpoint is correct
  • Use --consensus-version to override

Troubleshooting

Insufficient Balance

Ensure your account has enough credits for the execution cost and fees.

Transaction Rejected

Possible causes:
  • Invalid inputs
  • Program not deployed
  • Insufficient fee
  • Consensus version mismatch

Confirmation Timeout

The transaction may still be pending. Check the transaction ID on a block explorer.

Best Practices

  1. Test First: Use leo run for rapid testing before executing on-chain
  2. Verify Costs: Review cost summaries before confirming
  3. Use Priority Fees: For time-sensitive transactions
  4. Save Transactions: Use --save for record-keeping
  5. Monitor Confirmation: Wait for confirmation before assuming success

Next Steps