# Cbor.encode

Encodes a value into CBOR (Concise Binary Object Representation) format.

## Imports

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

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

## Examples

```ts twoslash
import { Cbor } from 'ox'

Cbor.encode([1, 2, 3])
// @log: '0x83010203'

Cbor.encode({ foo: 'bar', baz: [1, 2, 3] })
// @log: '0xa263666f6f636261726362617a83010203'

Cbor.encode('hello', { as: 'Bytes' })
// @log: Uint8Array(6) [ 101, 104, 101, 108, 108, 111 ]
```

## Definition

```ts
function encode<as>(
  data: unknown,
  options?: encode.Options<as>,
): encode.ReturnType<as>
```

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

## Parameters

### data

* **Type:** `unknown`

The value to encode.

### options

* **Type:** `encode.Options<as>`
* **Optional**

Encoding options.

#### options.as

* **Type:** `"Bytes" | "Hex" | as`
* **Optional**

The format to return the encoded value in.

## Return Type

The CBOR-encoded value.

`encode.ReturnType<as>`
