Skip to main content

Your First SnarkVM Program

This guide walks you through creating a simple SnarkVM application that demonstrates key functionality: account generation, cryptographic operations, and working with field elements.
Before starting, ensure you have installed SnarkVM and have Rust 1.88.0 or higher.

Create a New Project

1

Initialize the Project

2

Add Dependencies

Update your Cargo.toml:

Example 1: Account Management

Learn how to create and manage Aleo accounts.

Generate a New Account

Replace src/main.rs with:

Account Derivation from Existing Key

Example 2: Working with Field Elements

Field elements are fundamental to zero-knowledge proofs. Here’s how to use them:
Field arithmetic operates modulo the field’s prime order. Division by zero will cause a panic.

Example 3: Cryptographic Hashing

SnarkVM includes several hash functions optimized for zero-knowledge proofs.

Example 4: Complete Application

Combining all concepts into a practical example:
Run this complete example:
Expected output:

Understanding Network Types

SnarkVM supports multiple network configurations:
Use MainnetV0 for production applications. TestnetV0 and CanaryV0 are for testing and development.

Common Patterns

Error Handling

SnarkVM uses Result types extensively:

Working with Random Number Generators

TestRng is for testing only. For production applications, use cryptographically secure random number generators.

Next Steps

Console Types

Learn about Field, Group, Scalar, and other primitive types

Program Synthesis

Execute Aleo programs and generate zero-knowledge proofs

Circuit Development

Build constraint systems for custom computations

API Reference

Explore the complete API documentation

Troubleshooting

Compilation Errors

If you encounter compilation errors:

Performance Issues

For optimal performance:
  • Always use --release flag for production builds
  • Enable CPU-specific optimizations in .cargo/config.toml:

Getting Help

GitHub Issues

Report bugs or request features

Discord Community

Join the Aleo developer community