Overview
The Cycles Plugin supports:- Balance Management: Check canister cycles balance and status
- Top-Up Operations: Add cycles to canisters via management canister
- ICP to Cycles Conversion: Convert ICP tokens to cycles using current XDR rates
- Monitoring & Analytics: Track usage, forecasting, and automated alerts
- Batch Operations: Bulk cycles operations for multiple canisters
Core Operations
getBalance(canisterId)
Get cycles balance and status for a canister.
Parameters:
canisterId
:Principal | string
- Canister to query
Promise<ICyclesBalance>
canisterId
:Principal
- Canister IDbalance
:bigint
- Current cycles balancestatus
:string
- Canister statusfreezingThreshold
:bigint
- Freezing threshold in secondsmemorySize
:bigint
- Memory usageidle_cycles_burned_per_day
:bigint
- Daily cycles burn rate
topUp(canisterId, amount?, options?)
Add cycles to a canister.
Parameters:
canisterId
:Principal | string
- Canister to top upamount
(optional):bigint | string
- Cycles amount (default: 2T)options
(optional):ICyclesTopUpOptions
priority
:boolean
- Priority transactionmemo
:Uint8Array
- Transaction memo
Promise<void>
Example:
transfer(options)
Transfer cycles between canisters.
Parameters:
options
:ICyclesTransferOptions
from
:Principal
- Source canisterto
:Principal
- Destination canisteramount
:bigint
- Cycles amount to transfer
Promise<void>
Example:
ICP to Cycles Conversion
convertIcpToCycles(icpAmount, options?)
Convert ICP tokens to cycles.
Parameters:
icpAmount
:bigint | string
- ICP amount in e8soptions
(optional):IICPToCyclesOptions
targetCanister
:Principal
- Canister to send cycles toautoTopUp
:boolean
- Automatically top up target canister
Promise<ICyclesConversionResult>
icpAmount
:bigint
- ICP amount convertedcyclesAmount
:bigint
- Cycles receivedxdrRate
:bigint
- XDR exchange rate usedfee
:bigint
- Conversion fee
getPricing()
Get current cycles pricing information.
Returns: Promise<ICyclesPricing>
xdrRate
:bigint
- Current XDR to cycles ratecyclesPerXdr
:bigint
- Cycles per XDRicpToXdr
:number
- ICP to XDR exchange ratelastUpdated
:number
- Last update timestamp
Monitoring & Analytics
getUsageMetrics(canisterId, period?)
Get cycles usage metrics for a canister.
Parameters:
canisterId
:Principal | string
- Canister to analyzeperiod
(optional):'hour' | 'day' | 'week' | 'month'
- Metrics period (default: ‘day’)
Promise<ICyclesUsageMetrics[]>
canisterId
:Principal
- Canister IDperiod
:string
- Time periodtotalConsumed
:bigint
- Total cycles consumedavgConsumptionRate
:bigint
- Average consumption ratetimestamp
:number
- Metric timestamp
getForecast(canisterId)
Get cycles depletion forecast for a canister.
Parameters:
canisterId
:Principal | string
- Canister to forecast
Promise<ICyclesForecast>
canisterId
:Principal
- Canister IDcurrentBalance
:bigint
- Current balanceavgDailyConsumption
:bigint
- Average daily consumptiondaysUntilDepletion
:number
- Estimated days until depletionforecastDate
:Date
- Estimated depletion daterecommendedTopUp
:bigint
- Recommended top-up amountconfidence
:number
- Forecast confidence (0-100)
startMonitoring(config)
Start automated cycles monitoring.
Parameters:
config
:ICyclesMonitoringConfig
canisterIds
:Principal[]
- Canisters to monitorlowBalanceThreshold
:bigint
- Low balance alert thresholdcheckInterval
:number
- Check interval in secondsautoTopUp
(optional): Auto top-up configurationenabled
:boolean
- Enable auto top-uptopUpAmount
:bigint
- Amount to top up
Promise<void>
Example:
stopMonitoring()
Stop automated monitoring.
Returns: void
Example:
getAlerts()
Get current cycles alerts.
Returns: ICyclesAlert[]
id
:string
- Alert IDtype
:string
- Alert typeseverity
:'info' | 'warning' | 'critical'
- Severity levelcanisterId
:Principal
- Related canistermessage
:string
- Alert messagecurrentBalance
:bigint
- Current balance when alert was createdthreshold
:bigint
- Threshold that triggered alerttimestamp
:Date
- Alert timestampacknowledged
:boolean
- Whether alert was acknowledged
clearAlerts()
Clear all alerts.
Returns: void
Example:
Batch Operations
getBatchBalances(canisterIds)
Get balances for multiple canisters.
Parameters:
canisterIds
:(Principal | string)[]
- Canisters to query
Promise<ICyclesBalance[]>
- Array of balance information
Example:
batchTopUp(operations)
Top up multiple canisters.
Parameters:
operations
: Array of top-up operationscanisterId
:Principal | string
- Target canisteramount
:bigint | string
- Cycles amountoptions
:ICyclesTopUpOptions
(optional)
Promise<Array<{ canisterId: string; success: boolean; error?: string }>>
Example:
Utility Functions
formatCycles(cycles)
Format cycles amount for display.
Parameters:
cycles
:bigint
- Cycles amount
string
- Formatted cycles (e.g., “2.5T”, “1.2B”)
Example:
parseCycles(cycles)
Parse cycles string to bigint.
Parameters:
cycles
:string
- Cycles string (e.g., “2.5T”, “1B”)
bigint
- Parsed cycles amount
Example:
validateAmount(amount)
Validate and convert cycles amount.
Parameters:
amount
:bigint | string
- Amount to validate
bigint
- Validated amount
Example:
canisterExists(canisterId)
Check if a canister exists.
Parameters:
canisterId
:Principal | string
- Canister to check
Promise<boolean>
- Whether canister exists
Example:
getBalanceSummary(canisterId)
Get formatted balance summary.
Parameters:
canisterId
:Principal | string
- Canister to summarize
Promise<string>
- Balance summary
Example:
estimateConsumption(canisterId, days?)
Estimate cycles consumption over time.
Parameters:
canisterId
:Principal | string
- Canister to analyzedays
(optional):number
- Number of days to estimate (default: 30)
Promise<bigint>
- Estimated consumption
Example: