Skip to main content
Share Your Experience: Take the 2024 Developer Survey
3 votes
Accepted

Convert address to string in LIGO

You cannot convert an address to a string in Michelson. You could cheat by going through pack and inspecting the binary representation but it is unlikely something you would want to do.
FFF's user avatar
  • 3,260
3 votes

How to convert hex string/bytes to ASCII characters

The bytes2Char function from the @taquito/utils package will convert these bytes to a string. The char2bytes is the counterpart that does the reverse.
Roxane Létourneau's user avatar
3 votes

Which hash function is used when converting an address from raw bytes?

It’s not hashed. You simply need to compute the base58 translation with the right prefix. Proof that it’s not hashed: this process is reversible.
FFF's user avatar
  • 3,260
2 votes
Accepted

How do you read and store a UTF-8 value in Michelson

Byte sequences in Michelson are written in hexadecimal with a leading 0x. To convert between this representation and reguar UTF8 strings, you can use any tool that is dumb enough to iterate over UTF8 ...
Raphaël Cauderlier's user avatar
1 vote
Accepted

Why does calling sp.address() with a dynamic value inside an entrypoint fail?

That is not possible, sp.address(x) expects x to be a python string. params.address is a michelson value of type string and michelson does not have any instruction to explicitly cast a string to an ...
Rodrigo Quelhas's user avatar
1 vote
Accepted

Smartpy restrict entrypoint for originated addresses (KT1)

If you are specifically interested in the address of your caller there a simpler solution than the one proposed by @rodrigo-quelhas: sp.sender is an implicit account if and only if it is exactly sp....
Raphaël Cauderlier's user avatar
1 vote

Smartpy restrict entrypoint for originated addresses (KT1)

You can use: https://github.com/RomarQ/tezos-sc-utils Usage: Utils = sp.io.import_script_from_url("https://raw.githubusercontent.com/RomarQ/tezos-sc-utils/main/smartpy/utils.py"); # And ...
Rodrigo Quelhas's user avatar
1 vote
Accepted

How do you convert a string sent to an entrypoint into its byte representation?

I struggled on this for a while but finally reached a solution. It's a bit hacky, but you just have to remove the 6 bytes that sp.pack prepends onto the bytes you actually want with sp.slice before ...
0x10's user avatar
  • 359
1 vote

How can I do string interpolation on smartpy?

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: res.value.push('0') sp....
M88ache's user avatar
  • 11
1 vote
Accepted

How can I do string interpolation on smartpy?

It is not possible to cast an int to a string in Michelson. I recommend you to have static error messages, such as: class Errors: SOME_ERROR = "SOME_ERROR" # some contract class Contract(...
Rodrigo Quelhas's user avatar
1 vote
Accepted

How are strings serialized in Tezos?

Strings are serialized as follows: 01 to indicate type string Four bytes (eight hex chars) to indicate length of string: 0000000c=0x0c=12 in your case The string represented by its ASCII values: ...
Thorkil Værge's user avatar
1 vote

Can I use escape characters in LIGO strings?

Yes, you can, using exactly the same syntax. For instance, in CameLIGO, you could write let x = Bytes.pack "toto\n\x53woo".
Gabriel Alfour's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible