Access Internet Computer platform capabilities via Azle IC API
mainThe IC API is exposed as functions exported from the azle package. These functions allow your canister to interact with the Internet Computer platform, providing access to system time, canister identity, cycles management, timers, and inter-canister communication.
import {
msgCaller,
time,
canisterCycleBalance,
call,
IDL,
query,
update
} from 'azle';
export default class {
@query([], IDL.Text)
whoCalledWhen(): string {
const caller = msgCaller().toText();
const now = time();
return `Called by ${caller} at ${now}`;
}
@query([], IDL.Nat)
getBalance(): bigint {
return canisterCycleBalance();
}
@update([IDL.Principal, IDL.Text], IDL.Text)
async callOther(canisterId: Principal, message: string): Promise<string> {
const result = await call(canisterId, 'echo', {
args: [message],
paramIdlTypes: [IDL.Text],
returnIdlType: IDL.Text
});
return result;
}
}