I can't send cycles to a subaccount

How to send cycles to a subaccount of a canister hzopp-yqaaa-aaaad-aamqa-cai?

I created the address a24ab620518fb79668404793c73c7ec24ed1c6c93c404fa89a9c62536e7ed2ca, but when I try send TCYCLES from NNS to it, NNS says that the address is invalid: “Please enter a valid address.”

I got this address from

    public composite query({caller}) func userAccountBlob(): async Blob {
        Principal.toLedgerAccount(Principal.fromActor(this), ?(Principal.toBlob(caller)));
    };

and converted it to hex by TS:

  const address = Buffer.from(props.cyclesPaymentAddress!).toString('hex');

I also may send to to my canister using DFX, but for --to-subaccount <TO_SUBACCOUNT> I don’t know what is TO_SUBACCOUNT format.

Please teach me to send cycles to subaccount from both DFX and online wallets.

You need to interact with the cycles ledger(Cycles ledger | Internet Computer). It is an ICRC1/2 canister so you need to use the principal and 32 byte sub account format with your icrc1_transfer call.

I think the nns uses stringybois: ICRC-1/standards/ICRC-1/TextualEncoding.md at main · dfinity/ICRC-1 · GitHub

1 Like

I know that I need to interact with the cycles ledger.

I am asking how to encode subaccount in DFX and in NNS.

OK, for DFX you seem to have answered, but how to do this conversion (from a subaccount to the address) in practice without writing my own software?

In motoko: Mops • Motoko Package Manager

In js: @dfinity/ledger-icrc - npm ( I think )