Skip to main content
Version: 4.4.0

Running a Devnet

A local devnet can be a heavyweight but reliable way to test your application on Aleo.

Setup

The Leo CLI provides a helpful command to help startup a local devnet:

leo devnet --snarkos <SNARKOS> --snarkos-features test_network

The <SNARKOS> is the path to an installed binary of snarkOS, the decentralized operating system that forms the backbone of the Aleo network.

If snarkOS is not installed, pass --install. The CLI downloads, compiles, and stores the binary at the <SNARKOS> path.

leo devnet --snarkos <SNARKOS> --snarkos-features test_network --install
info

Windows users will need to perform some additional steps in order for snarkOS to install properly:

  1. Upon initially installing Rust, you should have been automatically prompted to install Visual Studio with the MSVC 2022 C++ build tools.
  2. Open the Visual Studio Installer. Install the C++ Clang Compiler for Windows. Install the Windows 10 SDK or Windows 11 SDK for your operating system. Record the tool installation path. It must have the form {PATH}\Microsoft Visual Studio\2022\BuildTools.
  3. Within the aforementioned build tools directory, you should find the location of a file called libclang.dll. For x86-based systems, this should be in the VC\Tools\Llvm\bin subdirectory. For x64-based systems, this should be in the VC\Tools\Llvm\x64\bin subdirectory.
  4. Once you have the full path of libclang.dll, create the LIBCLANG_PATH environment variable for your system and set it to this path.
  5. snarkOS should now compile and run properly.

The tmux command will allow you to toggle between nodes in your local devnet. You can enable this by passing the --tmux flag upon startup:

leo devnet --snarkos <SNARKOS> --snarkos-features test_network --tmux
info

This feature is only available on Unix-based systems.

You will need to install the tmux package first:

To install tmux on macOS, you can use the Homebrew package manager. If you have not installed Homebrew yet, you can find instructions at their website. Once Homebrew is installed, run:

brew install tmux

Here are some useful (default) commands in tmux:

# To toggle to the next node in a local devnet
Ctrl+b n
# To toggle to the previous node in a local devnet
Ctrl+b p
# To scroll easily, press q to quit
Ctrl+b q
# To select a node in a local devnet
Ctrl+b w
# To select a node manually in a local devnet
Ctrl+b :select-window -t {NODE_ID}
# To stop a local devnet
Ctrl+b :kill-session

See the full leo devnet CLI documentation.

Usage

When you start the devnet, the CLI will actually spin up a new instance of the blockchain from genesis via the snarkOS binary. This means that the chain will start at block 0 and consensus version 1, and the only program deployed will be credits.aleo.

The height of the chain will increase as blocks are produced. At various different heights, a new consensus version will activate, which will unlock various features that have been implemented as the Aleo network has matured. By default, snarkOS built with --features test_network will fast forward to the highest ConsensusVersion on a Testnet ledger within a few blocks. You can get more insights by calling curl localhost:3030/testnet/version.

To test an older ConsensusVersion, give a comma-separated height list to --consensus-heights. For example, use 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,20,$((2**32 - 1)) to activate V17 at height 20. V18 then stays inactive. The list must have one height for each consensus version in the VM.

Each time you stop and restart the chain, the prior state and history will be saved. You can clear any prior history by passing the --clear-storage flag:

leo devnet --snarkos <SNARKOS> --snarkos-features test_network --clear-storage

Clearing the ledger history may be useful if you wish to redeploy your program without changing the name. However, this will erase all transaction history and start a new instance of the Aleo blockchain from genesis.

Deploying and Executing

Before deployment or execution on a local devnet, set the endpoint to http://localhost:3030. Use one of these methods:

  • Set the ENDPOINT environment variable.
  • Pass --endpoint http://localhost:3030 to the CLI.
  • Set ENDPOINT in the .env file at the Leo project root.

You will also need credits to fund transactions on the devnet. snarkOS automatically initializes four development accounts with Aleo credits for tests.

# Account 0
APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH
AViewKey1mSnpFFC8Mj4fXbK5YiWgZ3mjiV8CxA79bYNa8ymUpTrw
aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px

# Account 1
APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh
AViewKey1pTzjTxeAYuDpACpz2k72xQoVXvfY4bJHrjeAQp6Ywe5g
aleo1s3ws5tra87fjycnjrwsjcrnw2qxr8jfqqdugnf0xzqqw29q9m5pqem2u4t

# Account 2
APrivateKey1zkp2GUmKbVsuc1NSj28pa1WTQuZaK5f1DQJAT6vPcHyWokG
AViewKey1u2X98p6HDbsv36ZQRL3RgxgiqYFr4dFzciMiZCB3MY7A
aleo1ashyu96tjwe63u0gtnnv8z5lhapdu4l5pjsl2kha7fv7hvz2eqxs5dz0rg

# Account 3
APrivateKey1zkpBjpEgLo4arVUkQmcLdKQMiAKGaHAQVVwmF8HQby8vdYs
AViewKey1iKKSsdnatHcm27goNC7SJxhqQrma1zkq91dfwBdxiADq
aleo12ux3gdauck0v60westgcpqj7v8rrcr3v346e4jtq04q7kkt22czsh808v2

Specify the private key with one of these methods:

  • Set the PRIVATE_KEY environment variable.
  • Pass --private-key <PRIVATE_KEY> to the CLI.
  • Set PRIVATE_KEY in the .env file at the Leo project root.

Once your private key and endpoint have been correctly set, deploying and executing largely function the same as they would on Testnet or Mainnet. For more details on either of those processes, check out the Deploying and Executing guides.

Querying Transaction Status

You can check your transactions by using the following API endpoint:

GET http://localhost:3030/testnet/transaction/{TRANSACTION_ID}

or by using leo query from the CLI:

leo query transaction {TRANSACTION_ID}

Use the transaction API endpoint to verify if a transaction succeeded. Successful and failed transactions both execute a fee transaction. If only the fee transaction appears, the transaction failed. Failed Testnet and Mainnet transactions still require a fee because the network performs a computation.

A full list of API endpoints is available in the explorer documentation.

Record Scanning

You can use the CLI from your installed snarkOS binary to view your records. First, navigate to the directory where you installed the binary. Then use the following command syntax:

./snarkos developer scan --endpoint http://localhost:3030 --private-key {YOUR_PRIVATE_KEY} --start <block_number> --network 1

Setting block_number to 0 will list all of the records created starting from the genesis block, including your test credit records.

sample output:
⚠️ Attention - Scanning the entire chain. This may take a while...

Scanning 3 blocks for records (100% complete)...

[
"{ owner: aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px.private, microcredits: 23437500000000u64.private, _nonce: 3666670146276262240199958044811329632452609778779651964870759629195088099828group.public}",
"{ owner: aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px.private, microcredits: 23437500000000u64.private, _nonce: 4536868268814456227312360347031739423312689137706933033938812386306238998060group.public}",
"{ owner: aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px.private, microcredits: 23437500000000u64.private, _nonce: 205967862164714901379497326815256981526025583494109091059194305832749867953group.public}",
"{ owner: aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px.private, microcredits: 23437500000000u64.private, _nonce: 4424806931746512507605174575961455750579179367541686805196254590136284583805group.public}"
]

Setting block_number to 1 or higher will exclude the above credit records from the scan.