I’m using taquito to parse a lambda, and the addresses are in bytes (0x0158f34461ea883382831e9d9333c1b88749130e7c00), how can I turn it into the string representation (KT1AfUy48JvqVvtcXKxBDy1guDTJSWd1n8Uv)?

1 Answer 1

let encode_address = s => (
  Js.String.slice(~from=0, ~to_=44, s)->encodePubKey,
  Js.String.sliceToEnd(~from=44, s)->hex2buf->BufferEx.toNodeBuffer->Node_buffer.toString,

This example above is right about using the encodePubKey util function in our @taquito/utils package.The example Julien supplied was a workaround for a slight difference of having an annotation added to the contract address, which currently is not supported without this workaround in Taquito.I have grabbed the following as an example from our unit tests:

  t('Should encode address properly (KT1)', () => {

The encodePubKey is designed for public key not contract address. I’ll suggest using @taquito/michel-codec package. Here’s an example to turn address into bytes and vice versa for your reference.

enter image description here

Your Answer

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