This document provides an exhaustive, step-by-step technical guide on developing, deploying, and executing smart contracts on the Aleo blockchain. It covers every tool, methodology, and best practice used to achieve zero-error deployments and high-speed execution.
To build on Aleo without issues, you must use this specific set of tools:
- Rust & Cargo: The primary language and package manager used to build Aleo's core infrastructure.
- Why? Leo and snarkOS are built in Rust. You need it to compile the CLI from source if binaries are unavailable.
- Leo CLI (v3.4.0): The functional programming language compiler for Aleo.
- Commands:
leo new,leo build,leo test,leo deploy,leo execute.
- Commands:
- Aleo SDK (@aleohq/sdk): The official JavaScript/TypeScript library.
- Why? Essential for building frontend integrations and automated deployment/execution scripts.
- snarkOS: The decentralized operating system for private applications.
- Usage: Used to run nodes or verify network state locally.
- Node.js & TypeScript: For running the deployment and interaction logic.
- Aleo Explorer: For real-time verification of transactions and program registry.
Writing Leo accurately requires a paradigm shift from traditional blockchain languages like Solidity.
Aleo does not have a global state like Ethereum. Instead, it uses Records. A record is a piece of data that is "spent" and "created".
- Accuracy Tip: Always ensure your
transitionfunctions return arecordif you need to store data privately.
Every literal must have a type suffix.
1u8,100u64,1field,1scalar,true.- Accuracy Tip: If you miss a suffix (e.g., writing
1instead of1u8), the compiler will throw an error.
transition: Generates a Zero-Knowledge Proof (ZKP). These are entry points called by users.function: Internal logic. Does NOT generate a separate proof.async transition/finalize: For on-chain state updates (mappings).
- Static Analysis: I use
leo checkconstantly to verify types before building. - Formal Verification Logic: Leo's syntax is designed to be mathematically verifiable. By following the "Functional Programming" pattern (no side effects within transitions), logic errors are minimized.
Always run leo build before deploying. This converts .leo code into Aleo Instructions (.aleo files in the build/ directory). These instructions are what the network actually executes.
This is the most stable method.
leo deploy --private-key <KEY> \
--network testnet \
--endpoint https://api.explorer.provable.com/v1 \
--priority-fees 1000000 \
--yes --broadcast- Critical Fix for "Constructor" Error: Modern Aleo requires a constructor with an annotation. Use
@noupgrade async constructor() {}to ensure the program is immutable and deployable. For upgradeable contracts, use@admin(address="...").
To deploy via the browser without errors:
- Memory Management: ZK-Proof generation is memory-intensive. Ensure the browser environment has enough heap space.
- WASM Initialization: The SDK uses WebAssembly. Always await the initialization of the SDK modules.
- Code Snippet:
const programManager = new ProgramManager(); programManager.setAccount(new Account({ privateKey })); // Crucial: Set the fee high enough (e.g. 1.5 - 2.0 credits) const txId = await programManager.deploy(compiledCode, 2.0);
To reach high transaction volumes (beating 250+ calls), sequential execution is too slow.
- Asynchronous Broadcasting: Use the
--broadcastflag in the CLI. This sends the transaction to the mempool and immediately returns, without waiting for the block to be mined. - Parallel Scripting: Use Bash's
&operator to launch multipleleo executeprocesses simultaneously. - Public Credits: Use
fee_public(credits held in the mapping) rather than private records. Private records require "spent" management which serializes transactions. Public credits allow the network to handle multiple transactions from the same address in parallel more efficiently.
# Launch 10 workers in parallel
for i in {1..10}; do
leo execute issue_certification <ADDR> 1u8 --broadcast --yes &
done
waitleo execute issue_certification <RECEIVER_ADDRESS> <TYPE_u8> --private-key <KEY> --broadcastconst txId = await programManager.execute(
"crane_signals_cert.aleo",
"issue_certification",
0.5, // Fee
false, // Private fee toggle
[receiver, "1u8"] // Arguments
);- Private key has at least 10+ testnet credits.
- Program name is unique on the network.
-
leo buildshows no warnings. - RPC endpoint (
api.explorer.provable.com/v1) is reachable.
Guide authored by Jules, Automated Aleo Expert.