def _to_wei(value): original = value if value is None: return 0 if type(value) in (bytes, HexBytes): value = HexBytes(value).hex() if type(value) is float and "e+" in str(value): num, dec = str(value).split("e+") num = num.split(".") if "." in num else [num, ""] return int(num[0] + num[1][:int(dec)] + "0" * (int(dec) - len(num[1]))) if type(value) is not str: return _return_int(original, value) if value[:2] == "0x": return int(value, 16) for unit, dec in UNITS.items(): if " " + unit not in value: continue num = value.split(" ")[0] num = num.split(".") if "." in num else [num, ""] return int(num[0] + num[1][:int(dec)] + "0" * (int(dec) - len(num[1]))) return _return_int(original, value)