1 unstable release
0.1.0 | Jun 14, 2024 |
---|
#140 in #tokens
27KB
615 lines
ICP to Cycles Conversion Library
Disclaimer
This library is supposed to be used in a canister environment
Overview
This Rust library provides a function to convert ICP tokens into cycles programmatically. This functionality is essential for scenarios where you need to manage and deploy canisters dynamically using the Rust CDK.
Use Case
One primary use case is when building canisters for users on the fly. In such cases, you need to add cycles to the canisters programmatically and deploy them automatically. The dfx
CLI tool isn't suitable for this scenario since it is designed for manual interactions. Our library offers a programmatic solution for converting ICP tokens into cycles.
Functionality
mint_cycles
The library includes a single function: mint_cycles
. This function converts ICP tokens held by a canister into cycles.
Function Signature
fn mint_cycles(amount: Tokens)
Parameters
amount
: This parameter is of type Tokens, defined as:
pub struct Tokens {
e8s: u64,
}
Refer to ic_ledger_types::Tokens
for more details.
Assumptions
The canister calling mint_cycles holds some ICP tokens.
Canisters can hold and transfer ICP tokens. Before calling mint_cycles, you can top up your main canister with ICP tokens using a wallet of your choice or any other method.
This main canister can be used for automatically building and deploying other canisters.
Example Workflow
- Top Up Main Canister: Transfer ICP tokens to your main canister.
- Convert Tokens to Cycles: Call mint_cycles with the desired amount of tokens to convert them into cycles.
- Deploy Canisters: Use the cycles to build and deploy other canisters programmatically.
Source Code
For more details and to contribute, please refer to the source code.
This library aims to simplify the process of converting ICP tokens into cycles for dynamic canister management and deployment. We hope this helps, and we look forward to your contributions.
Dependencies
~5–12MB
~157K SLoC