I’m using the
https://rpc.s0.t.hmny.io API to get transaction data from blocks. I use the
hmyv2_getBlockByNumber to get top-level transaction data and then
hmy_getLogs to LogEvents.
In responses from
hmyv2_getBlockByNumber the to/from addresses are in the bech32 format (
one...), but all addresses in the logs are hex (
Will this always be the case or does Harmony plan to convert all addresses to bech32 format?
Not sure what the plans for the future are but I wrote a docker service to convert addresses.
The code for the conversion is here but you will also require the bech32.py module included or just boot up the service and call via API…
This file has been truncated.
from core.bech32 import *
from eth_utils import *
from Crypto.Hash import keccak
HRP = "one"
async def is_eth_checksum_address(address: str) -> bool:
"""Takes an Ethereum based address and checks that the checksum is valid
address (str): Eth Address
bool: Result if valid or not.
address = address.replace("0x", "")
address_hash = keccak.new(digest_bits=256)
address_hash = address_hash.update(address.lower().encode("utf-8")).hexdigest()
Thank you. Converting it is no problem, I’m already doing that with this
npm package. I’m just wondering if there will be breaking changes in the future. I don’t quite understand why top level addresses in the
hmyv2_getBlockByNumber are bech32 but everything else is hex. We just convert to hex for our own sanity/ease
I was just about to post the js version
I’m the same, don’t care what format but i generally stick to one or the other.
It would be nice to have some consistency api wise.
@giv @rongjian do we have any plans to align this in the future?
I haven’t tested this myself. But you can check if eth_/hmy_/hmyv2_ methods give different results. AFAIK that’s what they are intended for