Compare txn sender to stored address


I have a stateful smart contract that stores the address of a logic account and then compares it to the sender of a transaction. However, the equality check always fails, even when I configure the addresses to match. Here’s the snippet from the smart contract where I make the check,

byte "ADDRESS"
gtxn 1 Sender

To debug, I’ve stored the value of the Sender field of the txn into a global variable (I know, there are probably better ways to debug), and here’s the global variable printout for the app,

    "tb": "Ӈ\ufffd\ufffde1\ufffdfH\u0005\ufffdA\u000f\ufffd\ufffd\u000e\ufffd\ufffd\ufffdR\f\t\ufffdE\fZq\u001ep\ufffdˎ",
    "tt": 1
  "ADDRESS": {
    "tt": 1

So the sender value is obviously encoded. But then how should I be comparing it against the stored address?

The issue is that one is a base32 string ("ADDRESS"), while the other is the actual 32 bytes of the address without the checksum ("SENDER", which is the proper way of encoding the address).

Most likely the issue is that you stored the address as follows:

byte "ADDRESS"

instead of

byte "ADDRESS"

which is the correct way of doing it.

Ah, that makes sense. Thanks for the quick reply.

I’m setting the address variable by making an application call with the address value as an argument, from a Python script using the Algo Python SDK,

txn = ApplicationNoOpTxn(

How can I get the smart contract to treat the argument as an addr? (Tried prefixing the string representation of the address with “addr:”, but the application still treated the argument as a string.)

Not tested but I guess something like

  app_args = [algosdk.encoding.decode_address("57L4BNLVKEKG6V2VBK3SCEJ2HOL4AP23VMQLPYUU5GC2RX5W4CH7VJD5OQ")]
1 Like

@Hardik another option, depending on your needs, could be passing the address in the account’s array.

In PyTeal this would be something like:

App.globalPut(Bytes("ADDRESS"), Txn.accounts[1])

Thanks @fabrice, I tested your suggestion and it worked !