Overview
The Cycles Minting Canister (CMC) is a core NNS canister responsible for converting ICP tokens into cycles, which are required to power computation on the Internet Computer. It provides two main workflows:- Canister Creation: Create new canisters by paying with cycles
- Cycle Top-Up: Convert ICP to cycles and top up existing canisters
Key Concepts
Payment Protocol
The CMC follows a two-step payment protocol:- Transfer ICP: Send ICP tokens to the CMC’s account on the ICP Ledger
- Notify: Call a CMC method (e.g.,
notify_top_up) with the block index to process the payment
Exchange Rate
The CMC maintains an ICP/XDR (Special Drawing Rights) exchange rate that determines how many cycles you receive for your ICP payment. This rate is updated regularly based on market conditions.API Methods
Top-Up Operations
notify_top_up
Converts ICP to cycles and tops up an existing canister.Index of the block on the ICP ledger containing the ICP payment
The canister to receive the cycles
NotifyTopUpResult
The amount of cycles sent to the specified canister
Error details if the operation failed
notify_mint_cycles
Mints cycles to a cycles ledger account instead of directly to a canister.Index of the ICP payment block
Optional subaccount in the cycles ledger
Optional memo for the deposit
NotifyMintCyclesResult
Success details including:
block_index: Cycles ledger block indexminted: Amount of cycles mintedbalance: New balance of the account
Canister Creation
create_canister
Creates a new canister using cycles attached to the call.Optional settings for the new canister (controllers, compute allocation, memory allocation, etc.)
Instructions for selecting which subnet to create the canister on
CreateCanisterResult
The principal ID of the newly created canister
Error with refund details if creation failed
notify_create_canister
Creates a canister using an ICP payment (two-step protocol).Index of the ICP payment block
The controller of the new canister
Optional subnet selection criteria
Optional canister settings
NotifyCreateCanisterResult
Query Methods
get_icp_xdr_conversion_rate
Returns the current ICP/XDR conversion rate with certification. Returns:IcpXdrConversionRateResponse
The conversion rate data:
timestamp_seconds: When the rate was queried (UNIX epoch)xdr_permyriad_per_icp: XDR per ICP in units of 10,000ths
CBOR-serialized hash tree for certification
System certificate for verification
get_average_icp_xdr_conversion_rate
Returns the average ICP/XDR conversion rate over a period. Returns:IcpXdrConversionRateResponse
get_subnet_types_to_subnets
Returns the mapping of subnet types to subnet principals. Returns:SubnetTypesToSubnetsResponse
Data Types
CanisterSettings
List of principals that control the canister
Compute allocation percentage (0-100)
Memory allocation in bytes
Freezing threshold in seconds
Maximum cycles that can be reserved
Who can view canister logs (controllers, public, or allowed_viewers)
WebAssembly memory limit
SubnetSelection
Choose how to select a subnet for canister creation: Subnet: Specify a particular subnet by principalThe specific subnet principal
The type of subnet (e.g., “application”, “system”)
NotifyError
Possible errors when processing ICP payments:-
Refunded: Payment was refunded (non-retriable)
reason: Description of whyblock_index: Refund block index
- Processing: Payment is being processed by another request (retriable)
-
TransactionTooOld: Payment is too old to process (non-retriable)
- Contains oldest valid block index
- InvalidTransaction: Payment doesn’t follow the protocol (non-retriable)
- Other: Generic error with code and message
Usage Examples
Top Up a Canister
Create a Canister with ICP
Create Canister with Specific Settings
Best Practices
Use Appropriate Memos
Use Appropriate Memos
When transferring ICP to the CMC, use the correct memo:
1347768404(0x50555054 in hex) for top-ups1095062083(0x41455243 in hex) for canister creation
Handle Errors Gracefully
Handle Errors Gracefully
The
NotifyError variants indicate whether errors are retriable:- Retriable:
Processing- wait and retry - Non-retriable:
Refunded,TransactionTooOld,InvalidTransaction- don’t retry
Monitor Exchange Rates
Monitor Exchange Rates
The ICP/XDR rate fluctuates. Query
get_icp_xdr_conversion_rate() before making payments to understand how many cycles you’ll receive.Set Freezing Threshold
Set Freezing Threshold
When creating canisters, consider setting a
freezing_threshold to ensure your canister won’t unexpectedly freeze due to low cycles.Related Resources
NNS Overview
Learn about the Network Nervous System
ICP Ledger
ICP Ledger canister API
Canisters
Understanding canister smart contracts
Governance
NNS Governance canister API
Source Code
The CMC implementation can be found in the IC repository:rs/nns/cmc/src/- Main CMC implementationrs/nns/cmc/cmc.did- Candid interface definitionrs/nns/integration_tests/src/cycles_minting_canister.rs- Integration tests