Fail to convert icp to cycles in canister

hi all. I make two steps to make it ,using send_dfx and notify_dfx interface in the ledger canister. there is my code

        //send ICP to minting canister
        let bh : BlockHeight = await ls.send_dfx({
            to = AccountIdentifier.fromText(CYCLES_MINTER, ?tosub);
            fee = MINFEE;
            memo = MINT_MEMO;
            from_subaccount = null;
            created_at_time = null;
            amount = { e8s = convertAmount };

        //notify minting canister
        await ls.notify_dfx({
            to_subaccount = ?tosub;
            from_subaccount = null;
            to_canister = Principal.fromText(CYCLES_MINTER);
            max_fee = MINFEE;
            block_height = bh;

I have deployed it to the main net , the caller have enough icp, but still fail.

Hi @hwdzz!

but still fail

What is the error that you get?

Did you use this interface description of the Ledger canister: ic/ledger.did at 971297fd46d2a188585ffb2d0368807f22cb5841 · dfinity/ic · GitHub?

Where does AccountIdentifier come from?


Hi Roman,

I’m getting this error when calling notify_dfx() from a Motoko canister:

Reject text: IC0503: Canister ryjl3-tyaaa-aaaaa-aaaba-cai trapped explicitly: Panicked at ‘Deserialization Failed: “Fail to decode argument 0 from table0 to record {\n to_subaccount : opt vec nat8;\n from_subaccount : opt vec nat8;\n to_canister : principal;\n max_fee : record { e8s : nat64 };\n block_height : nat64;\n}”’

The notify_dfx() call looks like this:

await ls.notify_dfx({
to_subaccount = ?toSubaccount; // opt SubAccount
from_subaccount = ?fromSubaccount; // opt SubAccount
to_canister = MINTER; // NNS minting canister principal ID: “rkp4c-7iaaa-aaaaa-aaaca-cai”
max_fee = FEE; // ICPTs
block_height = blockHeight;

I believe the “to_subaccount,” “from_subaccount,” and “max_fee” arguments are correct, as these were used successfully in a prior send_dfx() call using the same types (SubAccounts, and ICPTs).

The “block_height” argument is the awaited result of the prior send_dfx(), so I believe that this is probably also correct.

The “to_canister” argument I’m not sure about. Based on the source at line 204, it looks like “to_canister” should be a principal identifier, and not a Principal - is that right? But using either, I get this deserialization error.

Appreciate any help.

EDIT: It looks like the “to_canister” should be a Principal, and I have gotten the call to work like this.

Hi @ayjayem!

The notify_dfx call looks correct to me, it’s hard to say for sure where the problem comes from without having more context. Do you have a GitHub repo/gist with the full actor code? Also, which candid file do you use to make the calls?

Hey Roman - thanks for getting back! I’ve actually got this call working now - the challenge was in formatting the “to_subaccount” properly, as a derivative of the principal of the canister to be topped up. Appreciate the follow-up!