App problem, TEAL level

Hi, there!

During an upcoming show, NFT/ASA will be “sold” to the audience, minted right on the spot.

I made a small sample app, along the lines of the TealScript example auction.algo.ts

My first problem was: how to call app ABI method, when there is a PayTxn among the ABI params. This was solved by Ludo @Scholtz, see app call problem, TealScript

So now the test began to run. However, the TEAL code is still not correct:

  • first, it fails with “receiver is not globals.creatorAddress”. But in the test suite the testAccount was used create the app, so it should be the creatorAddress, shouldn’t it?
  • when I comment out this line in the TealScript code, the error reads as “unavailable Asset 1020”. But it IS available, when you check it with DAppflow. asset: 1020 can be seen in the app’s global field asset.
logic eval error: unavailable Asset 1020. Details: app=1016, pc=410, opcodes=bytec_0 // "asset"; app_global_get; itxn_field XferAsset

How can I debug the TEAL code? What tools can be used? What is the method?
If you SEE the error, please write to me. Consider it as a coding challenge.

1 Like

it would be much better to show the complete code you have…

unavailable Asset 1020 probably means you did not run the bootsrap of the sc, or you did not opt in to the asa

receiver is not globals.creatorAddress probably means you are calling the buyAsset method instead calling some bootrsap method… i assume you should call buyAsset when you want to close the auction and send to the creator the auctioned usdc for example. In your code you dont show where u create application, and if it was supposed to be by testAccount.addr you perhaps have to tell the client that the original sender is testAccount

1 Like

Hi, Ludo @scholtz ,
The code is here: biz_kor
It is a tiny-tiny app – my first app (after @joe-p ).I committed it at 20:50 CET.
Thanks for your caring.

P.S. I DID run bootstrap, and got an asset id of 1020. The asset is created withon the app.
It is more simple than an auction: just a demo of tokenized RWA. So anybody can “buy” the
NFT/ASA created in the smart contract.

1 Like

unavailable Asset 1020 means it’s not in the transaction as an available resource. AVM must know all state that is accessed before execution. A the simplest way to address this is to enable resource population.

You can see an example of this here TEALScript/examples/tuple_in_box/client.ts at d8d4f78384f07fb497d3bb065a488ddd33fba869 · algorandfoundation/TEALScript · GitHub

1 Like

You mean algokit.Config.configure({ populateAppCallResources: true });?
It was already in the test.

1 Like

What version of algokit-utils are you on?

