> **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.

# RpcResponse.from

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

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

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

## Examples

### Instantiating a Response Object

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

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
// @noErrors
import { RpcRequest, RpcResponse } from 'viem/utils'

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>>
```

## 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>>`
