https://github.com/quantum-leap-labs-inc/minting_cycles
How to programmatically mint cycles in Motoko
https://github.com/quantum-leap-labs-inc/minting_cycles
cycles dfinity dfx internet-computer-protocol motoko-language
Last synced: 2 months ago
JSON representation
How to programmatically mint cycles in Motoko
- Host: GitHub
- URL: https://github.com/quantum-leap-labs-inc/minting_cycles
- Owner: Quantum-Leap-Labs-Inc
- License: mit
- Created: 2025-03-02T14:08:46.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2025-03-02T15:04:52.000Z (4 months ago)
- Last Synced: 2025-03-02T15:22:55.773Z (4 months ago)
- Topics: cycles, dfinity, dfx, internet-computer-protocol, motoko-language
- Language: Motoko
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# **Minting Cycles in Motoko**
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)**.
## **Overview**
To mint cycles for a canister, the process involves two main steps:
1. **Send ICP to the CMC canister** via an `icrc1_transfer` transaction on the ICP ledger.
2. **Notify the CMC** with the block index and canister ID to convert the ICP into cycles for the target canister.### **Process Flow**
```mermaid
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
```## **Project Structure**
```md
/minting_cycles
│── src/minting_cycles_backend
│ ├── utils/
│ │ ├── types/
│ ├── main.mo # Main Motoko file handling cycle minting
│── README.md # Project documentation
```## **How It Works**
1. Transfers ICP to the **CMC canister**.
2. Retrieves the **block index** from the transfer.
3. Calls `notify_top_up` with the **block index** and **target canister ID**.
4. The **CMC converts ICP into cycles** and credits them to the specified canister.