Skip to content

Commit c9a4c2d

Browse files
feat: support for subaccount in admin /ledger/transfer/?to= (#224)
1 parent 7fdccc4 commit c9a4c2d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

cli/src/services/server/ledger.services.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {nonNullish} from '@dfinity/utils';
1+
import {nonNullish, toNullable} from '@dfinity/utils';
2+
import {decodeIcrcAccount} from '@icp-sdk/canisters/ledger/icrc';
23
import {AnonymousIdentity} from '@icp-sdk/core/agent';
3-
import {Principal} from '@icp-sdk/core/principal';
44
import {createAgent} from '../../api/agent.api';
55
import {ICP_LEDGER_CANISTER_ID} from '../../modules/icp-ledger';
66
import type {CliContext} from '../../types/context';
@@ -29,9 +29,11 @@ export const transfer = async ({
2929
const to = searchParams.get('to') ?? '';
3030
const amount = searchParams.get('amount');
3131

32+
const {owner, subaccount} = decodeIcrcAccount(to);
33+
3234
await icrc1_transfer({
3335
amount: nonNullish(amount) ? BigInt(amount) : 5_500_010_000n,
34-
to: {owner: Principal.fromText(to), subaccount: []},
36+
to: {owner, subaccount: toNullable(subaccount)},
3537
fee: [],
3638
memo: [],
3739
from_subaccount: [],

0 commit comments

Comments
 (0)