Read ASA from Smart contract - General - Algorand

Read ASA from Smart contract

post by pagito on Oct 8, 2021

Hi everyone,

I can’t use this opcode: asset_params_get i. It always returns 0s.


txn Assets 0 // ASA ID in assets array
asset_params_get AssetTotal

P.S. Using teal 5, but it didn’t work either on previous versions.

post by pagito on Oct 9, 2021

Suddenly it started working

post by pagito on Oct 11, 2021

Found out that it’s not working with Atomic transfer. Anyone else experiencing the same?

post by fabrice on Oct 11, 2021

Can you share a minimum example on TestNet which creates the issue?

Ideally it should contain a TEAL script and the list of goal command / script you used, so we can easily reproduce the issue.

post by pagito on Oct 11, 2021

Did more tests, it doesn’t work with single tnx either. I’m not sure, how it worked several days ago. Here is the example on testnet.

TEAL code

#pragma version 5

// Handle each possible OnCompletion type. We don't have to worry about
// handling ClearState, because the ClearStateProgram will execute in that
// case, not the ApprovalProgram.

// check if the app is being created, if not save creator
int 0
txn ApplicationID // current stateful smart contract
==
bz not_creation

// Check Storage vars
txn GlobalNumUint
int 0
==
txn GlobalNumByteSlice
int 0
==
&&
txn LocalNumUint
int 0
==
&&
txn LocalNumByteSlice
int 0
==
&&
bz failed

int 1
return

not_creation:

txn OnCompletion
int NoOp
==
bnz handle_noop

txn OnCompletion
int OptIn
==
bnz handle_optin

txn OnCompletion
int CloseOut
==
bnz handle_closeout

txn OnCompletion
int UpdateApplication
==
bnz handle_updateapp

txn OnCompletion
int DeleteApplication
==
bnz handle_deleteapp

// Unexpected OnCompletion value. Should be unreachable.
err

handle_noop:
// Handle NoOp
txn Assets 0
store 0

txn Assets 1
store 1

load 0
asset_params_get AssetTotal
pop
pop

load 1
asset_params_get AssetTotal
pop
pop

load 0
asset_params_get AssetDecimals
pop
pop

load 1
asset_params_get AssetUnitName
pop
pop

b finished

handle_optin:
// Handle OptIn
b finished

handle_closeout:
// Handle CloseOut

// By default, disallow updating or deleting the app. Add custom authorization
// logic below to allow updating or deletion in certain circumstances.
handle_updateapp:
handle_deleteapp:
err

failed:
int 0
return

finished:
int 1
return

Randomly taken ASAs from testnet:

ASSET1=408947

ASSET2=14704676

App call:


goal app call --app-id ${APPID} --from ${ACCOUNT1} --foreign-asset ${ASSET1} --foreign-asset ${ASSET2} --out=tt.tx

goal -v
12884901889
3.0.1.stable [rel/stable] (commit #b619b940)
go-algorand is licensed with AGPLv3.0
source code available at https://github.com/algorand/go-algorand

goal node status
Last committed block: 17209432
Time since last block: 3.5s
Sync Time: 0.0s
Last consensus protocol: https://github.com/algorandfoundation/specs/tree/bc36005dbd776e6d1eaf0c560619bb183215645c
Next consensus protocol: https://github.com/algorandfoundation/specs/tree/bc36005dbd776e6d1eaf0c560619bb183215645c
Round for next consensus protocol: 17209433
Next consensus protocol supported: true
Last Catchpoint:
Genesis ID: testnet-v1.0
Genesis hash: SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=

asset_params_get returns 0s on each case.

post by fabrice on Oct 12, 2021

How did you read the output of asset_params_get?

Did you use the TEAL Debugger or dryrun?

post by pagito on Oct 12, 2021

I used TEAL debugger:


goal clerk dryrun -t tt.tx --dryrun-dump  -o dr.msgp
tealdbg debug --remote-debugging-port 234 test.teal -d dr.msgp & socat tcp-listen:9392,reuseaddr,fork tcp:localhost:234

post by fabrice on Oct 12, 2021

It is most likely an issue with the debugger, not an issue with TEAL.

If you ran the transaction and, e.g., compared the asset total to the expected asset total, you would see it passes the test.

Regarding the debugger, can you try instead:


tealdbg debug --remote-debugging-port 234 test.teal -t tt.tx --painless & socat tcp-listen:9392,reuseaddr,fork tcp:localhost:234

post by pagito on Oct 12, 2021

That debugger didn’t work either. But you are right, issue is with debugger. Tested by running transaction and it works as expected.

Thanks!