# The best way to enable payments to canisters from users?

**URL:** <https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843>\
**Category:** Getting Started\
**Created:** [April 1, 2022, 9:43pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843 "2022-04-01T21:43:44Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnonymousCoder](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/anonymouscoder/32/4747_2.png) [@AnonymousCoder](https://forum.dfinity.org/u/AnonymousCoder)\
**Post date:** [April 1, 2022, 9:43pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/1 "2022-04-01T21:43:44Z")

</div>

Hello!

I’ve been thinking about this for some time now and have come to some conclusion (which I yet need to test out and see if it works the way I imagined it to), but I am not sure if it’s the only and / or best way to do so and would like your opinion on it.

I would like to have an app that is able to allow users to purchase whatever (let’s say NFT’s) that are listed for sale. But I did not find any other way of possibly doing so right now than using a combination of the following (this is my current plan):

1. Through javascript, there would be a call made to ledger canister (i have one deployed locally for testing) by importing a ledger canister, then calling it’s `send_dfx` method to transfer funds to my smart contract canister (ie: user sends ICP to my smart contract canister by calling ledger canister directly)
2. If that call was a success (this would need to be checked in JS I guess after the async method is completed) I can then make another call to the ledger canister to notify it of the transfer so that it invokes the `transaction_notification` method in my canister (to which the user has sent the payment in step 1). In that method in my SC i would then do checks to see if the address matches the user’s address, price matches token price etc… Then, I would send him the item he bought

Is this the way to do this (the only / best way currently) ? Are there any drawbacks to this method (other than if a user leaves the page before the second when the call to ledger notify method is made) ?

Or is there something a lot more simple that would allow me to do what I want?

---

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [April 2, 2022, 12:21am UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/2 "2022-04-02T00:21:31Z")

</div>

I think @anon74414410 was working on something related to this.

---

<div class="post-metadata">

**Author:** ![AnonymousCoder](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/anonymouscoder/32/4747_2.png) [@AnonymousCoder](https://forum.dfinity.org/u/AnonymousCoder)\
**Post date:** [April 2, 2022, 8:16am UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/3 "2022-04-02T08:16:08Z")

</div>

Thank you 🙂 I hope he gets to see this eventually and posts his own thoughts or solution 🙂 In the meantime, there must be a way people are currently doing this, as there are services like Entrepot for example which already have this implemented

---

<div class="post-metadata">

**Author:** ![AnonymousCoder](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/anonymouscoder/32/4747_2.png) [@AnonymousCoder](https://forum.dfinity.org/u/AnonymousCoder)\
**Post date:** [April 3, 2022, 4:47pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/4 "2022-04-03T16:47:01Z")

</div>

bump to see if anyone has anything more to add.

---

<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:** [April 3, 2022, 5:02pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/5 "2022-04-03T17:02:30Z")

</div>

Send\_dfx to the canister, then have a deposit function that takes a block and processes the payment. Add the block to a tracker so it can’t be used again, Check the block, make sure it matches the deposit, then credit the user for the payment and take action. If it didn’t match, remove the block from the tracker.

---

<div class="post-metadata">

**Author:** ![AnonymousCoder](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/anonymouscoder/32/4747_2.png) [@AnonymousCoder](https://forum.dfinity.org/u/AnonymousCoder)\
**Post date:** [April 3, 2022, 6:12pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/6 "2022-04-03T18:12:22Z")

</div>

Alright, so pretty much what I had in plan already then? Is there a need to send a second tx to ledger from the client to trigger the `transaction_notification` in my canister where I would handle fulfillment logic (ie sending NFT to the user), or would just a callback once a successful async call to ledger for `send_dfx` was made do? Is it safe to assume a tx was successful if a call to `send_dfx` was made, so we could go straight to a method in the canister that assigns whatever has been bought to the user, or is that vulnerable if not checked in `transaction_notification` hook callback?

Thank you very much for this, I really appreciate it ! 🙂 Needed to get a confirmation from someone who has done it or tested it like yourself to be sure it’s the way to go!

---

<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:** [April 4, 2022, 4:29pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/7 "2022-04-04T16:29:51Z")

</div>

The issue with notify was that a malicious canister could hang your ledger by never returning a value. Thus it is being deprecated. get\_block has a similar ddos vector, but at least the attacker has to pay cycles for it. I would not assume that your send\_dfx works perfectly. Check the block and make sure.

Some of the checking logic can be found at [aramakme\_nft\_auction/main.mo at f0ca7fb629814dc24a90ad84c7d024a49390e38b · aramakme/aramakme\_nft\_auction · GitHub](https://github.com/aramakme/aramakme_nft_auction/blob/f0ca7fb629814dc24a90ad84c7d024a49390e38b/main.mo#L1142). ← uses a proxy canister to check blocks because it used to(maybe still is) only available to protobuff

---

<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:** [April 4, 2022, 4:58pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/8 "2022-04-04T16:58:57Z")

</div>

My solution is mostly done - we haven’t announced it yet as I resolve some final security / scaling considerations, but that’s what I’ll be working on this sprint! News should be coming before much longer

---

<div class="post-metadata">

**Author:** ![AnonymousCoder](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/anonymouscoder/32/4747_2.png) [@AnonymousCoder](https://forum.dfinity.org/u/AnonymousCoder)\
**Post date:** [April 4, 2022, 5:40pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/9 "2022-04-04T17:40:15Z")

</div>

Thank you both for providing help on this matter 🙂 It gives me something to work with until @anon74414410 is done with his solution (which I hope would perhaps provide a more streamlined approach and ease up this kind of app flow).

---

<div class="post-metadata">

**Author:** ![simdi.jinkins](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/simdi.jinkins/32/5189_2.png) [@simdi.jinkins](https://forum.dfinity.org/u/simdi.jinkins)\
**Post date:** [May 30, 2022, 2:54pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/10 "2022-05-30T14:54:20Z")

</div>

Hey @anon74414410 was wondering how your solution looks currently ? Working on ICP payments too.

---

<div class="post-metadata">

**Author:** ![AnonymousCoder](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/anonymouscoder/32/4747_2.png) [@AnonymousCoder](https://forum.dfinity.org/u/AnonymousCoder)\
**Post date:** [May 30, 2022, 3:39pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/11 "2022-05-30T15:39:31Z")

</div>

If I am correctly informed, it got dropped unfortunately and the replacement for it will come out only some time in 2023…

---

<div class="post-metadata">

**Author:** ![simdi.jinkins](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/simdi.jinkins/32/5189_2.png) [@simdi.jinkins](https://forum.dfinity.org/u/simdi.jinkins)\
**Post date:** [May 30, 2022, 4:02pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/12 "2022-05-30T16:02:07Z")

</div>

Wow, you know why that happened ?

---

<div class="post-metadata">

**Author:** ![AnonymousCoder](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/anonymouscoder/32/4747_2.png) [@AnonymousCoder](https://forum.dfinity.org/u/AnonymousCoder)\
**Post date:** [May 30, 2022, 4:05pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/13 "2022-05-30T16:05:14Z")

</div>

I believe they said that “it’s not as important as other things” and pushed it further away down the backlog.

---

<div class="post-metadata">

**Author:** ![simdi.jinkins](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/simdi.jinkins/32/5189_2.png) [@simdi.jinkins](https://forum.dfinity.org/u/simdi.jinkins)\
**Post date:** [May 30, 2022, 4:11pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/14 "2022-05-30T16:11:27Z")

</div>

Thanks, how did you solve this at the end ?

---

<div class="post-metadata">

**Author:** ![AnonymousCoder](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/anonymouscoder/32/4747_2.png) [@AnonymousCoder](https://forum.dfinity.org/u/AnonymousCoder)\
**Post date:** [May 30, 2022, 4:12pm UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/15 "2022-05-30T16:12:04Z")

</div>

I didn’t yet. But I think the only way (or the best way) of doing it is what I had in mind initially.

---

<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:** [May 31, 2022, 6:31am UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/16 "2022-05-31T06:31:26Z")

</div>

> [@simdi.jinkins](#):
>
> Wow, you know why that happened ?

> [@Payments - Invoice Canister Design Review](https://forum.dfinity.org/t/payments-invoice-canister-design-review/9843/47):
>
> Hello all - eng manager from the SDK team here. Here is the path forward for the invoice canister and IC based payments workflows in general: the invoice canister authored by Kyle will be provided as sample code [here](https://github.com/dfinity/invoice-canister). Ultimately, it’s a showcase of how invoices and payments can be facilitated on Internet Computer, but due to [considerations raised](https://github.com/dfinity/invoice-canister/issues) by our security team at DFINITY, we as an organization, have decided not to officially endorse it as the defecto invoice solution on Internet Compute…

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [May 31, 2022, 8:36am UTC](https://forum.dfinity.org/t/the-best-way-to-enable-payments-to-canisters-from-users/11843/17 "2022-05-31T08:36:38Z")

</div>

Cross-posting…

> [@Payments - Invoice Canister Design Review](https://forum.dfinity.org/t/payments-invoice-canister-design-review/9843/48):
>
> Would Quark help?
