Implementing lock functionality

Hello
I am trying to implement lock functionality. so I have created new app id but getting error.
If I use old app id it 's working fine.
My steps are below

const transaction1 = algosdk.makeApplicationNoOpTxn(
    accountAddress,
    params,
    contractId,
    appArgs,
    appAccts,
    undefined,
    undefined,
    undefined
  )

const transaction2 = algosdk.makeAssetTransferTxnWithSuggestedParams(
    accountAddress,
    escrowAddress,
    undefined,
    undefined,
    amount,
    note,
    tokenId,
    params
  )

const txns = [transaction1, transaction2]
  // Group both transactions
  algosdk.assignGroupID(txns)

After this when calling algodClient.sendRawTransaction( getting below error.

Network request error. Received status 400 (): TransactionPool.Remember: transaction UIZPD7LAVIXMTR4WZ3ZKEIW647AXJXMSJIQOF3WJZOT5TYXE6VNA: logic eval error: invalid Assets index 0. Details: pc=773, opcodes=store 5 global CurrentApplicationAddress txna Assets 0

Thanks

The error says that txna Assets 0 failed, because invalid Assets index 0.
This is most likely because you did not provide the asset ID as foreign asset (aka in asset array) in the transaction app call.
See argument foreignAssets in makeApplicationNoOpTxn.
See documentation Smart contract details - Algorand Developer Portal

I also strongly recommend using the *FromObject version of the SDK calls, namely makeApplicationNoOpTxnFromObject which is much more readable.

PS: I’ve put your code in triple backquotes ``` so it looks better.

Hello
Thanks for your suggestions.
I have passed foreignAssets as below
const tokenId = 67395862
const foreignAssets = [tokenId]
const transaction1 = algosdk.makeApplicationNoOpTxn(
accountAddress,
params,
contractId,
appArgs,
appAccts,
undefined,
foreignAssets,
undefined
)

Now I am getting below error :
Network request error. Received status 400 (): TransactionPool.Remember: transaction FCQHMDFEQBVB2VXKB4AUIW7QJGSPVJRX32WUIWK2PLOYBBMBABXA: logic eval error: txn index 2, len(group) is 2. Details: pc=792, opcodes=intc 6 // 3 == gtxn 2 TypeEnum

Since this recommend back and forth, I would recommend using Discord instead.
Also, it would be great if you could provide the smart contract to help debugging and get feedback.

From what I can see, your smart contract is not using the new ABI, which would actually make the above much simpler. ABI indeed automatically set up the right transaction group and the right foreign assets/app/accounts.

See ABI Support — PyTeal documentation and Hello Beaker | Algorand Developer Portal
Beaker is experimental but makes writing smart contracts much easier.

Now for your concrete questions, it looks like you’re trying to access transaction number 2 in the group (gtxn 2), which means you are missing at least one transaction in the group as transaction numbers start at 0.

Hello @fabrice
I appreciate your effort. Thank you so much.
Can you send me link to connect on discord.

This is the Discord server:

You will need to pass the CAPTCHA step to access all channels.

Hello
I have try to join discord but it 's now allow me to enter message.
we are using contract : https://testnet.algoexplorer.io/application/121505850

We have just updated new contract so we are facing these type of error otherwise all going good in older one APP ID

Thanks.

If you only see the Welcome channel, this means that you need to pass the CAPTCHA that was sent by DM.
You need to enable DM.

If you still can’t join the server, DM directly the person who wrote the welcome message.

Hello @fabrice

Somehow I get success to resolved issue of transaction index , but now I getting below error.

Network request error. Received status 400 (): TransactionPool.Remember: transaction EC7AF5OZTPYEYTQBI6LUTTC5XG45ELYPGVKNYEJYEGYPU4DXZF7Q: logic eval error: assert failed pc=814. Details: pc=814, opcodes=== && assert