# RpcResponse.from

A type-safe interface to instantiate a JSON-RPC response object as per the [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification#response_object).

## Imports

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

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

## Examples

### Instantiating a Response Object

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

const response = RpcResponse.from({
  id: 0,
  jsonrpc: '2.0',
  result: '0x69420'
})
```

### Type-safe Instantiation

If you have a JSON-RPC request object, you can use it to strongly-type the response. If a `request` is provided, then the `id` and `jsonrpc` properties will be overridden with the values from the request.

```ts twoslash
import { RpcRequest, RpcResponse } from 'ox'

const request = RpcRequest.from({
  id: 0,
  method: 'eth_blockNumber'
})

const response = RpcResponse.from(
  { result: '0x69420' },
  { request }
)
```

## Definition

```ts
function from<request, response>(
  response: from.Response<request, response>,
  options?: from.Options<request>,
): Compute<from.ReturnType<response>>
```

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

## Parameters

### response

* **Type:** `from.Response<request, response>`

Opaque JSON-RPC response object.

### options

* **Type:** `from.Options<request>`
* **Optional**

Parsing options.

#### options.request

* **Type:** `request | { method: string; params?: unknown; id: number; jsonrpc: "2.0"; _returnType: unknown; }`
* **Optional**

## Return Type

Typed JSON-RPC result, or response object (if `raw` is `true`).

`Compute<from.ReturnType<response>>`
