Help Needed: How to Generate Multiple Payment Addresses Under a Canister in Motoko?

Hi everyone,

We’re working on a payment protocol on the Internet Computer and could use some assistance with generating multiple payment addresses under a single canister using Motoko.

Specifically, we need the canister to generate a new payment address (Principal ID) on demand. Each time a new payment is required, a unique address should be created.

Any guidance on how to achieve this or suggestions for best practices would be greatly appreciated. Thanks!

2 Likes

Have you considered using ICRC-2 instead?

With ICRC-2, you can make the transfer on behalf of the user, thus you don’t need multiple addresses to differentiate between payments from various users.

Instead you could store the ledger canister id and block index of the ICRC-2 transfer with each e.g. invoice to mark it as paid with that block index as payment reference.

In case of ICRC-1, you’d indeed need to create multiple addresses to differentiate between payments from various users, since the transfer is initiated by the user instead of dapp on behalf of the user.

As for this latter ICRC-1 payment flow see this example GitHub - atengberg/icrc1_payment_client_demo: Adaption of BNT-3 ICRC1 Compliant Payment Flow with web workers, Tailwind & more.

If you search for “payment”, “demo”, “example”, etc on the forums, you’ll probably find more demo implementations of payment flows.

Just to clarify a common confusion, all ICRC-2 tokens are also ICRC-1 tokens since ICRC-2 is an extension standard of ICRC-1 not a replacement or alternative standard.