Custom Transfers
Overview
The ART20 module implements a sophisticated transfer mechanism that goes beyond simple ownership changes. It manages user balances, collection integrity, deny lists, and batch operations while ensuring proper state updates across the protocol.
Transfer Functions
1. Standard Transfer
public entry fun transfer_art20(
tokens: vector<NFT>,
recipients: vector<address>,
collection_cap: &CollectionCap,
mut sender_balances: vector<UserBalance>,
ctx: &mut TxContext
)Purpose
Enables secure transfer of NFTs while maintaining protocol state, balances, and collection integrity.
Parameters
tokens: Vector of NFTs to transferrecipients: Vector of recipient addressescollection_cap: Collection capability for validationsender_balances: Vector of sender's balance objectsctx: Transaction context
Process Flow
Initial Validation
Balance Verification
Deny List Check
Transfer Execution
Event Emission
2. Batch Transfer
Special Features
Balance Management
Tracks user token balances
Automatically creates recipient balances
Handles balance updates atomically
Security Checks
Batch Processing
Efficient handling of multiple transfers
Atomic updates across all operations
Event emission for batch transfers
Integration Guide
1. Basic Transfer
2. Batch Transfer Example
Error Handling
Common errors and their meanings:
E_INSUFFICIENT_BALANCE
Sender lacks required balance
Verify balance before transfer
E_COLLECTION_MISMATCH
NFT doesn't belong to collection
Check collection ID
E_ADDRESS_DENIED
Address in deny list
Verify recipient status
E_INVALID_LENGTH
Mismatched vectors
Ensure equal tokens and recipients
Events
TransferEvent
Emitted for individual transfers
Tracks from/to addresses, token ID, amount
BatchTransferEvent
Emitted for batch transfers
Includes all recipients and token IDs
Records timestamp and collection ID
Best Practices
Balance Management
Always verify balances before transfer
Handle balance updates atomically
Clean up empty balances
Security
Implement deny list checks
Verify collection capability
Validate all addresses
Gas Optimization
Use batch transfers when possible
Clean up unused resources
Minimize storage operations
Common Integration Patterns
Marketplace Integration
Game Integration
Last updated