Is it possible to create an ASA during smart contract execution?

Is it possible to create an ASA during the execution of a smart contract?

Essentially, I only want to create the NFT if I know it’s being sold. The NFT in question will be dynamically generated based on some state.

I want to avoid having to create a possibly redundant asset prior to smart contract execution, as it might mean I’ve created it for no reason.

It feels like a slightly chicken and egg problem, what do you think?

For that purpose, you need to use the following pattern:
create an escrow account using a stateless smart contract that only allows transactions when done in an atomic transfer (aka group) with an application call.

Then the application can authorize the ASA creation application from the escrow account.
You just need to put enough Algos in the escrow account to pay for the ASA creation.

See 4. Building Applications - Algorand Developer Portal for the general pattern.
See Example Crowdfunding Stateful Smart Contract Application | Algorand Developer Portal for an actual example using the pattern (note that the example uses the escrow account to make payments, but making payments and creating an ASA are both transactions).

1 Like