@validate_conversion_arguments<EOL>def to_hex(<EOL>primitive: Primitives = None, hexstr: HexStr = None, text: str = None<EOL>) -> HexStr:
if hexstr is not None:<EOL><INDENT>return HexStr(add_0x_prefix(hexstr.lower()))<EOL><DEDENT>if text is not None:<EOL><INDENT>return HexStr(encode_hex(text.encode("<STR_LIT:utf-8>")))<EOL><DEDENT>if is_boolean(primitive):<EOL><INDENT>return HexStr("<STR_LIT>") if primitive else HexStr("<STR_LIT>")<EOL><DEDENT>if isinstance(primitive, (bytes, bytearray)):<EOL><INDENT>return HexStr(encode_hex(primitive))<EOL><DEDENT>elif is_string(primitive):<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if is_integer(primitive):<EOL><INDENT>return HexStr(hex(cast(int, primitive)))<EOL><DEDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(repr(type(primitive)))<EOL>)<EOL>
Auto converts any supported value into its hex representation.
Trims leading zeros, as defined in:
https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding