I am parsing some information from the topics array.

I receive 32bit padded addresses in some indexes. Is there a web3 utility function or useful helper method to get these back into normal sized addresses?

I'm not sure if I will remove the correct amount of 0's to get the same valid address Im looking for.

Please advise

  • 1
    Did you finaly find a way ?
    – Lbrth_BoC
    Jun 14 '18 at 21:27
  • @Lbrth_BoC I think I do something similar to the answer below, and then run the web3 isValid method to double check
    – CQM
    Jun 14 '18 at 22:16

A bit simpler:

function paddedToChecksumAddress(address) {
  if (address.slice(0, 2) === '0x') address = address.slice(2)
  while (address.slice(0, 2) === '00') address = address.slice(2)
  return web3.utils.toChecksumAddress('0x' + address)


web3.eth.abi.decodeParameter('address', address)

is the correct way


Try this for any length of padding:

    getAddress(address) {
        const web3Utils = require('web3-utils');

        let i = -1;
        let exit = false;
        let result = address;
        while(!exit && i < address.length){
            result = "0x" + address.substring(i);
            exit = web3Utils.isAddress(result);

        return web3Utils.toChecksumAddress(result);

This function removes any leading groups of "00", and then adds "0x" at the beginning.

public string AddressWithoutPadding(string address)
        if (address.StartsWith("0x"))
            address = address.Remove(0, 2);
            if (address.StartsWith("00"))
                address = address.Remove(0, 2);
        } while (true);
        return "0x" + address;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.