Skip to content

Commit 329990c

Browse files
docs: replace candid idl mumbo jumbo with zod and j (#707)
* docs: replace candid idl mumbo jumbo with zod and j Signed-off-by: David Dal Busco <david.dalbusco@outlook.com> * 📄 Update LLMs.txt snapshot for PR review --------- Signed-off-by: David Dal Busco <david.dalbusco@outlook.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 5df5265 commit 329990c

2 files changed

Lines changed: 149 additions & 65 deletions

File tree

.llms-snapshots/llms-full.txt

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12543,7 +12543,7 @@ The `@junobuild/functions/canisters` module provides a unified interface for int
1254312543

1254412544
* ⚙️ Type-safe interfaces for well-known IC canisters
1254512545
* 🧩 Modular structure with independent sub-packages
12546-
* 🔄 Up-to-date Candid declarations and types
12546+
* 🔄 Up-to-date declarations and types
1254712547
* 🧪 Battle-tested through production applications
1254812548

1254912549
---
@@ -12576,29 +12576,29 @@ You can interact with the ICP Ledger through the class `IcpLedgerCanister`.
1257612576
Sends ICP using the Ledger canister `transfer` method.
1257712577

1257812578
```
12579-
transfer(params: { args: IcpLedgerDid.TransferArgs}): Promise<IcpLedgerDid.TransferResult>
12579+
transfer(params: { args: TransferArgs}): Promise<TransferResult>
1258012580
```
1258112581

1258212582
#### Parameters:
1258312583

1258412584
* `args`: The ledger transfer arguments
12585-
* `to`: Destination account identifier (AccountIdentifier)
12585+
* `to`: Destination account identifier (`Uint8Array`)
1258612586
* `amount`: Transfer amount object with `e8s` (bigint)
1258712587
* `fee`: Fee object with `e8s` (bigint)
1258812588
* `memo`: Optional transfer memo (bigint)
12589-
* `from_subaccount`: Optional subaccount (Uint8Array | number\[\])
12589+
* `from_subaccount`: Optional subaccount (`Uint8Array`)
1259012590
* `created_at_time`: Optional timestamp object with `timestamp_nanos` (bigint)
1259112591

1259212592
#### Returns:
1259312593

12594-
* `Promise<IcpLedgerDid.TransferResult>`: The result of the ICP transfer
12595-
* On success: `{ Ok: bigint }` (block height)
12594+
* `Promise<TransferResult>`: The result of the ICP transfer
12595+
* On success: `{ Ok: bigint }` (block index)
1259612596
* On error: `{ Err: TransferError }`
1259712597

1259812598
#### Example:
1259912599

1260012600
```
12601-
import { IcpLedgerCanister } from "@junobuild/functions/canisters/ledger/icp";export const onExecute = async () => { const ledger = new IcpLedgerCanister(); const result = await ledger.transfer({ args: { to: "destination-account-identifier", amount: { e8s: 100_000_000n }, // 1 ICP fee: { e8s: 10_000n }, memo: 0n } }); if ("Ok" in result) { console.log("Transfer successful, block height:", result.Ok); } else { console.error("Transfer failed:", result.Err); }};
12601+
import { IcpLedgerCanister } from "@junobuild/functions/canisters/ledger/icp";export const onExecute = async () => { const ledger = new IcpLedgerCanister(); const result = await ledger.transfer({ args: { to: destinationAccountIdentifier, // Uint8Array amount: { e8s: 100_000_000n }, // 1 ICP fee: { e8s: 10_000n }, memo: 0n } }); if ("Ok" in result) { console.log("Transfer successful, block index:", result.Ok); } else { console.error("Transfer failed:", result.Err); }};
1260212602
```
1260312603

1260412604
---
@@ -12612,53 +12612,53 @@ Interact with ICRC compatible ledgers through the class `IcrcLedgerCanister`.
1261212612
Returns the balance of an ICRC account.
1261312613

1261412614
```
12615-
icrc1BalanceOf(params: { account: IcrcLedgerDid.Account}): Promise<IcrcLedgerDid.Tokens>
12615+
icrc1BalanceOf(params: { account: Account}): Promise<bigint>
1261612616
```
1261712617

1261812618
#### Parameters:
1261912619

1262012620
* `account`: The account to query
1262112621
* `owner`: Principal of the account owner
12622-
* `subaccount`: Optional subaccount (Uint8Array | number\[\])
12622+
* `subaccount`: Optional subaccount (`Uint8Array`)
1262312623

1262412624
#### Returns:
1262512625

12626-
* `Promise<IcrcLedgerDid.Tokens>`: The token balance (bigint)
12626+
* `Promise<bigint>`: The token balance
1262712627

1262812628
#### Example:
1262912629

1263012630
```
12631-
import { IcrcLedgerCanister } from "@junobuild/functions/canisters/ledger/icrc";import { Principal } from "@dfinity/principal";export const onExecute = async () => { const ledger = new IcrcLedgerCanister({ canisterId: "your-icrc-ledger-canister-id" }); const balance = await ledger.icrc1BalanceOf({ account: { owner: Principal.fromText("user-principal"), subaccount: [] } }); console.log("Balance:", balance);};
12631+
import { IcrcLedgerCanister } from "@junobuild/functions/canisters/ledger/icrc";import { Principal } from "@dfinity/principal";export const onExecute = async () => { const ledger = new IcrcLedgerCanister({ canisterId: "your-icrc-ledger-canister-id" }); const balance = await ledger.icrc1BalanceOf({ account: { owner: Principal.fromText("user-principal") } }); console.log("Balance:", balance);};
1263212632
```
1263312633

1263412634
### icrc1Transfer
1263512635

1263612636
Transfers tokens using the ICRC-1 `icrc1_transfer` method.
1263712637

1263812638
```
12639-
icrc1Transfer(params: { args: IcrcLedgerDid.TransferArg}): Promise<IcrcLedgerDid.TransferResult>
12639+
icrc1Transfer(params: { args: TransferArgs}): Promise<TransferResult>
1264012640
```
1264112641

1264212642
#### Parameters:
1264312643

1264412644
* `args`: Transfer arguments
12645-
* `to`: Destination account (Account object)
12645+
* `to`: Destination account (`Account`)
1264612646
* `amount`: Transfer amount (bigint)
1264712647
* `fee`: Optional fee (bigint)
12648-
* `memo`: Optional memo (Uint8Array | number\[\])
12649-
* `from_subaccount`: Optional subaccount (Uint8Array | number\[\])
12648+
* `memo`: Optional memo (`Uint8Array`)
12649+
* `from_subaccount`: Optional subaccount (`Uint8Array`)
1265012650
* `created_at_time`: Optional timestamp (bigint)
1265112651

1265212652
#### Returns:
1265312653

12654-
* `Promise<IcrcLedgerDid.TransferResult>`: The result of the transfer
12654+
* `Promise<TransferResult>`: The result of the transfer
1265512655
* On success: `{ Ok: bigint }` (block index)
1265612656
* On error: `{ Err: TransferError }`
1265712657

1265812658
#### Example:
1265912659

1266012660
```
12661-
import { IcrcLedgerCanister } from "@junobuild/functions/canisters/ledger/icrc";import { Principal } from "@dfinity/principal";export const onExecute = async () => { const ledger = new IcrcLedgerCanister({ canisterId: "your-icrc-ledger-canister-id" }); const result = await ledger.icrc1Transfer({ args: { to: { owner: Principal.fromText("recipient-principal"), subaccount: [] }, amount: 1_000_000n, fee: 10_000n } }); if ("Ok" in result) { console.log("Transfer successful, block index:", result.Ok); } else { console.error("Transfer failed:", result.Err); }};
12661+
import { IcrcLedgerCanister } from "@junobuild/functions/canisters/ledger/icrc";import { Principal } from "@dfinity/principal";export const onExecute = async () => { const ledger = new IcrcLedgerCanister({ canisterId: "your-icrc-ledger-canister-id" }); const result = await ledger.icrc1Transfer({ args: { to: { owner: Principal.fromText("recipient-principal") }, amount: 1_000_000n, fee: 10_000n } }); if ("Ok" in result) { console.log("Transfer successful, block index:", result.Ok); } else { console.error("Transfer failed:", result.Err); }};
1266212662
```
1266312663

1266412664
### icrc2TransferFrom
@@ -12668,30 +12668,62 @@ Transfers tokens using the ICRC-2 `icrc2_transfer_from` method.
1266812668
Allows transferring tokens from another user's account when an approval has previously been granted via `icrc2_approve`.
1266912669

1267012670
```
12671-
icrc2TransferFrom(params: { args: IcrcLedgerDid.TransferFromArgs}): Promise<IcrcLedgerDid.TransferFromResult>
12671+
icrc2TransferFrom(params: { args: TransferFromArgs}): Promise<TransferFromResult>
1267212672
```
1267312673

1267412674
#### Parameters:
1267512675

1267612676
* `args`: Transfer-from arguments
12677-
* `from`: Source account (Account object)
12678-
* `to`: Destination account (Account object)
12677+
* `from`: Source account (`Account`)
12678+
* `to`: Destination account (`Account`)
1267912679
* `amount`: Transfer amount (bigint)
1268012680
* `fee`: Optional fee (bigint)
12681-
* `memo`: Optional memo (Uint8Array | number\[\])
12682-
* `spender_subaccount`: Optional spender subaccount (Uint8Array | number\[\])
12681+
* `memo`: Optional memo (`Uint8Array`)
12682+
* `spender_subaccount`: Optional spender subaccount (`Uint8Array`)
1268312683
* `created_at_time`: Optional timestamp (bigint)
1268412684

1268512685
#### Returns:
1268612686

12687-
* `Promise<IcrcLedgerDid.TransferFromResult>`: The result of the transfer-from operation
12687+
* `Promise<TransferFromResult>`: The result of the transfer-from operation
1268812688
* On success: `{ Ok: bigint }` (block index)
1268912689
* On error: `{ Err: TransferFromError }`
1269012690

1269112691
#### Example:
1269212692

1269312693
```
12694-
import { IcrcLedgerCanister } from "@junobuild/functions/canisters/ledger/icrc";import { Principal } from "@dfinity/principal";export const onExecute = async () => { const ledger = new IcrcLedgerCanister({ canisterId: "your-icrc-ledger-canister-id" }); const result = await ledger.icrc2TransferFrom({ args: { from: { owner: Principal.fromText("source-principal"), subaccount: [] }, to: { owner: Principal.fromText("destination-principal"), subaccount: [] }, amount: 500_000n } }); if ("Ok" in result) { console.log("Transfer from successful, block index:", result.Ok); } else { console.error("Transfer from failed:", result.Err); }};
12694+
import { IcrcLedgerCanister } from "@junobuild/functions/canisters/ledger/icrc";import { Principal } from "@dfinity/principal";export const onExecute = async () => { const ledger = new IcrcLedgerCanister({ canisterId: "your-icrc-ledger-canister-id" }); const result = await ledger.icrc2TransferFrom({ args: { from: { owner: Principal.fromText("source-principal") }, to: { owner: Principal.fromText("destination-principal") }, amount: 500_000n } }); if ("Ok" in result) { console.log("Transfer from successful, block index:", result.Ok); } else { console.error("Transfer from failed:", result.Err); }};
12695+
```
12696+
12697+
### icrc2Approve
12698+
12699+
Approves a spender to transfer tokens on behalf of the caller using the ICRC-2 `icrc2_approve` method.
12700+
12701+
```
12702+
icrc2Approve(params: { args: ApproveArgs}): Promise<ApproveResult>
12703+
```
12704+
12705+
#### Parameters:
12706+
12707+
* `args`: Approve arguments
12708+
* `spender`: The account being approved (`Account`)
12709+
* `amount`: The amount to approve (bigint)
12710+
* `fee`: Optional fee (bigint)
12711+
* `memo`: Optional memo (`Uint8Array`)
12712+
* `from_subaccount`: Optional subaccount of the approver (`Uint8Array`)
12713+
* `created_at_time`: Optional timestamp (bigint)
12714+
* `expected_allowance`: Optional expected current allowance for optimistic concurrency control (bigint)
12715+
* `expires_at`: Optional expiry timestamp for the approval (bigint)
12716+
12717+
#### Returns:
12718+
12719+
* `Promise<ApproveResult>`: The result of the approval
12720+
* On success: `{ Ok: bigint }` (block index)
12721+
* On error: `{ Err: ApproveError }`
12722+
12723+
#### Example:
12724+
12725+
```
12726+
import { IcrcLedgerCanister } from "@junobuild/functions/canisters/ledger/icrc";import { Principal } from "@dfinity/principal";export const onExecute = async () => { const ledger = new IcrcLedgerCanister({ canisterId: "your-icrc-ledger-canister-id" }); const result = await ledger.icrc2Approve({ args: { spender: { owner: Principal.fromText("spender-principal") }, amount: 1_000_000n } }); if ("Ok" in result) { console.log("Approval successful, block index:", result.Ok); } else { console.error("Approval failed:", result.Err); }};
1269512727
```
1269612728

1269712729
---
@@ -12709,7 +12741,7 @@ After sending ICP to the CMC top-up account for a canister, the transfer is reco
1270912741
The CMC will then convert the ICP from the given ledger block into cycles and add them to the specified canister.
1271012742

1271112743
```
12712-
notifyTopUp(params: { args: CmcDid.NotifyTopUpArg}): Promise<CmcDid.NotifyTopUpResult>
12744+
notifyTopUp(params: { args: NotifyTopUpArgs}): Promise<NotifyTopUpResult>
1271312745
```
1271412746

1271512747
#### Parameters:
@@ -12720,14 +12752,14 @@ notifyTopUp(params: { args: CmcDid.NotifyTopUpArg}): Promise<CmcDid.NotifyTopUp
1272012752

1272112753
#### Returns:
1272212754

12723-
* `Promise<CmcDid.NotifyTopUpResult>`: The result of the CMC conversion and deposit
12755+
* `Promise<NotifyTopUpResult>`: The result of the CMC conversion and deposit
1272412756
* On success: `{ Ok: bigint }` (cycles deposited)
1272512757
* On error: `{ Err: NotifyError }`
1272612758

1272712759
#### Example:
1272812760

1272912761
```
12730-
import { CMCCanister } from "@junobuild/functions/canisters/cmc";import { IcpLedgerCanister } from "@junobuild/functions/canisters/ledger/icp";import { Principal } from "@dfinity/principal";export const onExecute = async () => { // Step 1: Send ICP to the CMC top-up account const ledger = new IcpLedgerCanister(); const transferResult = await ledger.transfer({ args: { to: "cmc-top-up-account-identifier", amount: { e8s: 100_000_000n }, // 1 ICP fee: { e8s: 10_000n }, memo: 0n } }); if ("Err" in transferResult) { console.error("Transfer failed:", transferResult.Err); return; } const blockIndex = transferResult.Ok; // Step 2: Notify the CMC to convert the ICP to cycles const cmc = new CMCCanister(); const notifyResult = await cmc.notifyTopUp({ args: { block_index: blockIndex, canister_id: Principal.fromText("your-canister-id") } }); if ("Ok" in notifyResult) { console.log("Cycles deposited:", notifyResult.Ok); } else { console.error("Notify failed:", notifyResult.Err); }};
12762+
import { CMCCanister } from "@junobuild/functions/canisters/cmc";import { IcpLedgerCanister } from "@junobuild/functions/canisters/ledger/icp";import { Principal } from "@dfinity/principal";export const onExecute = async () => { // Step 1: Send ICP to the CMC top-up account const ledger = new IcpLedgerCanister(); const transferResult = await ledger.transfer({ args: { to: cmcTopUpAccountIdentifier, // Uint8Array amount: { e8s: 100_000_000n }, // 1 ICP fee: { e8s: 10_000n }, memo: 0n } }); if ("Err" in transferResult) { console.error("Transfer failed:", transferResult.Err); return; } const blockIndex = transferResult.Ok; // Step 2: Notify the CMC to convert the ICP to cycles const cmc = new CMCCanister(); const notifyResult = await cmc.notifyTopUp({ args: { block_index: blockIndex, canister_id: Principal.fromText("your-canister-id") } }); if ("Ok" in notifyResult) { console.log("Cycles deposited:", notifyResult.Ok); } else { console.error("Notify failed:", notifyResult.Err); }};
1273112763
```
1273212764

1273312765
---

0 commit comments

Comments
 (0)