Hot answers tagged

2

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 strings byte-per-byte; here is a solution using bash and tezos-codec: # Encoding an UTF8 string as Michelson bytes $ MSG='"Привет, мир"' $ ...


2

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.


2

The bytes2Char function from the @taquito/utils package will convert these bytes to a string. The char2bytes is the counterpart that does the reverse.


1

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(sp.Contract): ... x_i = (sp.to_int(params.x + I)) y_j = (sp.to_int(params.y + j)) sp.failwith(Errors.SOME_ERROR) SmartPy also gives you the option to ...


1

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: 48656c6c6f20576f726c6421 in your case The 05 in the beginning is a prefix which is only used by the PACK Michelson instruction which the Bytes.pack function in ...


1

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


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