golem-base-sdk
    Preparing search index...

    Function toHex

    • Encodes a string, number, bigint, or ByteArray into a hex string

      Parameters

      • value: string | number | bigint | boolean | ByteArray

        Value to encode.

      • Optionalopts: ToHexParameters

        Options.

      Returns `0x${string}`

      Hex value.

      import { toHex } from 'viem'
      const data = toHex('Hello world')
      // '0x48656c6c6f20776f726c6421'
      import { toHex } from 'viem'
      const data = toHex(420)
      // '0x1a4'
      import { toHex } from 'viem'
      const data = toHex('Hello world', { size: 32 })
      // '0x48656c6c6f20776f726c64210000000000000000000000000000000000000000'