TEAL 'foreign apps'

Hi all,
I have a little question about the PyTeal syntax. What is the purpose of defining an array of foreign apps when deploying the smart contract, if i can’t use it inside the smart contract? In fact, the PyTeal documentation says that you need to explicitly use the app-id of the external app you want to access.

Ex: App.localGetEx(Int(0), Int(42), Bytes(“key”))

where ‘Int(42)’ is the id of the application to read from. Why can’t i just pass the index of the foreignApps array instead? (Like i do for Txn.application_args array)

I believe the application array, assets array, and accounts arrays are used as an optimization to load these from the ledger before the code is evaluated. When you load an account you are already getting the assets and apps (local storage) that associated with that account so no need to go to the application array for this specific call for local storage values.

1 Like

It’s also worth noting that the upcoming TEAL v3 release (the spec was in this PR) will expose ForeignApps and ForeignAssets to TEAL.