There is a similar question but it does not fully answer this question.

In the answer for that question posted here there is mention that while it is officially not possible it is actually technically possible to do this conversion "using super weird hacks that you really don't want to hear about", but there is no further elaboration on how to achieve this goal.

I really would like to know how to use these internals to achieve this objective.

Please can we see how to use the internals mentioned in that answer to convert either from String to Address, or from Address to String (or anything that will be comparable).

1 Answer 1


You have to re-implement the algorithm described here: https://tezos.stackexchange.com/a/5908/5292 but in SmartPy.

You can then

1) pack the address 
2) loop over each bytes with
    sp.for i in range(sp.len(my_packed_address)):
        my_byte = sp.slice(packed_address, i, 1).open_some():
3) Use maps that associates bytes to the string and build your string a bit like in these functions:
    def string_of_nat(params):
        c   = sp.map({x : str(x) for x in range(0, 10)})
        x   = sp.local('x', params)
        res = sp.local('res', [])
        sp.if x.value == 0:
        sp.while 0 < x.value:
            res.value.push(c[x.value % 10])
            x.value //= 10
        return sp.concat(res.value)

    def nat_of_string(params):
        c   = sp.map({str(x) : x for x in range(0, 10)})
        res = sp.local('res', 0)
        sp.for idx in sp.range(0, sp.len(params)):
            res.value = 10 * res.value + c[sp.slice(params, idx, 1).open_some()]

If you want to do this in the tests I suggest you to wait. Maybe SmartPy will provide an easy way to do that in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.