Why I get logic eval error: txn index 1, len(group) is 1?

Hi everybody. I’m neophyte about teal and smart contract and I do not understand why I am getting the error above. Can someone help me? Thanks!

#pragma version 5

//check on creation
int 0
txn ApplicationID
==
bz not_creation

global GroupSize
int 2
==
gtxn 0 TypeEnum
int appl
==
&&
gtxn 1 TypeEnum
int pay
==
&&

not_creation:
int 1
return

The logic is explicitly checking that the GroupSize is 2, however after you deploy the smart contract you seem to be submitting a single transaction rather than a group of 2, so it’s failing.

You’d need to send a group transaction where the first transaction is the application call and the second transaction is a payment.

If you’re using goal you can do something like this:

goal app call --app-id $APPID -f $ADDR -o 0_appl.txn
goal clerk send -a 1000000 -f $ADDR -t $ADDR -o 1_pay.txn
cat 0_appl.txn 1_pay.txn > group.ctxn
goal clerk group -i group.ctxn -o group.gtxn
goal clerk sign -i group.gtxn -o group.stxn
goal clerk rawsend -f group.stxn

Edit:
You probably want to put an assert or a return after the last && also.

2 Likes

Thank you so much @nullun ! Just an integration: I am getting the error above in the goal app create (...) call. What am I wrong in this way?

Ah OK, so there’s potentially two routes here. Typically you would branch to a int 1; return during deployment, but you appear to have it setup so that you jump to the not_creation only after it has been deployed. So this means that during deployment you are expected to submit the deployment in a group transaction that also includes a payment transaction.

So it depends what you want to happen. Should it be checking the group size and payment transaction on deployment or on subsequent calls after deployment?

Here’s a working example assuming you want to deploy the contract, then subsequent calls require a group.

#pragma version 5

// Deploy?
txn ApplicationID
int 0
==
bnz deploy

global GroupSize
int 2
==
gtxn 0 TypeEnum
int appl
==
&&
gtxn 1 TypeEnum
int pay
==
&&
assert

deploy:
int 1
return
2 Likes

It is exactly the result I wanted to achieve! Thank you so much @nullun , have a good day!

1 Like