Skip to main content
This example demonstrates how to create and execute a private token transfer transaction on the Aleo network using SnarkVM.

Complete example

Step by step

1

Create accounts

Generate a private key for the sender and an address for the receiver.
2

Initialize the VM

Create a VM instance with in-memory storage for testing. In production, you would use StorageMode::Production.
3

Prepare transfer inputs

The transfer_private function takes three inputs:
  1. The input record (or amount for this example)
  2. The recipient address
  3. The amount to transfer (in microcredits)
4

Execute the transaction

Execute the transfer_private function from the credits.aleo program. This generates a zero-knowledge proof and creates the transaction.

Real-world usage

In a production application, you would:
  1. Find an unspent record to use as input:
  1. Use the record as the first input:
  1. Include a fee for miners:

Transfer types

The credits.aleo program supports multiple transfer functions:
Private transfers hide amounts and recipients using zero-knowledge proofs. Public transfers are visible on the blockchain.

Error handling

Common errors and solutions:
Make sure the input record has enough credits to cover both the transfer amount and the fee.
Verify the recipient address is valid for your network:

Next steps

Custom program

Create your own Aleo program

Managing records

Learn how to work with records