> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Bytes.fromNumber

:::info
`Bytes.fromNumber` is a re-export of ox's [`Bytes.fromNumber`](https://oxlib.sh/api/Bytes/fromNumber). Refer to the ox documentation for the full reference.
:::

Encodes a number value into [`Bytes.Bytes`](/docs/utilities/bytes/types#bytes).

## Imports

```ts
import { Bytes } from 'viem/utils'
```

## Examples

```ts twoslash
// @noErrors
import { Bytes } from 'viem/utils'

const data = Bytes.fromNumber(420)
// @log: Uint8Array([1, 164])
```

```ts twoslash
// @noErrors
import { Bytes } from 'viem/utils'

const data = Bytes.fromNumber(420, { size: 4 })
// @log: Uint8Array([0, 0, 1, 164])
```

## Definition

```ts
function fromNumber(
  value: bigint | number,
  options?: fromNumber.Options,
): Uint8Array
```

## Parameters

### value

* **Type:** `bigint | number`

Number value to encode.

### options

* **Type:** `fromNumber.Options`
* **Optional**

Encoding options.

## Return Type

Encoded [`Bytes.Bytes`](/docs/utilities/bytes/types#bytes).

`Uint8Array`
