# Base64.fromHex

Encodes a [`Hex.Hex`](/api/Hex/types#hex) to a Base64-encoded string (with optional padding and/or URL-safe characters).

## Imports

:::code-group
```ts [Named]
import { Base64 } from 'ox'
```

```ts [Entrypoint]
import * as Base64 from 'ox/Base64'
```
:::

## Examples

```ts twoslash
import { Base64, Hex } from 'ox'

const value = Base64.fromHex(Hex.fromString('hello world'))
// @log: 'aGVsbG8gd29ybGQ='
```

### No Padding

Turn off [padding of encoded data](https://datatracker.ietf.org/doc/html/rfc4648#section-3.2) with the `pad` option:

```ts twoslash
import { Base64, Hex } from 'ox'

const value = Base64.fromHex(
  Hex.fromString('hello world'),
  { pad: false }
)
// @log: 'aGVsbG8gd29ybGQ'
```

### URL-safe Encoding

Turn on [URL-safe encoding](https://datatracker.ietf.org/doc/html/rfc4648#section-5) (Base64 URL) with the `url` option:

```ts twoslash
import { Base64, Hex } from 'ox'

const value = Base64.fromHex(Hex.fromString('hello wod'), {
  url: true
})
// @log: 'aGVsbG8gd29_77-9ZA=='
```

## Definition

```ts
function fromHex(
  value: Hex.Hex,
  options?: fromHex.Options,
): string
```

**Source:** [src/core/Base64.ts](https://github.com/wevm/ox/blob/main/src/core/Base64.ts#L438)

## Parameters

### value

* **Type:** `Hex.Hex`

The hex value to encode.

### options

* **Type:** `fromHex.Options`
* **Optional**

Encoding options.

#### options.pad

* **Type:** `boolean`
* **Optional**

Whether to [pad](https://datatracker.ietf.org/doc/html/rfc4648#section-3.2) the Base64 encoded string.

#### options.url

* **Type:** `boolean`
* **Optional**

Whether to Base64 encode with [URL safe characters](https://datatracker.ietf.org/doc/html/rfc4648#section-5).

## Return Type

The Base64 encoded string.

`string`
