Asset ID in inner transaction

Hi,

I am creating an inner transaction to opt-in to a ASA from a application creating transaction in PyTeal. I understand that asset array should have the asset id for that. How do I pass the asset id to this asset array so that the inner transaction can use that.

I tried setting TxnField.assets in the inner transaction then i get error : unexpected array field
I tried passing the asset id through parameter Assets in application creating transaction.
I tried passing the asset id through parameter ForeignAssets in application creating transaction. Both these are not recognised in Txn.assets[0] saying invalid Assets index 0

Please clarify.

Thanks,

The asset array TxnFields.assets is used to list assets that an application can access.
You do not need and actually cannot set this field in inner transactions.

The field you are looking for is TxnField.xfer_asset.

Hi,

Thanks for the reply. How to pass the asset id to TxnField.xfer_asset. when i directly provide the asset id like InnerTxnBuilder.SetField(TxnField.xfer_asset, Int(43714228)) getting the error : algosdk.error.AlgodHTTPError: TransactionPool.Remember: transaction BDULPKBE27L5VQ5IMC3NOW2I5AR3QNDWH5OMRS4A27XAUXQNVFOQ: logic eval error: invalid Asset reference 43714228

Please clarify.

Thanks,

You also need to put your assset 43714228 in the (foreign) assets array of the outer transaction. See Smart contract details - Algorand Developer Portal and Smart contract details - Algorand Developer Portal

Note that the receiver also needs to be in the (foreign) accounts array.