Logic eval error: transaction of type pay has non-zero fields for type axfer

Hi, I’m testing some simple smart contracts and I’m encoutering an error. I’m using pyteal to create two inner transactions in a single app call (I’ve seen that there is possible to do a maximum of 16 Inner txs).

InnerTxnBuilder.Begin(),
        InnerTxnBuilder.SetFields({
            TxnField.type_enum: TxnType.AssetTransfer,
            TxnField.asset_amount: Int(0),
            TxnField.xfer_asset: Btoi(Txn.application_args[0]),
            TxnField.asset_receiver: Global.current_application_address()
            }),
        InnerTxnBuilder.Submit(),
        
        InnerTxnBuilder.Begin(),
        InnerTxnBuilder.SetFields({
            TxnField.type_enum: TxnType.Payment,
            TxnField.asset_amount: Int(200000),
            TxnField.asset_receiver: Global.creator_address()
            }),
        InnerTxnBuilder.Submit(),
        Return(Int(1))

And calling the application I’m using this tx group:

txns = [PaymentTxn(sender,params,get_application_address(index),amount),
            ApplicationNoOpTxn(sender, params, index, accounts=["address"], app_args=[asa_id.to_bytes(8,'big')], foreign_assets=[asa_id])]

I’m getting the logic eval error: transaction of type pay has non-zero fields for type axfer but I’m not understading why. If I delete the payment inner tx part, It work fine. Can someone help me?

The issue is that a payment transaction (TxnType.Payment) is only meant for transfers of Algos, not ASA. You need to use TxnType.AssetTransfer.

See Smart contract details - Algorand Developer Portal on how to do asset transfer.

PS: I have written the code between triple backquotes ```python to make it much easier to read.

Ok thanks for the quote suggestion I will keep that in mind! By the way yes the second inner transaction wanted to be a payment so to transfer 0.2 algo. Is that right? Here I changed the TxnField.asset_amount to TxnField.amount but it gives me the same error

In that case, you also need to change asset_receiver into receiver.
See Smart contract details - Algorand Developer Portal

Ohh ok that’s clear. How this was hiding to me,i don’t know… Thank you so much