# How do i notify a canister upon receiving ICP transferred to it

**URL:** <https://forum.dfinity.org/t/how-do-i-notify-a-canister-upon-receiving-icp-transferred-to-it/24597>\
**Category:** Programs & Applications\
**Created:** [November 11, 2023, 2:41pm UTC](https://forum.dfinity.org/t/how-do-i-notify-a-canister-upon-receiving-icp-transferred-to-it/24597 "2023-11-11T14:41:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jesse](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jesse/32/37836_2.png) [@Jesse](https://forum.dfinity.org/u/Jesse)\
**Post date:** [November 11, 2023, 2:41pm UTC](https://forum.dfinity.org/t/how-do-i-notify-a-canister-upon-receiving-icp-transferred-to-it/24597/1 "2023-11-11T14:41:39Z")

</div>

I have a wallet that I’ve created. I want to be able to update users’ transaction history as they send and receive ICP. How do i go about notifying a canister whenever is has received ICP?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [November 13, 2023, 9:43am UTC](https://forum.dfinity.org/t/how-do-i-notify-a-canister-upon-receiving-icp-transferred-to-it/24597/2 "2023-11-13T09:43:41Z")

</div>

I know of three options:

- Polling. The canister checks occasionally if its balance has changed
- Some `notify_` function on the canister that can be called with a block index so that the canister can go look up the new transaction
- Let the canister itself do the transaction. We now have `icrc2_transfer_from`, which allows you to tell a canister that it shall deposit some ICP to itself

---

<div class="post-metadata">

**Author:** ![Jesse](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jesse/32/37836_2.png) [@Jesse](https://forum.dfinity.org/u/Jesse)\
**Post date:** [November 13, 2023, 1:43pm UTC](https://forum.dfinity.org/t/how-do-i-notify-a-canister-upon-receiving-icp-transferred-to-it/24597/3 "2023-11-13T13:43:31Z")

</div>

The  
’notify\_’ functions sounds like the best option for me in my case. Is there a specific function signature that the ‘notify\_’ function must conform to?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [November 13, 2023, 2:14pm UTC](https://forum.dfinity.org/t/how-do-i-notify-a-canister-upon-receiving-icp-transferred-to-it/24597/4 "2023-11-13T14:14:26Z")

</div>

No, that’s just a common pattern, nothing really standardised. [Here](https://github.com/dfinity/ic/blob/master/rs/nns/cmc/cmc.did#L195) are two examples of `notify_` functions that we have in the NNS.

---

<div class="post-metadata">

**Author:** ![Jesse](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jesse/32/37836_2.png) [@Jesse](https://forum.dfinity.org/u/Jesse)\
**Post date:** [November 13, 2023, 7:32pm UTC](https://forum.dfinity.org/t/how-do-i-notify-a-canister-upon-receiving-icp-transferred-to-it/24597/5 "2023-11-13T19:32:05Z")

</div>

After looking at the link you referenced, I realized that this actually doesn’t resolve my challenge. I intend for a canister, that I control, to be able to know when it has received an incoming transaction and upon knowing that an incoming transaction was made, that canister would then update an internal stable object that is used to keep track of the canister’s transaction history.

As the current solution, I implemented the polling method you described. Every 15 seconds or so, the canister queries the blockchain and makes updates to its transaction history when appropriate. The issue with this method is that it requires a constant timer which consumes many cycles.

I was hoping that there was some sort of `system` function signature that would allow me to program some logic to fire whenever an incoming transaction is detected; similar to how the `heartBeat` function allows you program logic thats fired upon each block propogation. I thought that’s what you were referring to when you mentioned the `notify_` function earlier.

> [@Vivienne](#):
>
> Let the canister itself do the transaction. We now have `icrc2_transfer_from`, which allows you to tell a canister that it shall deposit some ICP to itself

is there some workaround you have in mind which utilizes the `icrc2_transfer_from` method to allow me to achieve the desired effect of essentially having a canister “listen” for incoming transactions without relying on the Timer API?

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [November 13, 2023, 11:23pm UTC](https://forum.dfinity.org/t/how-do-i-notify-a-canister-upon-receiving-icp-transferred-to-it/24597/6 "2023-11-13T23:23:02Z")

</div>

pub / sub would be the pattern that you want, but that’s not a feature that the ICP ledger supports.
