ASC1/TEAL and Atomic Transfers

I am trying to simulate something like how Ethereum allows a contract to originate multiple transfers with an ASC1 contract.

I believe I can do this by having my ASC1 contract (written in TEAL) approve an atomic transaction group, with, for example, two transactions, T1 and T2, which would be prepared by my client (whereas in Ethereum, they’d be initiated by the contract itself.)

By my reading of the docs, my contract will run on each transaction separately and I can tell when I’m run on T1 vs T2 by looking at txn GroupIndex which would return 0 and 1 respectively. So, I can independently approve each of the sub-transactions.

However, I do not understand how I can mandate (via the contract) that the two transactions are present in the group and would not be approved otherwise. I suspect it can’t be as simple as checking the global group size (i.e. global GroupSize)

Maybe the real answer is that I should not look at txn but look at gtxn? Does that mean that my whole transaction set will be inspected by the contract running once? Or will it run N times for N transactions in a group?

Yes you can look at GroupSize. If you look at the split template, the TEAL requires that their be two transactions in an atomic transfer:

https://developer.algorand.org/docs/reference/teal/templates/split/#initial-checks

I hope that helps.

You can sign both transactions independently but they have to be submitted as a group. They can be signed with a logic signature that contains the program bytes.

Thank you, this was very helpful!