Is asset creation and transfer in a single transaction group possible?

I’m trying to write a stateful smart contract application that can

  • Create an NFT (therefore, unique ASA Id per user)
  • Have the user opt-in to receive the NFT
  • And transfer the NFT to the user

I know you can do this with two separate groups: one for asset creation and another for opting in and transferring the ASA but if possible, I want to do this in a single transaction or at the very least, in an atomic transfer.

The problem I’m running into is that the created ASA is not being a part of the foreign ASA array so I’m unable to have the user opt-in. I tried to use group transfers but I don’t have access to the ASA Id.

Is the only way to do this to have two separate transaction groups?

I think the answer is no*. In order to opt in the user would have to sign the transaction with the asset id.

*There is at least one way around it, namely rekey the users account to the application address and create inner transactions that opt in and transfer but its not a method I’d recommend.