How to pass foreign_accounts to inner app call in PyTeal

Hello! In pyteal, is it possibile to pass all foreign accounts to an inner tx call?

Executing:

TxnField.accounts: Gtxn[1].accounts

complains with the following

pyteal.TealInputError: inner transaction set array field TxnField.accounts with non-array value

You can pass it as a python list like TxnField.accounts: [Gtxn[1].accounts[0], Gtxn[1].accounts[1],...]

And if you call it multiple times it’ll append to the list

Ben

What if the outer app call can have a different number of foreign accounts?
That static implementation you proposed would not work unfortunately.

Sure, you can iterate over the length of the outer array and sequential calls to InnerTxnBuilder.SetField(TxnField.accounts, Gtxn[1].accounts[scratchVar.load()]) should append the acct to the list

Ben

Ah nice! so subsequent calls to SetField are going to push values on accounts array.
https://pyteal.readthedocs.io/en/stable/api.html?highlight=setfield#pyteal.InnerTxnBuilder.SetField
Many thanks!