1 Like
$ cat package.json
  "dependencies": {
    "@algorandfoundation/algokit-utils": "^5.5.0",
.
.
.
$ algokit --version
algokit, version 2.0.1

From the test run I see:

  • testAccount is used to create the app.
  • app checks if Algo is sent to creator – but when is does the check, the test_account (the supposed creator) is already changed by const { algod, testAccount } = fixture.context; and money is sent to that address, and the app fails.

So now, I allocate an account from KMD to buy the NFT, and another account to create the app. Now my TEAL assertations don’t fail at once. But I get the same error: logic eval error: unavailable Asset 1079. Details: app=1075, pc=438, opcodes=bytec_0 // "asset"; app_global_get; itxn_field XferAsset

Full test run is here:

@A-Maugli ➜ .../akt02/biz_kor/projects/biz_kor-contracts (main) $ npm run test

> biz_kor-contracts@0.0.0 test
> npm run build && jest


> biz_kor-contracts@0.0.0 build
> npm run compile-contract && npm run generate-client


> biz_kor-contracts@0.0.0 compile-contract
> tealscript contracts/*.algo.ts contracts/artifacts


> biz_kor-contracts@0.0.0 generate-client
> algokit generate client contracts/artifacts/ --language typescript  --output contracts/clients/{contract_name}Client.ts

Generating TypeScript client code for application specified in /workspaces/akt02/biz_kor/projects/biz_kor-contracts/contracts/artifacts/BizKor.arc32.json and writing to contracts/clients/BizKorClient.ts
Reading application.json file from path /workspaces/akt02/biz_kor/projects/biz_kor-contracts/contracts/artifacts/BizKor.arc32.json
Generating TS client for BizKor
Writing TS client to /workspaces/akt02/biz_kor/projects/biz_kor-contracts/contracts/clients/BizKorClient.ts
Operation completed successfully

  console.log
    acc1.addr (token buyer): DDQALG7PFHBOPL2RW77CNBGMC7HFW34K7BPQGT4IFY6EUKWHDWYAGTTRSM

      at __test__/BizKor.test.ts:34:13

  console.log
    acc2.addr (app creator): I4SYCPJGSRPJX2RDQI77R7XMRXF3L46WP76IDSVFJRLSALMI4BX47FZF4I

      at __test__/BizKor.test.ts:52:13

  console.debug
    Created app 1075 from creator I4SYCPJGSRPJX2RDQI77R7XMRXF3L46WP76IDSVFJRLSALMI4BX47FZF4I

      at Object.createApp (node_modules/@algorandfoundation/src/app.ts:115:48)

  console.debug
    Transferring 400000µALGOs from I4SYCPJGSRPJX2RDQI77R7XMRXF3L46WP76IDSVFJRLSALMI4BX47FZF4I to ZKIOSI4LNXPPOGVRZDI2THOZUDCDXGUI7PJEBCN7TMM3R5FE5XDG4XOGJU

      at Object.transferAlgos (node_modules/@algorandfoundation/src/transfer/transfer-algos.ts:38:46)

  console.log
    getGlobalState assetAmountInitial: 10

      at __test__/BizKor.test.ts:98:13

  console.log
    getGlobalState assetAmount: 10

      at __test__/BizKor.test.ts:99:13

  console.log
    getGlobalState assetPrice: 1000000

      at __test__/BizKor.test.ts:100:13

  console.log
    getGlobalState asset: 1079

      at __test__/BizKor.test.ts:101:13

  console.log
    getGlobalState sellPeriodEnd: 1712047631

      at __test__/BizKor.test.ts:102:13

  console.debug
    Transferring 400000µALGOs from I4SYCPJGSRPJX2RDQI77R7XMRXF3L46WP76IDSVFJRLSALMI4BX47FZF4I to ZKIOSI4LNXPPOGVRZDI2THOZUDCDXGUI7PJEBCN7TMM3R5FE5XDG4XOGJU

      at Object.transferAlgos (node_modules/@algorandfoundation/src/transfer/transfer-algos.ts:38:46)

  console.log
    Try to opt in to asset:  1079 SHWD6OQPXA76TGTGOIEEICCVBG2DVZC74TWR7PBQCVCASVBY2CFSP6UXHU

      at __test__/BizKor.test.ts:112:13

  console.log
    buyAsset: testAccount.addr  SHWD6OQPXA76TGTGOIEEICCVBG2DVZC74TWR7PBQCVCASVBY2CFSP6UXHU

      at __test__/BizKor.test.ts:127:13

  console.log
    buyAsset: appRef.appAddress  ZKIOSI4LNXPPOGVRZDI2THOZUDCDXGUI7PJEBCN7TMM3R5FE5XDG4XOGJU

      at __test__/BizKor.test.ts:128:13

  console.log
    buyAsset: appCreatorAddr  I4SYCPJGSRPJX2RDQI77R7XMRXF3L46WP76IDSVFJRLSALMI4BX47FZF4I

      at __test__/BizKor.test.ts:129:13

 FAIL  __test__/BizKor.test.ts (11.901 s)
  BizKor
    ✓ bootstrap (1484 ms)
    ✓ getGlobalState (1580 ms)
    ✕ buyAsset (1725 ms)
    ○ skipped deleteApplication

  ● BizKor › buyAsset

    URLTokenBaseHTTPError: Network request error. Received status 400 (Bad Request): TransactionPool.Remember: transaction RHXFJLWHN4FYR5CXM7ZN46HBRECHRYO7GXED3LKFF73Y6O6PUDKA: logic eval error: unavailable Asset 1079. Details: app=1075, pc=438, opcodes=bytec_0 // "asset"; app_global_get; itxn_field XferAsset

      at Function.checkHttpError (node_modules/@algorandfoundation/src/types/urlTokenBaseHTTPClient.ts:129:11)
      at Function.formatFetchResponse (node_modules/@algorandfoundation/src/types/urlTokenBaseHTTPClient.ts:137:5)
      at AlgoHttpClientWithRetry.callWithRetry (node_modules/@algorandfoundation/src/types/algo-http-client-with-retry.ts:30:20)
      at AlgoHttpClientWithRetry.post (node_modules/@algorandfoundation/src/types/algo-http-client-with-retry.ts:68:12)
      at HTTPClient.post (node_modules/algosdk/src/client/client.ts:269:19)
      at SendRawTransaction.do (node_modules/algosdk/src/client/v2/algod/sendRawTransaction.ts:53:17)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 skipped, 2 passed, 4 total
Snapshots:   0 total
Time:        11.961 s, estimated 13 s
Ran all test suites.
@A-Maugli ➜ .../akt02/biz_kor/projects/biz_kor-contracts (main) $ 

@joe-p As my app is a “variation” on @joe-p Tealscript DOA example (proposal, voting), it would help a lot, if you could give me the repository, where this example is.

The challenge is still not solved: “unavailable asset”. See the source. Any guesses, suggestions, or solutions?

Your can easily try it in codespaces, just like the other, “more convenient” Algorand coding challenges.

Thanks for your help,
Maugli

1 Like

i think your issue is that you should write tests without dependency on other tests…

you do not run the bootstrap in this test (nor in the before each test section) : akt02/biz_kor/projects/biz_kor-contracts/__test__/BizKor.test.ts at e0f732d34166df88b0d9c3f1f7f508664a7cd4b0 · A-Maugli/akt02 · GitHub

1 Like

Dear Ludo @scholtz , you are right. In the meantime I changed the tests, and now a fixed, allocated account is used to create the app. But the problem still prevails.

1 Like

There is no “unavailable asset” error during the buyAsset method, when in the app call the asset id is also passed in the assets array:

    const compose = appClient.compose().buyAsset(
      {
        payment: tx1,
      },
      {
        sender: signer1,
        sendParams: {
          fee: algokit.microAlgos(3000),
        },
        assets: [Number(asset)],
      }
    );

    const atc = await compose.atc();
    const txs = atc.buildGroup().map((tx) => tx.txn);

Thank you for help and for your example, @scholtz

1 Like