Sample code: receiving ICP/cycles donation

I wrote a small sample showing how one can accepts cycles donation from ICP users.

Demo: https://k25co-pqaaa-aaaab-aaakq-cai.ic0.app/

Code: GitHub - ninegua/tipjar: ICP donation deposited as Cycles

It showcases that the frontend code is free to create any identities and call into the ledger canister.

The current limitation is that the canister itself has no idea of how many cycles it has received from the user. Although the frontend can perhaps calculate it, the backend canister still cannot verify such claims with a proof. So it is only suitable for accepting donations, not payments.

9 Likes

This is awesome! Can you walk us through the flow a bit?

It looks like you

  1. Create a new Identity and put it in web storage.
  2. Then if I send ICP to that account it will detect it and call topup with your tipjar ID as the recipient of the cycles
  3. This sends the dfx to the minting canister with the top up memo
  4. Then you notify the minting canister of your transaction with the tipjar canister as your to_subaccount
  5. Cycle minting canister gives you the cycles.

Awesome example. It cleared some things up for me. I thought the to_canister was a principal and to_subAccount had to be a sub account of that canister. I wish they had chosen different words. It is kind of confusing.

2 Likes

Your reading is correct :slight_smile:

2 Likes