2

While examining the json rpc response I encountered a transaction inside of "internal_operation_results" which has parameters (its inside of a tokenToCash contract call). Addresses specified in those parameters do not have the standard readable format (015d3457613be02737706699883bf10f8f079be70400 in this example). While inspecting the transaction in a blockexplorer (https://tzkt.io/ooBtrjSSPuRijLpQhktxrHWR4X8auavYHCnero45vqpud39miER in this case) it shows the readable format (tz1acb9QgYWqt13WUmkXSaaM2bXwZyQthcnT).

How do I convert from the seemingly hex representation to the readable one? Explanation of the format and or code snippets in C# or python please.

Edit: (i have found a solution)
solution in form of C# code snippet

static string convert(string hexstring) { var bytes = System.Convert.FromHexString(hexstring); var prefix = (bytes[0], bytes[1], bytes[21]) switch { (0, 0, _) => new byte[] { 6, 161, 159 }, // tz1 (0, 1, _) => new byte[] { 6, 161, 161 }, // tz2 (0, 2, _) => new byte[] { 6, 161, 164 }, // tz3 (1, _, 0) => new byte[] { 2, 90, 121 } // KT1 }; var pkh = bytes[0] == 0 ? bytes[2..22] : bytes[1..21]; var arr = new byte[pkh.Length + prefix.Length]; prefix.CopyTo(arr, 0); pkh.CopyTo(arr, prefix.Length); var address = Base58Check.Base58CheckEncoding.Encode(arr); // tz1XrwX7i9Nzh8e6UmG3VnFkAeoyWdTqDf3U return address; } 

Base58Check is from nuget package (Base58Check --version 0.2.0)

2 Answers 2

0

Here is an example of how to check if the address is an originated contract or an implicit account.

https://github.com/ecadlabs/taquito/blob/516834923d7f24ec725cc4931f0dfd7fde0dc069/packages/taquito-michel-codec/src/binary.ts#L382

Then encoding to (KT1, tz1, tz2, tz3):

https://github.com/ecadlabs/taquito/blob/516834923d7f24ec725cc4931f0dfd7fde0dc069/packages/taquito-michel-codec/src/binary.ts#L1267

3
  • Hey thanks for the response. However your response does not answer my question. I do not want to check the type of account im dealing with rather i want to know how i do the conversion from "0000a444253d07bf4bc29f1c070fda0118cda6f25565" to "tz1acb9QgYWqt13WUmkXSaaM2bXwZyQthcnT". Commented Apr 12, 2022 at 7:11
  • The links above show how to do it. If the bytes start with "0", it is an implicit account -- or an originated account if it starts with "1". If the bytes are of an implicit account, then you need to also look at the "curve tag", which will indicate if it is a (tz1, tz2 or a tz3). github.com/ecadlabs/taquito/blob/… Commented Apr 12, 2022 at 8:44
  • 1
    my bad. i now see that the snippets actually do what i was looking for. I was just unable to figure that out a the time as the code is quite distributed in the repo and i have never dealt with type script before. (tried to edit my comment but that doesn't seem to work) Commented Apr 13, 2022 at 23:39
0

You can convert between readable and optimized notations using tezos-client normalize data ... of type address.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.