# Convert Byte to String in Pyteal

**URL:** https://forum.algorand.co/t/convert-byte-to-string-in-pyteal/5347
**Category:** Uncategorized
**Tags:** teal, smart-contracts
**Created:** [December 8, 2021, 5:20am UTC](https://forum.algorand.co/t/convert-byte-to-string-in-pyteal/5347 "2021-12-08T05:20:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Dalvor](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Dalvor](https://forum.algorand.co/u/Dalvor)
#### Post date: [December 8, 2021, 5:20am UTC](https://forum.algorand.co/t/convert-byte-to-string-in-pyteal/5347/1 "2021-12-08T05:20:32Z")

</div>

I am currently saving some wallet addresses in the global state for my smart contract:

```auto
option_one_wallet = Txn.application_args[8]
option_two_wallet = Txn.application_args[9]

```

However when I try to use them later, I get this error:

```auto
logic eval error: not an address

```

When I look at the smart contract state, it looks like Txn.sender() is a string while optionOneWallet and optionTwoWallet are byte strings:  
[https://testnet.algoexplorer.io/application/49823982](https://testnet.algoexplorer.io/application/49823982)

Looking through the pyteal documentation, I don’t see a way to convert byte strings to strings. What would be the best method for me to convert the byte string to a string?

---

<div class="post-metadata">

### Author: ![Ben](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.algorand.co/ben/32/1979_2.png) [@Ben](https://forum.algorand.co/u/Ben)
#### Post date: [December 8, 2021, 12:52pm UTC](https://forum.algorand.co/t/convert-byte-to-string-in-pyteal/5347/2 "2021-12-08T12:52:46Z")

</div>

Each SDK has a method to convert the 58 byte address (the one we see normally) to the 32 byte address that logic needs. The implementation is just base32 encode/decode with some padding adding/removal logic

In Python for example:  
[https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/encoding.html#algosdk.encoding.decode\_address](https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/encoding.html#algosdk.encoding.decode_address)

Ben

---

<div class="post-metadata">

### Author: ![Dalvor](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Dalvor](https://forum.algorand.co/u/Dalvor)
#### Post date: [December 8, 2021, 11:31pm UTC](https://forum.algorand.co/t/convert-byte-to-string-in-pyteal/5347/3 "2021-12-08T23:31:01Z")

</div>

Hey Ben, thanks for the reply!

Would this mean if I want to send a Algorand wallet address to be used in the smart contract I have to encode the wallet address with the encode address function? If I wanted to save these wallet addresses as a global variable to be used later, is there any way in pyteal that I can decode the addresses again or would it be done automatically?

---

<div class="post-metadata">

### Author: ![Ben](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.algorand.co/ben/32/1979_2.png) [@Ben](https://forum.algorand.co/u/Ben)
#### Post date: [December 9, 2021, 4:23pm UTC](https://forum.algorand.co/t/convert-byte-to-string-in-pyteal/5347/4 "2021-12-09T16:23:10Z")

</div>

If you’re passing it as a foreign account the SDKs will handle it for you, if its an argument it would need to be encoded since those are just byte strings.

In teal you don’t need to think about conversion since it should be the 32 byte version _always_ when it makes it to the contract logic

Ben

---

<div class="post-metadata">

### Author: ![Dalvor](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Dalvor](https://forum.algorand.co/u/Dalvor)
#### Post date: [December 12, 2021, 8:15pm UTC](https://forum.algorand.co/t/convert-byte-to-string-in-pyteal/5347/5 "2021-12-12T20:15:11Z")

</div>

I see. I was previously decoding the address incorrectly. Now it works after

```auto
wallet := types.DecodeAddress("address")
[]byte(wallet[:])

```

Thanks!
