# RpcRequest.from

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

:::warning
You will likely want to use [`RpcRequest.createStore`](/api/RpcRequest/createStore) instead as it will also manage `id`s and uses this function internally.
:::

## Imports

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

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

## Examples

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

// 1. Build a request object.
const request = RpcRequest.from({
  // [!code focus]
  id: 0, // [!code focus]
  method: 'eth_estimateGas', // [!code focus]
  params: [
    // [!code focus]
    {
      // [!code focus]
      from: '0xd2135CfB216b74109775236E36d4b433F1DF507B', // [!code focus]
      to: '0x0D44f617435088c947F00B31160f64b074e412B4', // [!code focus]
      value: '0x69420' // [!code focus]
    } // [!code focus]
  ] // [!code focus]
}) // [!code focus]

// 2. Send the JSON-RPC request via HTTP.
const gas = await fetch('https://1.rpc.thirdweb.com', {
  body: JSON.stringify(request),
  headers: {
    'Content-Type': 'application/json'
  },
  method: 'POST'
})
  .then((response) => response.json())
  // 3. Parse the JSON-RPC response into a type-safe result.
  .then((response) =>
    RpcResponse.parse(response, { request })
  )
```

## Definition

```ts
function from<methodName>(
  options: from.Options<methodName>,
): from.ReturnType<methodName>
```

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

## Parameters

### options

* **Type:** `from.Options<methodName>`

JSON-RPC request options.

#### options.Request

* **Type:** `{ method: methodName; }`

#### options.id

* **Type:** `number`

#### options.method

* **Type:** `methodName`

#### options.params

* **Type:** `unknown`
* **Optional**

## Return Type

The fully-formed JSON-RPC request object.

`from.ReturnType<methodName>`
