2

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
-1

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);
        do
        {
            if (address.StartsWith("00"))
            {
                address = address.Remove(0, 2);
            }
            else
                break;
        } 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.