How to convert public key back to address in js sdk

I Convert an address to publick key to send to the application.

How to convert it back after it send to the application as a global state?

I get this global state as a string like “ZXUc/psAtm6K6AOMpvytibbSa8H6WFc6O8XTp/rHuEE=”

And the application id is 17990232.
I tried so many way to convert it back, all. failed.

1 Like

Is this what you are looking for?

ZXUc/psAtm6K6AOMpvytibbSa8H6WFc6O8XTp/rHuEE= is base64 format of the address… just put it to base32, and that is your address you are looking for

1 Like

In command line:

$ base64 -d <<< ZXUc/psAtm6K6AOMpvytibbSa8H6WFc6O8XTp/rHuEE= | base32
MV2RZ7U3AC3G5CXIAOGKN7FNRG3NE26B7JMFOOR3YXJ2P6WHXBAQ====
MV2RZ7U3AC3G5CXIAOGKN7FNRG3NE26B7JMFOOR3YXJ2P6WHXBAQ====

Note that addresses have a checksum at the end, which the above does not have.

You can do the conversion with checksum with this python one-liner in console:

$ python3 -c 'import base64; import algosdk; print(algosdk.encoding.encode_address(base64.b64decode("ZXUc/psAtm6K6AOMpvytibbSa8H6WFc6O8XTp/rHuEE=")))'
MV2RZ7U3AC3G5CXIAOGKN7FNRG3NE26B7JMFOOR3YXJ2P6WHXBA4IGKRJ4

You need to install Python and the Python Algorand SDK beforehand:

$ python3 -m pip install py-algorand-sdk

JS SDK has similar functions.

1 Like