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

# RpcSchema Types

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

## `RpcSchema.Default`

Type-safe union of all JSON-RPC Methods.

### Examples

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

type Schema = RpcSchema.Default
//   ^?
```

## `RpcSchema.Eth`

Union of all JSON-RPC Methods for the `eth_` namespace.

### Examples

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

type Schema = RpcSchema.Eth
//   ^?
```

## `RpcSchema.ExtractItem`

Extracts a schema item from a [`RpcSchema.Generic`](/docs/utilities/rpcschema/types#generic) or [`RpcSchema.MethodNameGeneric`](/docs/utilities/rpcschema/types#methodnamegeneric).

### Examples

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

type Item = RpcSchema.ExtractItem<
  RpcSchema.Eth,
  'eth_getBlockByNumber'
>
const item = null as unknown as Item
//    ^?
```

## `RpcSchema.ExtractMethodName`

Type-safe union of all JSON-RPC Method Names.

### Examples

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

type MethodName =
  RpcSchema.ExtractMethodName<RpcSchema.Default>
//   ^?
```

## `RpcSchema.ExtractParams`

Extracts parameters from a [`RpcSchema.Generic`](/docs/utilities/rpcschema/types#generic) or [`RpcSchema.MethodNameGeneric`](/docs/utilities/rpcschema/types#methodnamegeneric).

### Examples

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

type Eth_GetBlockByNumber = RpcSchema.ExtractParams<
  RpcSchema.Eth,
  'eth_getBlockByNumber'
>
const parameters = null as unknown as Eth_GetBlockByNumber
//    ^?
```

## `RpcSchema.ExtractRequest`

Extracts request from a [`RpcSchema.Generic`](/docs/utilities/rpcschema/types#generic) or [`RpcSchema.MethodNameGeneric`](/docs/utilities/rpcschema/types#methodnamegeneric).

### Examples

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

type Request = RpcSchema.ExtractRequest<
  RpcSchema.Eth,
  'eth_getBlockByNumber'
>
const request = null as unknown as Request
//    ^?
```

## `RpcSchema.ExtractReturnType`

Extracts return type from a [`RpcSchema.Generic`](/docs/utilities/rpcschema/types#generic) or [`RpcSchema.MethodNameGeneric`](/docs/utilities/rpcschema/types#methodnamegeneric).

### Examples

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

type ReturnType = RpcSchema.ExtractReturnType<
  RpcSchema.Eth,
  'eth_getBlockByNumber'
>
const returnType = null as unknown as ReturnType
//    ^?
```

## `RpcSchema.From`

Type to define a custom type-safe JSON-RPC Schema.

### Examples

```ts twoslash
// @noErrors
import { RpcSchema, RpcRequest } from 'viem/utils'

type Schema = RpcSchema.From<{
  Request: {
    method: 'eth_foobar'
    params: [id: number]
  }
  ReturnType: string
}>
```

## `RpcSchema.FromViem`

Converts a [Viem-compatible RPC schema](https://viem.sh) (tuple of `{ Method, Parameters, ReturnType }`) to an Ox [`RpcSchema.Generic`](/docs/utilities/rpcschema/types#generic) (union of `{ Request, ReturnType }`).

### Examples

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

type OxSchema = RpcSchema.FromViem<
  [
    {
      Method: 'eth_blockNumber'
      Parameters?: undefined
      ReturnType: `0x${string}`
    },
    {
      Method: 'eth_chainId'
      Parameters?: undefined
      ReturnType: `0x${string}`
    }
  ]
>
```

## `RpcSchema.FromZod`

Converts a record of Zod `params`/`returns` schemas (keyed by method name) to an Ox [`RpcSchema.Generic`](/docs/utilities/rpcschema/types#generic) (union of `{ Request, ReturnType }`).

Each method's name comes from its key. Both `params` and `ReturnType` are derived from the Zod schema's input (wire) type, since raw JSON-RPC clients send and receive wire values. Decode wire results to their native representation explicitly via `zod.RpcSchema.decodeReturns`.

### Examples

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

type Schema = RpcSchema.FromZod<typeof z.RpcSchema.Eth>
//   ^?
```

## `RpcSchema.Generic`

Generic type to define a JSON-RPC Method.

### Examples

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

type Schema = RpcSchema.Generic
//   ^?
```

## `RpcSchema.MethodNameGeneric`

Generic type to define a JSON-RPC Method Name.

### Examples

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

type Name = RpcSchema.MethodNameGeneric
//   ^?
```

## `RpcSchema.Schema`

Schema input accepted by APIs that statically type JSON-RPC requests (e.g. [`Provider.from`](/docs/utilities/provider/from), [`RpcTransport.fromHttp`](https://oxlib.sh/api/RpcTransport/fromHttp)): either an Ox [`RpcSchema.Generic`](/docs/utilities/rpcschema/types#generic) or a record of Zod `params`/`returns` schemas (keyed by method name) from `ox/zod`.

## `RpcSchema.ToGeneric`

Resolves a [`RpcSchema.Schema`](/docs/utilities/rpcschema/types#schema) input to an Ox [`RpcSchema.Generic`](/docs/utilities/rpcschema/types#generic). A Zod namespace is converted via [`RpcSchema.FromZod`](/docs/utilities/rpcschema/types#fromzod); a `Generic` is passed through; otherwise falls back to [`RpcSchema.Default`](/docs/utilities/rpcschema/types#default).

## `RpcSchema.ToViem`

Converts an Ox [`RpcSchema.Generic`](/docs/utilities/rpcschema/types#generic) (union of `{ Request, ReturnType }`) to a [Viem-compatible RPC schema](https://viem.sh) (tuple of `{ Method, Parameters, ReturnType }`).

### Examples

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

type ViemSchema = RpcSchema.ToViem<
  | {
      Request: {
        method: 'eth_blockNumber'
        params?: undefined
      }
      ReturnType: `0x${string}`
    }
  | {
      Request: { method: 'eth_chainId'; params?: undefined }
      ReturnType: `0x${string}`
    }
>
```

## `RpcSchema.Wallet`

Union of all JSON-RPC Methods for the `wallet_` namespace.

### Examples

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

type Schema = RpcSchema.Wallet
//   ^?
```
