Skip to content

[Docs] credits.aleo integration examples missing Final block handling #29424

Description

@Elexy101

📚 Documentation

The code example shows incorrect syntax for calling credits.aleo::transfer_public and with no final, which would cause compilation errors. New developers following this example will get stuck.

Problems:

  • transfer_public returns a Final type, but you can't directly return it without .run()
  • Missing explicit final block to execute the transfer
  • No handling of the returned Final value
  • This might limit new developers from running the program since if ran, triggers an error from transfer_public. so the final must have the function to execute the transaction.
fn transfer_public_credits(
    to: address, 
    amount: u64
) -> Final {
    return credits.aleo::transfer_public(self.caller, to, amount);
}

Fixed (Working):

fn transfer_public_credits(
    to: address, 
    amount: u64
) -> Final {
    let payment: Final = credits.aleo::transfer_public(to, amount);
    return final {
        payment.run();
    };
}

Full Fixed code:

import credits.aleo;

program address_example.aleo {
    // 1. Read from external mapping
    fn get_public_balance(user: address) -> Final {
        return final {
            let balance: u64 = credits.aleo::account.get_or_use(user, 0u64);
            // Note: get_or_use doesn't need .run() - it's a read operation
        };
    }
    
    // 2. Execute external final operation
    fn transfer_public_credits(to: address, amount: u64) -> Final {
        let payment: Final = credits.aleo::transfer_public(to, amount);
        return final {
            payment.run();  // execute the transfer
        };
    }
    
    // 3. Work with private credits (no Final needed)
    fn transfer_private_credits(
        input: credits.aleo::credits,
        to: address,
        amount: u64
    ) -> (credits.aleo::credits, credits.aleo::credits) {
        return credits.aleo::transfer_private(input, to, amount);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions