I’m trying to understand how data types work in Teal. As I see, Int is represented with big endian to uint64. For example, if my argument string is “1”, btoi opcode converts it to 49.
OK. That completely makes sense. But my question was from the example above. How do you assert that AssetID sent from atomic transfer equals to AssetID you saved in the beginning. XferAsset returns int 1, not byte… so can’t use btoi…
If the Application Arg is given as byte when calling the app, then btoi converts to uint64, ans XferAsset also gives back uint64.
--app-arg strings Args to encode for application transactions (all will be encoded to a byte slice). For ints, use the form 'int:1234'. For raw bytes, use the form 'b64:A=='. For printable strings, use the form 'str:hello'. For addresses, use the form 'addr:XYZ...'.
This makes AssetID arg in Teal as byte and 1 becomes 49 after btoi.
On the other hand with goal cli --app-arg "int:1" arg keeps value as 1. As a result this block becomes valid:
gtxn 1 XferAsset // 1
load 11 //1
==
I can’t find the equivalent SDK code for int type arg (--app-arg "int:1") in the documentation. I see the example for Stateless contract: args.push(algosdk.encodeUint64(123)); but this gives the error err TypeError: algosdk.encodeUint64 is not a function.