Complete example
Step by step
1
Create accounts
2
Initialize the VM
StorageMode::Production.3
Prepare transfer inputs
transfer_private function takes three inputs:- The input record (or amount for this example)
- The recipient address
- The amount to transfer (in microcredits)
4
Execute the transaction
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:- Find an unspent record to use as input:
- Use the record as the first input:
- Include a fee for miners:
Transfer types
Thecredits.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:Insufficient balance
Insufficient balance
Make sure the input record has enough credits to cover both the transfer amount and the fee.
Invalid address
Invalid address
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