ASA Dispenser / Vending Machine using Smart Contract?

If you want to receive all the participation rewards of the users, what you can do is create a stateless smart contract escrow account C and an application (stateful smart contract) App that works as follows:

  • To join, a user will send a group of two transaction:
    1. Send x Algos to C
    2. Opt in to the application App that will record in the user address that they sent x Algos, and also keep in global state the total amount of Algos sent by user (call it Total)
  • C allows any transaction from C to an account you own if it is done in a group transaction with a call to App. And App will in that case allow any such transaction as long as the resulting balance of C is above Total. This allows to get all the participation rewards at any point in time.

To have an example of such a application using an escrow account, see the crowfunding stateful smart contract application.

If you want to only take part of the participation rewards, it becomes a bit more complex.
What you need to do is create one escrow account per user.
You can do it using the ideas in Bond Implementation - #7 by fabrice

2 Likes