# RpcRequest.createStore

Creates a JSON-RPC request store to build requests with an incrementing `id`.

Returns a type-safe `prepare` function to build a JSON-RPC request object as per the [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification#request_object).

## Imports

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

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

## Examples

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

const store = RpcRequest.createStore()

const request_1 = store.prepare({
  method: 'eth_blockNumber'
})
// @log: { id: 0, jsonrpc: '2.0', method: 'eth_blockNumber' }

const request_2 = store.prepare({
  method: 'eth_call',
  params: [
    {
      to: '0x0000000000000000000000000000000000000000',
      data: '0xdeadbeef'
    }
  ]
})
// @log: { id: 1, jsonrpc: '2.0', method: 'eth_call', params: [{ to: '0x0000000000000000000000000000000000000000', data: '0xdeadbeef' }] }
```

### Type-safe Custom Schemas

It is possible to define your own type-safe schema by using [`RpcSchema.from`](/api/RpcSchema/from).

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

const schema = RpcSchema.from<
  | {
      // [!code focus]
      Request: {
        // [!code focus]
        method: 'eth_foobar' // [!code focus]
        params: [number] // [!code focus]
      } // [!code focus]
      ReturnType: string // [!code focus]
    }
  | {
      // [!code focus]
      Request: {
        // [!code focus]
        method: 'eth_foobaz' // [!code focus]
        params: [string] // [!code focus]
      } // [!code focus]
      ReturnType: string // [!code focus]
    }
>() // [!code focus]

const store = RpcRequest.createStore({ schema }) // [!code focus]

const request = store.prepare({
  method: 'eth_foobar', // [!code focus]
  // ^?
  params: [42]
})
```

## Definition

```ts
function createStore<schema>(
  options?: createStore.Options<schema>,
): createStore.ReturnType<schema>
```

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

## Parameters

### options

* **Type:** `createStore.Options<schema>`
* **Optional**

Request store options.

#### options.id

* **Type:** `number`
* **Optional**

The initial request ID.

#### options.schema

* **Type:** `schema | Generic`
* **Optional**

RPC Schema to use for the request store.

## Return Type

The request store

`createStore.ReturnType<schema>`
