# Sample code: receiving ICP/cycles donation

**URL:** <https://forum.dfinity.org/t/sample-code-receiving-icp-cycles-donation/4752>\
**Category:** Programs & Applications\
**Created:** [June 4, 2021, 1:18am UTC](https://forum.dfinity.org/t/sample-code-receiving-icp-cycles-donation/4752 "2021-06-04T01:18:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulLiu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulliu/32/4701_2.png) [@PaulLiu](https://forum.dfinity.org/u/PaulLiu)\
**Post date:** [June 4, 2021, 1:18am UTC](https://forum.dfinity.org/t/sample-code-receiving-icp-cycles-donation/4752/1 "2021-06-04T01:18:48Z")

</div>

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

Demo: [https://k25co-pqaaa-aaaab-aaakq-cai.ic0.app/](https://k25co-pqaaa-aaaab-aaakq-cai.ic0.app/)

Code: [GitHub - ninegua/tipjar: ICP donation deposited as Cycles](https://github.com/ninegua/tipjar)

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.

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [June 4, 2021, 1:47am UTC](https://forum.dfinity.org/t/sample-code-receiving-icp-cycles-donation/4752/2 "2021-06-04T01:47:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PaulLiu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulliu/32/4701_2.png) [@PaulLiu](https://forum.dfinity.org/u/PaulLiu)\
**Post date:** [June 4, 2021, 2:11am UTC](https://forum.dfinity.org/t/sample-code-receiving-icp-cycles-donation/4752/3 "2021-06-04T02:11:18Z")

</div>

Your reading is correct 🙂
