evmosjs
evmosjs copied to clipboard
Address conversation
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.
Hi @aramakam3505, thanks for your question! It is not supported at the moment, but we will consider adding it in the future
@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