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 transfer

  • recipients: Vector of recipient addresses

  • collection_cap: Collection capability for validation

  • sender_balances: Vector of sender's balance objects

  • ctx: Transaction context

Process Flow

  1. Initial Validation

  2. Balance Verification

  3. Deny List Check

  4. Transfer Execution

  5. Event Emission

2. Batch Transfer

Special Features

  1. Balance Management

    • Tracks user token balances

    • Automatically creates recipient balances

    • Handles balance updates atomically

  2. Security Checks

  3. 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:

Error Code
Description
Solution

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

  1. TransferEvent

    • Emitted for individual transfers

    • Tracks from/to addresses, token ID, amount

  2. BatchTransferEvent

    • Emitted for batch transfers

    • Includes all recipients and token IDs

    • Records timestamp and collection ID

Best Practices

  1. Balance Management

    • Always verify balances before transfer

    • Handle balance updates atomically

    • Clean up empty balances

  2. Security

    • Implement deny list checks

    • Verify collection capability

    • Validate all addresses

  3. Gas Optimization

    • Use batch transfers when possible

    • Clean up unused resources

    • Minimize storage operations

Common Integration Patterns

  1. Marketplace Integration

  1. Game Integration

Last updated