evmosjs icon indicating copy to clipboard operation
evmosjs copied to clipboard

Address conversation

Open aramakam3505 opened this issue 2 years ago • 2 comments

Is there any way to convert evmos address to evmosvaloper address? In cli we use evmosd debug addr .... which gives us valoper address. Can we do the same thing using evmosjs? Any help will be appreciated.

aramakam3505 avatar Apr 12 '23 13:04 aramakam3505

Hi @aramakam3505, thanks for your question! It is not supported at the moment, but we will consider adding it in the future

GAtom22 avatar May 24 '23 17:05 GAtom22

@aramakam3505 You can try this code to convert addresses. Just change prefix argument.

import { bech32 } from 'bech32';

export function bech32Encode(address: string, prefix = 'evmos') {
  const words = bech32.toWords(Buffer.from(address.replace('0x', ''), 'hex'));

  return bech32.encode(prefix, words);
}

export function bech32Decode(address: string) {
  const { words } = bech32.decode(address);
  const hex = Buffer.from(bech32.fromWords(words)).toString('hex');

  return `0x${hex}`.toLowerCase();
}

Hope it's help

olegshilov avatar Jul 05 '23 14:07 olegshilov