Skip to content

Latest commit

 

History

History
71 lines (58 loc) · 2.51 KB

README.md

File metadata and controls

71 lines (58 loc) · 2.51 KB

IC management canister interface

mops documentation

Motoko interface for the IC management canister (aaaaa-aa). The Motoko types are generated from the upstream Candid spec mirrored at did/ic.did (from dfinity/developer-docs).

See Call module documentation for automatic calculation of the cycles a call needs and attaching them to the call.

Examples

Import

import { ic } "mo:ic";
import IC "mo:ic/Types";

ic is the management canister actor; IC is the module of request/response types.

Make an HTTPS outcall

Call.httpRequest prices the outcall with pricing version 2 and attaches the cycles. Each withExpected* setter lowers the reservation, and unspent cycles are refunded. An outcall that uses more than you set is rejected.

import Call "mo:ic/Call";

let response = await Call.httpRequest("https://example.com/api")
	.withMaxResponseBytes(4_000)
	.withExpectedRoundtripTimeMs(300)
	.send();

Fetch canister status

import { ic } "mo:ic";

let canisterId = Principal.fromText("e3mmv-5qaaa-aaaah-aadma-cai");
let canisterStatus = await ic.canister_status({ canister_id = canisterId });

Debug.print("status = " # debug_show canisterStatus.status);
Debug.print("memory_size = " # debug_show canisterStatus.memory_size);
Debug.print("module_hash = " # debug_show canisterStatus.module_hash);
Debug.print("settings = " # debug_show canisterStatus.settings);

Update canister settings

Here we set the canister controllers to a single blackhole canister.

import { ic } "mo:ic";
import IC "mo:ic/Types";

let canisterId = Principal.fromText("e3mmv-5qaaa-aaaah-aadma-cai");
let settings : IC.CanisterSettings = {
	controllers = ?[Principal.fromText("e3mmv-5qaaa-aaaah-aadma-cai")];
	compute_allocation = null;
	memory_allocation = null;
	freezing_threshold = null;
	reserved_cycles_limit = null;
	log_visibility = null;
	log_memory_limit = null;
	snapshot_visibility = null;
	wasm_memory_limit = null;
	wasm_memory_threshold = null;
	environment_variables = null;
	minimum_incoming_canister_call_cycles = null;
	status_visibility = null;
};
await ic.update_settings({
	canister_id = canisterId;
	settings = settings;
	sender_canister_version = null;
});