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
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)', () => {
expect(encodePubKey('01f9b689a478253793bd92357c5e08e5ebcd8db47600')).toEqual(
'KT1XM8VUFBiM9AC5czWU15fEeE9nmuEYWt3Y'
);
});
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.