[**@tevm/utils**](../README.md) *** [@tevm/utils](../globals.md) / stringToHex # Function: stringToHex() > **stringToHex**(`value_`, `opts?`): `` `0x${string}` `` Defined in: node\_modules/.pnpm/viem@2.49.3\_bufferutil@4.1.0\_typescript@6.0.3\_utf-8-validate@5.0.10\_zod@4.4.3/node\_modules/viem/\_types/utils/encoding/toHex.d.ts:147 Encodes a UTF-8 string into a hex string - Docs: https://viem.sh/docs/utilities/toHex#stringtohex ## Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `value_` | `string` | - | | `opts?` | `StringToHexOpts` | Options. | ## Returns `` `0x${string}` `` Hex value. ## Examples ```ts import { stringToHex } from 'viem' const data = stringToHex('Hello World!') // '0x48656c6c6f20576f726c6421' ``` ```ts import { stringToHex } from 'viem' const data = stringToHex('Hello World!', { size: 32 }) // '0x48656c6c6f20576f726c64210000000000000000000000000000000000000000' ```