This repository provides an example of how to programmatically mint cycles in Motoko by interacting with the ICP Ledger and the Cycles Minting Canister (CMC).
To mint cycles for a canister, the process involves two main steps:
- Send ICP to the CMC canister via an
icrc1_transfer
transaction on the ICP ledger. - Notify the CMC with the block index and canister ID to convert the ICP into cycles for the target canister.
sequenceDiagram
User->>Ledger: Send ICP to CMC via Ledger
Ledger-->>User: Return block index
User->>CMC: Send block index and canister ID
CMC->>Canister: Mint cycles
CMC-->>User: Confirm cycles minted
/minting_cycles
│── src/minting_cycles_backend
│ ├── utils/
│ │ ├── types/
│ ├── main.mo # Main Motoko file handling cycle minting
│── README.md # Project documentation
- Transfers ICP to the CMC canister.
- Retrieves the block index from the transfer.
- Calls
notify_top_up
with the block index and target canister ID. - The CMC converts ICP into cycles and credits them to the specified canister.