# TransactionReceipt.fromRpc

Converts a [`TransactionReceipt.Rpc`](/api/TransactionReceipt/types#rpc) to an [`TransactionReceipt.TransactionReceipt`](/api/TransactionReceipt/types#transactionreceipt).

## Imports

:::code-group

```ts [Named]
import { TransactionReceipt } from 'ox'
```

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

:::

## Examples

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

const receipt = TransactionReceipt.fromRpc({
  blobGasPrice: '0x42069',
  blobGasUsed: '0x1337',
  blockHash:
    '0xc350d807505fb835650f0013632c5515592987ba169bbc6626d9fc54d91f0f0b',
  blockNumber: '0x12f296f',
  contractAddress: null,
  cumulativeGasUsed: '0x82515',
  effectiveGasPrice: '0x21c2f6c09',
  from: '0x814e5e0e31016b9a7f138c76b7e7b2bb5c1ab6a6',
  gasUsed: '0x2abba',
  logs: [],
  logsBloom:
    '0x00200000000000000000008080000000000000000040000000000000000000000000000000000000000000000000000022000000080000000000000000000000000000080000000000000008000000200000000000000000000200008020400000000000000000280000000000100000000000000000000000000010000000000000000000020000000000000020000000000001000000080000004000000000000000000000000000000000000000000000400000000000001000000000000000000002000000000000000020000000000000000000001000000000000000000000200000000000000000000000000000001000000000c00000000000000000',
  status: '0x1',
  to: '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad',
  transactionHash:
    '0x353fdfc38a2f26115daadee9f5b8392ce62b84f410957967e2ed56b35338cdd0',
  transactionIndex: '0x2',
  type: '0x2'
})
// @log: {
// @log:   blobGasPrice: 270441n,
// @log:   blobGasUsed: 4919n,
// @log:   blockHash: "0xc350d807505fb835650f0013632c5515592987ba169bbc6626d9fc54d91f0f0b",
// @log:   blockNumber: 19868015n,
// @log:   contractAddress: null,
// @log:   cumulativeGasUsed: 533781n,
// @log:   effectiveGasPrice: 9062804489n,
// @log:   from: "0x814e5e0e31016b9a7f138c76b7e7b2bb5c1ab6a6",
// @log:   gasUsed: 175034n,
// @log:   logs: [],
// @log:   logsBloom: "0x00200000000000000000008080000000000000000040000000000000000000000000000000000000000000000000000022000000080000000000000000000000000000080000000000000008000000200000000000000000000200008020400000000000000000280000000000100000000000000000000000000010000000000000000000020000000000000020000000000001000000080000004000000000000000000000000000000000000000000000400000000000001000000000000000000002000000000000000020000000000000000000001000000000000000000000200000000000000000000000000000001000000000c00000000000000000",
// @log:   root: undefined,
// @log:   status: "success",
// @log:   to: "0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad",
// @log:   transactionHash: "0x353fdfc38a2f26115daadee9f5b8392ce62b84f410957967e2ed56b35338cdd0",
// @log:   transactionIndex: 2,
// @log:   type: "eip1559",
// @log: }
```

### End-to-end

Below is an example of how to use the `TransactionReceipt.fromRpc` method to convert an RPC transaction receipt to a [`TransactionReceipt.TransactionReceipt`](/api/TransactionReceipt/types#transactionreceipt) object.

```ts twoslash
import 'ox/window'
import { TransactionReceipt } from 'ox'

const receipt = await window
  .ethereum!.request({
    method: 'eth_getTransactionReceipt',
    params: [
      '0x353fdfc38a2f26115daadee9f5b8392ce62b84f410957967e2ed56b35338cdd0'
    ]
  })
  .then(TransactionReceipt.fromRpc) // [!code hl]
// @log: {
// @log:   blobGasPrice: 270441n,
// @log:   blobGasUsed: 4919n,
// @log:   blockHash: "0xc350d807505fb835650f0013632c5515592987ba169bbc6626d9fc54d91f0f0b",
// @log:   blockNumber: 19868015n,
// @log:   contractAddress: null,
// @log:   cumulativeGasUsed: 533781n,
// @log:   effectiveGasPrice: 9062804489n,
// @log:   from: "0x814e5e0e31016b9a7f138c76b7e7b2bb5c1ab6a6",
// @log:   gasUsed: 175034n,
// @log:   logs: [],
// @log:   logsBloom: "0x00200000000000000000008080000000000000000040000000000000000000000000000000000000000000000000000022000000080000000000000000000000000000080000000000000008000000200000000000000000000200008020400000000000000000280000000000100000000000000000000000000010000000000000000000020000000000000020000000000001000000080000004000000000000000000000000000000000000000000000400000000000001000000000000000000002000000000000000020000000000000000000001000000000000000000000200000000000000000000000000000001000000000c00000000000000000",
// @log:   root: undefined,
// @log:   status: "success",
// @log:   to: "0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad",
// @log:   transactionHash: "0x353fdfc38a2f26115daadee9f5b8392ce62b84f410957967e2ed56b35338cdd0",
// @log:   transactionIndex: 2,
// @log:   type: "eip1559",
// @log: }
```

:::note

For simplicity, the above example uses `window.ethereum.request`, but you can use any type of JSON-RPC interface.

:::

## Definition

```ts
function fromRpc<receipt>(
  receipt: receipt | Rpc | null,
): receipt extends Rpc ? TransactionReceipt : null
```

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

## Parameters

### receipt

* **Type:** `receipt | Rpc | null`

The RPC receipt to convert.

## Return Type

An instantiated [`TransactionReceipt.TransactionReceipt`](/api/TransactionReceipt/types#transactionreceipt).

`receipt extends Rpc ? TransactionReceipt : null`
