Place an Algorand ARC-4 payment argument in the right group position

A method declared with a pay argument receives evidence of a payment through its position in an atomic group. Encoding its transaction ID as a normal application argument changes the call shape.

Build the payment immediately before the app call

This schematic shows two preceding unrelated group members followed by the required payment and call. The transaction argument consumes no ApplicationArgs slot. Preserve its position relative to the call when combining multiple methods in a larger group.

Method: reserve(pay,uint64)void

group index 2   Payment to the reservation application
group index 3   Application call
                ApplicationArgs[0] = method selector
                ApplicationArgs[1] = encoded uint64 reservation ID

Validate the payment contents inside the application

An adjacent pay transaction can have the wrong receiver, insufficient amount or an unexpected sender. Check the fields against the order, and validate close and rekey fields according to the signing policy. Test the group with a valid payment moved one position earlier: the contract must not accidentally accept an unrelated transaction in its place.

Sources