What are Records?
Records are Leo’s primitive for representing owned, private data on the Aleo blockchain. They are similar to UTXOs (Unspent Transaction Outputs) in Bitcoin - each record has a unique owner and can only be consumed once.Record Declaration
Records are declared using therecord keyword:
Every record must include an
owner field of type address. The owner is the only account that can spend or consume the record.Record Fields
Records can contain multiple fields of different types:Creating Records
In Functions
Create records by constructing them with all required fields:With Self Reference
Useself.caller to create records for the transaction caller:
Consuming Records
Records are consumed when used as function inputs:Record Ownership
Owner Field
Theowner field determines who can spend the record:
Transferring Ownership
Transfer records by creating new records with different owners:Accessing Record Fields
Access record fields using dot notation:Record Validation
Validate record data before processing:Records vs Structs
Records
- Must have an
ownerfield - Represent owned, consumable assets
- Are private by default
- Can only be spent by the owner
Structs
- No ownership requirement
- Represent data structures
- Can be used anywhere
- Not consumable
Privacy Guarantees
Records provide strong privacy guarantees:- Private Amounts: Record field values are not revealed on-chain
- Private Owners: Record owners are not publicly known
- Private Operations: Computations on records are private
- Zero-Knowledge Proofs: All record operations are proven without revealing data
Hybrid Public/Private Operations
Combine private records with public state:Best Practices
1. Validate Before Consuming
2. Clear Ownership Transfer
3. Document Record Purpose
4. Handle Zero Amounts
Common Patterns
Splitting Records
Merging Records
Burning Records
Next Steps
Mappings
Store public state on-chain
Functions
Work with records in functions
Finalize
Combine records with public state
Data Types
Explore other types