You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@dfinity/cmc

Package Overview
Dependencies
Maintainers
10
Versions
908
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dfinity/cmc

A library for interfacing with the cycle minting canister.

5.0.7
latest
Source
npmnpm
Version published
Weekly downloads
2.7K
-16.73%
Maintainers
10
Weekly downloads
 
Created
Source

cmc-js

A library for interfacing with the cycle minting canister.

npm version GitHub license

Table of contents

Installation

You can use cmc-js by installing it in your project.

npm i @dfinity/cmc

The bundle needs peer dependencies, be sure that following resources are available in your project as well.

npm i @dfinity/agent @dfinity/candid @dfinity/principal @dfinity/utils

Usage

The features are available through the class CMCCanister. It has to be instantiated with the canister ID of the cycles minting canister. On mainnet, its ID is rkp4c-7iaaa-aaaaa-aaaca-cai.

e.g. querying the current Icp to cycles conversion rate.

import { CMCCanister } from "@dfinity/cmc";
import { createAgent } from "@dfinity/utils";

const agent = await createAgent({
  identity,
  host: HOST,
});

const { getIcpToCyclesConversionRate } = CMCCanister.create({
  agent,
  canisterId: CYCLES_MINTING_CANISTER_ID,
});

const rate = await getIcpToCyclesConversionRate();

Features

cmc-js implements following features:

:factory: CMCCanister

:link: Source

Static Methods

:gear: create
MethodType
create(options: CMCCanisterOptions) => CMCCanister

:link: Source

Methods

:gear: getIcpToCyclesConversionRate

Returns conversion rate of ICP to Cycles. It can be called as query or update.

MethodType
getIcpToCyclesConversionRate({ certified, }?: QueryParams) => Promise<bigint>

Parameters:

  • params: - The parameters for the call.
  • params.certified: - Determines whether the response should be certified (default: non-certified)

Returns:

Promise

:link: Source

:gear: notifyCreateCanister

Notifies Cycles Minting Canister of the creation of a new canister. It returns the new canister principal.

MethodType
notifyCreateCanister(request: NotifyCreateCanisterArg) => Promise<Principal>

Returns:

Promise

:link: Source

:gear: notifyTopUp

Notifies Cycles Minting Canister of new cycles being added to canister. It returns the new Cycles of the canister.

MethodType
notifyTopUp(request: NotifyTopUpArg) => Promise<bigint>

Returns:

Promise

:link: Source

:gear: getDefaultSubnets

This function calls the get_default_subnets method of the CMC canister, which returns a list of default subnets as Principal objects. It can be called as query or update.

MethodType
getDefaultSubnets({ certified }?: QueryParams) => Promise<Principal[]>

Parameters:

  • params: - The query parameters for the call.
  • params.certified: - Determines whether the response should be certified (default: non-certified if not specified).

Returns:

  • A promise that resolves to an array of Principal objects representing the default subnets.

:link: Source

:gear: getSubnetTypesToSubnets

This function calls the get_subnet_types_to_subnets method of the CMC canister, which returns a list of subnets where canisters can be created. These subnets are excluded from the random subnet selection process used by the CMC when no explicit subnet ID is provided during canister creation and therefore, not provided in the results of the similar function get_default_subnets.

MethodType
getSubnetTypesToSubnets({ certified, }?: QueryParams) => Promise<SubnetTypesToSubnetsResponse>

Parameters:

  • params: - The optional query parameters for the call.
  • params.certified: - Specifies whether the response should be certified. If not provided, the response defaults to non-certified.

Returns:

  • A promise that resolves to an object representing the mapping of subnet types to subnets.

:link: Source

Keywords

internet computer

FAQs

Package last updated on 15 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts