load static method

Future<Icrc1Ledger> load(
  1. Principal icrc1_ledger_id, [
  2. CallType calltype = CallType.query
])

Implementation

static Future<Icrc1Ledger> load(Principal icrc1_ledger_id, [CallType calltype = CallType.query]) async {
    Canister icrc1_ledger = Canister(icrc1_ledger_id);
    Vector<Record> metadata = (c_backwards(await icrc1_ledger.call(
        method_name: 'icrc1_metadata',
        calltype: calltype,
    ))[0] as Vector).cast_vector<Record>();
    late final String symbol;
    late final String name;
    late final int decimals;
    late final BigInt fee;
    String? logo_data_url;
    for (Record r in metadata) {
        if ((r[0] as Text).value == 'icrc1:decimals') {
            decimals = ((r[1] as Variant)['Nat'] as Nat).value.toInt();
        } else if ((r[0] as Text).value == 'icrc1:name') {
            name = ((r[1] as Variant)['Text'] as Text).value;
        } else if ((r[0] as Text).value == 'icrc1:symbol') {
            symbol = ((r[1] as Variant)['Text'] as Text).value;
        } else if ((r[0] as Text).value == 'icrc1:fee') {
            fee = ((r[1] as Variant)['Nat'] as Nat).value;
        } else if ((r[0] as Text).value == 'icrc1:logo') {
            logo_data_url = ((r[1] as Variant)['Text'] as Text).value;
        }
    }
    // call icrc1_supported_standards and find the icrc building blocks
    return Icrc1Ledger(
        symbol: symbol,
        name:name,
        decimals:decimals,
        fee:fee,
        ledger: Canister(icrc1_ledger_id),
        logo_data_url: logo_data_url
    );
}