Merchandise store
This page will guide you through the example of building the merchandise store using DeCash tokens. In this article, we call a store which sells goods the "merchant", and a "customer" is one who makes a purchase in this store.
The concept
Delegated Wallets allow merchants to create multiple multi-purpose wallets, primarily to accept DeCash tokens and distinct users who make payments.
The following sequence of actions happen in order for customers to pay for their purchases in DeCash tokens, represented by the following sequence diagram:
- The customer finally lands on the payment page, where they have to pay for their purchases in DeCash tokens.
- The merchant generates a new Delegated Wallet by invoking
CreateDelegatedWallet in DeCash API.
They receive an address like
6E63EKJYUPLL4SKM5FNX3PD7HSWZ26XPS7BXYLVWJAPDEK3VA7DERTFV4E
, which is then optionally displayed to the customer.- When deciding who is an owner of CreateDelegatedWallet, note that it would be the hot wallet you generate or store on your back end and later use to signManyToOneTransfer transactions from it, thus being able to collect DeCash tokens from multiple Delegated Wallets.
- If you don't want all Delegated Wallets to be associated with a single owner (which is visible in blockchain), you can generate new owner wallets for each Delegated Wallet, and then use CloseDelegatedWallet to collect funds from each individual wallet, as ManyToOneTransfer works only for a single owner.
- The customer is then asked to make a payment to this address.
- Effectively, the merchant invokes TransferTokens and asks the customer to sign the returned toSign transaction with their Algorand wallet. When signing the transaction, a transaction fee in DeCash tokens is displayed to the user.
- The customer signs the transaction. See signing transactions to learn more how they can do it for different wallets.
- The signed transaction is sent back to DeCash API via the SubmitTransaction endpoint.
- Once the submitted transaction is mined in the blockchain (takes around 5 seconds), it is considered final and the merchant can release the goods to the customer. Merchants can check the transaction status using TransactionStatus API endpoint.
- When needed, the merchant collects DeCash tokens from many Delegated Wallets to a single wallet using ManyToOneTransfer.
Thus, every customer goes through the same procedure of making payments to different Delegated Wallets, whereas the merchant can keep a mapping of which purchase corresponds to which delegated wallet.
info
The private keys from the wallet managing multiple Delegated Wallets should be stored on the merchant's side. It will be used to collect tokens from Delegated Wallets by using, for example, ManyToOneTransfer.