Overview
Memos are 32-byte values attached to transfers and emitted as indexed events:- Stored on-chain as event logs (not state)
- All three parameters (
from,to,memo) are indexed - Efficient filtering by sender, recipient, or memo hash
- Does not increase state size
- Minimal gas overhead (~5,000 gas)
Transfer Methods
Transfer With Memo
Transfer tokens with an attached memo:Transfer From With Memo
Allowance-based transfer with memo:Mint and Burn With Memo
Administrative functions also support memos:Use Cases
Invoice Payments
Track payments against specific invoices:- Vendor indexes
TransferWithMemoevents - Filters by recipient (vendor address) and memo (invoice hash)
- Matches payments to outstanding invoices
- No off-chain database synchronization needed
Multi-Party Coordination
Coordinate payments across multiple parties:Payment References
Embed arbitrary payment metadata:Cross-Chain Messaging
Coordinate with bridge contracts:Event Indexing
All three indexed parameters enable efficient filtering:Query by Sender
Query by Recipient
Query by Memo
Complex Queries
Memo Patterns
Hash Commitments
Store hash of off-chain data:Packed Metadata
Pack multiple values into 32 bytes:Enumeration
Simple sequential numbering:Gas Costs
Memos add minimal overhead to transfers:| Operation | Gas Cost |
|---|---|
| Transfer (no memo) | ~50,000 |
| Transfer with memo | ~55,000 |
| Memo overhead | ~5,000 |
- Event emission: ~375 gas per topic (3 topics)
- Event data (amount): ~8 gas per byte
- Total: ~1,125 + ~256 + overhead = ~5,000 gas
Best Practices
Memo Design
-
Use hashes for complex data
- Store full data off-chain
- Store only hash on-chain
- Verify later if needed
-
Make memos queryable
- Use consistent hashing schemes
- Document memo format
- Index events for efficient queries
-
Consider privacy
- Memos are public on-chain
- Use hashes to obscure sensitive data
- Don’t include PII directly
Error Handling
Event Parsing
Integration Example
Comparison to Alternatives
vs. Off-Chain References
On-chain memos:- ✅ Trustless verification
- ✅ Permanent record
- ✅ Indexed for efficient queries
- ❌ Additional gas cost (~5,000 gas)
- ❌ 32-byte limit
- ✅ No gas cost
- ✅ Unlimited metadata
- ❌ Requires centralized database
- ❌ Not cryptographically linked
vs. Separate Event Emission
TransferWithMemo:- ✅ Atomic with transfer
- ✅ Single event to index
- ✅ Guaranteed consistency
- ❌ Can emit without transfer
- ❌ Two events to track
- ❌ Possible inconsistency
vs. Contract Storage
Event logs:- ✅ Much cheaper (~5,000 gas)
- ✅ Indexed for filtering
- ❌ Cannot read from contracts
- ❌ Expensive (250,000 gas for new slot)
- ❌ Requires custom indexing
- ✅ Can read from contracts
Security Considerations
Memo Forgery
Memos are not signatures:- Anyone can transfer with any memo
- Don’t rely on memo alone for authentication
- Combine with sender/recipient validation
Privacy
Memos are public:- Never include sensitive data directly
- Use hashes to obscure relationships
- Consider privacy of hash preimages
Replay Attacks
Memo observation doesn’t prevent replays:- Use unique memos per payment
- Track processed memos
- Implement nonce schemes if needed
See Also
- Transfers - Transfer methods and gas costs
- Compliance - Policy enforcement on transfers
- Event Indexing - Querying on-chain events