Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Address conversation #165

Open
aramakam3505 opened this issue Apr 12, 2023 · 2 comments
Open

Address conversation #165

aramakam3505 opened this issue Apr 12, 2023 · 2 comments

Comments

@aramakam3505
Copy link

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.

@GAtom22
Copy link
Contributor

GAtom22 commented May 24, 2023

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

@olegshilov
Copy link
Contributor

olegshilov commented Jul 5, 2023

@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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants