### Initialize ICRC37.mo Class with Migration Pattern Source: https://github.com/panindustrial-org/icrc37.mo/blob/main/README.md This Motoko code demonstrates the initialization of the ICRC37 class, incorporating a migration pattern and the Class+ pattern for stable memory management. It includes the setup of the initial state, a private function to get the ICRC37 environment, and a public function to access the initialized ICRC37 instance, handling lazy initialization to ensure the class is ready when needed. ```motoko stable var icrc37_migration_state = ICRC37.init(ICRC37.initialState() , #v0_1_0(#id), ICRC37Default.defaultConfig(); , init_msg.caller); let #v0_1_0(#data(icrc37_state_current)) = icrc37_migration_state; private var _icrc37 : ?ICRC37.ICRC37 = null; private func get_icrc37_environment() : ICRC37.Environment { { canister = get_canister; get_time = get_time; refresh_state = get_icrc37_state; icrc7 = icrc7(); //your icrc7 class can_approve_token = null; can_approve_collection = null; can_revoke_token_approval = null; can_revoke_collection_approval = null; can_transfer_from = null; }; }; func icrc37() : ICRC37.ICRC37 { switch(_icrc37){ case(null){ let initclass : ICRC37.ICRC37 = ICRC37.ICRC37(?icrc37_migration_state, Principal.fromActor(this), get_icrc37_environment()); _icrc37 := ?initclass; initclass; }; case(?val) val; }; }; ``` -------------------------------- ### Install ICRC37.mo with Mops Source: https://github.com/panindustrial-org/icrc37.mo/blob/main/README.md This snippet shows how to add the ICRC37.mo library to your Motoko project using the Mops package manager, a common tool for managing Motoko dependencies. ```shell mops add icrc37.mo ``` -------------------------------- ### ICRC37.mo Initialization Arguments Source: https://github.com/panindustrial-org/icrc37.mo/blob/main/README.md This section describes the various configuration parameters that can be passed during the initialization of the ICRC37.mo class. These arguments control aspects like maximum approvals, revoke limits, collection approval requirements, and cleanup behavior for approvals, allowing fine-grained control over the class's operation. ```APIDOC Initialization Arguments: max_approvals_per_token_or_collection: the maximum number of approvals that can be active for any account, defaults to 10,000; max_revoke_approvals: the maximum number of approvals that can be revoked at one time - defaults to the max_batch_update setting in your icrc7 class collection_approval_requires_token: will require that any user making a collection approval has a token in ownership; max_approvals: the max approvals allowed on the canister - defaults to 100,000; settle_to_approvals: the number of approvals that the cleanup will seek to reach if max_approvals is exceeded. Defaults to 99,750(So the default state is that 250 approvals(oldest first) will be removed if 100,001 approvals is reached). - deployer: the principal deploying, will be the owner of the collection; ``` -------------------------------- ### ICRC37.mo Environment Configuration Source: https://github.com/panindustrial-org/icrc37.mo/blob/main/README.md This section details the `Environment` record structure used by the ICRC37.mo class, explaining each field's purpose. It allows passing dynamic information and custom functions to the class, such as canister ID, current time, state refresh, and references to ICRC7 and approval/transfer override functions, enabling flexible integration. ```APIDOC ICRC37.Environment: get_canister: A function to retrieve the canister this class is running on get_time: A function to retrieve the current time to make testing easier refresh_state: A function to call to refresh the state of your class. useful in async environments where state may change after an await - provided for future compatibility. icrc7: ICRC37 needs a reference to the ICRC7.mo class that runs your NFT canister. can_transfer_from: override functions to access and manipulate a transfer from transaction just before it is committed. can_approve_token: override functions to access and manipulate an approve transaction just before it is committed. can_approve_collection: override functions to access and manipulate an approve transaction just before it is committed. can_revoke_token_approval: override functions to access and manipulate a revoke transaction just before it is committed. can_revoke_collection_approval: override functions to access and manipulate a collection transaction just before it is committed. ``` -------------------------------- ### Import ICRC37.mo in Motoko Source: https://github.com/panindustrial-org/icrc37.mo/blob/main/README.md This snippet demonstrates how to import the ICRC37.mo library into a Motoko source file. Importing the module makes its functionalities and types available for use within your Motoko canister. ```motoko import Icrc37Mo "mo:icrc37.mo"; ``` -------------------------------- ### APIDOC: ICRC37 Event Listener Registration Endpoints Source: https://github.com/panindustrial-org/icrc37.mo/blob/main/README.md Describes the methods available on the ICRC37 class for registering event listeners. These methods allow external objects to subscribe to and be notified of various token events such as approvals, revocations, and transfers. Notifications are synchronous and cannot make direct canister calls. ```APIDOC Class Methods: register_token_approved_listener: Registers a listener for token approval events. register_collection_approved_listener: Registers a listener for collection approval events. register_token_revoked_listener: Registers a listener for token revocation events. register_collection_revoked_listener: Registers a listener for collection revocation events. register_transfer_from_listener: Registers a listener for transfer-from events. Notes: - Events are synchronous; direct canister calls are not allowed. - Suggested use: set timers for notifications via Timers API. - TransferFrom Notifications are accompanied by ICRC7 Transfer Notifications. ``` -------------------------------- ### Motoko: ICRC37 Event Notification and Listener Types Source: https://github.com/panindustrial-org/icrc37.mo/blob/main/README.md Defines the data structures for various token and collection event notifications (TransferFromNotification, TokenApprovalNotification, etc.) and the corresponding function signatures for event listeners (TokenApprovedListener, TransferFromListener, etc.) within the ICRC37 standard. These types are used to register and receive synchronous notifications when token events occur. ```Motoko public type TransferFromNotification = { token_id: Nat; spender: Account; // the subaccount of the caller (used to identify the spender) from : Account; to : Account; memo : ?Blob; created_at_time : ?Nat64; }; public type TokenApprovalNotification = { token_id : Nat; from : Account; spender : Account; // Approval is given to an ICRC Account memo : ?Blob; expires_at : ?Nat64; created_at_time : ?Nat64; }; public type CollectionApprovalNotification = { from : Account; spender : Account; // Approval is given to an ICRC Account memo : ?Blob; expires_at : ?Nat64; created_at_time : ?Nat64; }; public type RevokeTokenNotification = { token_id : Nat; from : Account; spender : Account; memo: ?Blob; }; public type RevokeCollectionNotification = { from: Account; spender: Account; memo: ?Blob; created_at_time : ?Nat64; }; public type TokenApprovedListener = ( approval: TokenApprovalNotification, trxid: Nat) -> (); public type CollectionApprovedListener = (approval: CollectionApprovalNotification, trxid: Nat) -> (); public type TokenApprovalRevokedListener = ( revoke: RevokeTokenNotification, trxid: Nat) -> (); public type CollectionApprovalRevokedListener = (revoke: RevokeCollectionNotification, trxid: Nat) -> (); public type TransferFromListener = (trx: TransferFromNotification, trxid: Nat) -> (); ``` -------------------------------- ### APIDOC: ICRC37 Transaction Override Functions Source: https://github.com/panindustrial-org/icrc37.mo/blob/main/README.md Describes the optional functions that can be assigned by the user to intercept and manipulate transaction data before commitment. These functions allow for pre-transaction validation or modification, and can cancel a transaction by returning an error. ```APIDOC Environment Functions (Optional): can_approve_token: Intercepts token approval transactions. Parameters: trx: Transaction - The current transaction. trxtop: ?Transaction - Optional top-level transaction. notification: TokenApprovalNotification - The notification data for the approval. Returns: Result.Result<(trx: Transaction, trxtop: ?Transaction, notification: TokenApprovalNotification), Text> - Returns modified transaction data or an error to cancel. can_approve_collection: Intercepts collection approval transactions. Parameters: trx: Transaction - The current transaction. trxtop: ?Transaction - Optional top-level transaction. notification: CollectionApprovalNotification - The notification data for the approval. Returns: Result.Result<(trx: Transaction, trxtop: ?Transaction, notification: CollectionApprovalNotification), Text> - Returns modified transaction data or an error to cancel. can_revoke_token_approval: Intercepts token approval revocation transactions. Parameters: trx: Transaction - The current transaction. trxtop: ?Transaction - Optional top-level transaction. notification: RevokeTokenNotification - The notification data for the revocation. Returns: Result.Result<(trx: Transaction, trxtop: ?Transaction, notification: RevokeTokenNotification), Text> - Returns modified transaction data or an error to cancel. can_revoke_collection_approval: Intercepts collection approval revocation transactions. Parameters: trx: Transaction - The current transaction. trxtop: ?Transaction - Optional top-level transaction. notification: RevokeCollectionNotification - The notification data for the revocation. Returns: Result.Result<(trx: Transaction, trxtop: ?Transaction, notification: RevokeCollectionNotification), Text> - Returns modified transaction data or an error to cancel. can_transfer_from: Intercepts transfer-from transactions. Parameters: trx: Transaction - The current transaction. trxtop: ?Transaction - Optional top-level transaction. notification: TransferFromNotification - The notification data for the transfer. Returns: Result.Result<(trx: Transaction, trxtop: ?Transaction, notification: TransferFromNotification), Text> - Returns modified transaction data or an error to cancel. Behavior: - Returning #err cancels the transaction, providing a #GenericError to the caller. - Wire these functions via the environment object. ``` -------------------------------- ### Motoko: ICRC37 Transaction Override Function Signatures Source: https://github.com/panindustrial-org/icrc37.mo/blob/main/README.md Defines the optional function signatures for intercepting and potentially modifying or canceling various transaction types (token approval, collection approval, revocation, transfer from) before they are committed. These functions can return a modified transaction or an error to cancel the operation. ```Motoko can_approve_token : ?((trx: Transaction, trxtop: ?Transaction, notification: TokenApprovalNotification) -> Result.Result<(trx: Transaction, trxtop: ?Transaction, notification: TokenApprovalNotification), Text>); can_approve_collection : ?((trx: Transaction, trxtop: ?Transaction, notification: CollectionApprovalNotification) -> Result.Result<(trx: Transaction, trxtop: ?Transaction, notification: CollectionApprovalNotification), Text>); can_revoke_token_approval : ?((trx: Transaction, trxtop: ?Transaction, notification: RevokeTokenNotification) -> Result.Result<(trx: Transaction, trxtop: ?Transaction, notification: RevokeTokenNotification), Text>); can_revoke_collection_approval : ?((trx: Transaction, trxtop: ?Transaction, notification: RevokeCollectionNotification) -> Result.Result<(trx: Transaction, trxtop: ?Transaction, notification: RevokeCollectionNotification), Text>); can_transfer_from : ?((trx: Transaction, trxtop: ?Transaction, notification: TransferFromNotification) -> Result.Result<(trx: Transaction, trxtop: ?Transaction, notification: TransferFromNotification), Text>); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.