# Receipt

The receipt of a mined transaction: whether it succeeded, the gas it used, the logs it emitted
and the contract it created.

```ts
import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";

const hash = "0xa23b52004fe574000765fbe20a311b2785a318c9dbe6b0bf6a4c1f8936f57ff3";

const outcome = Effect.gen(function* () {
  const receipt = yield* Eth.getTransactionReceipt(hash);
  if (receipt === null) return "not mined yet";
  // receipt: Receipt.Receipt
  return `${receipt.status} in block ${receipt.blockNumber}, gas ${receipt.gasUsed}`;
});
// "success in block 1, gas 21000"
```

## Schemas

| Schema | Type | Describes | Returned by |
| --- | --- | --- | --- |
| `Receipt.schema` | `Receipt.Receipt` | a receipt | [`Eth.getTransactionReceipt`](https://ethect.dev/rpc/eth/get-transaction-receipt/), [`Eth.getBlockReceipts`](https://ethect.dev/rpc/eth/get-block-receipts/), [`Eth.sendTransactionSync`](https://ethect.dev/rpc/eth/send-transaction-sync/), [`Eth.sendRawTransactionSync`](https://ethect.dev/rpc/eth/send-raw-transaction-sync/), [`Eth.subscribe.transactionReceipts`](https://ethect.dev/rpc/eth/subscribe/transaction-receipts/) |
| `Receipt.statusSchema` | `Receipt.Status` | `"success"` or `"reverted"` | `status` of a receipt |

Import a type to name it in your own signatures.

```ts
import type { Receipt } from "@ethect/core/rpc";

/** The fee paid, in wei, where the node reports the price. */
const feePaid = (receipt: Receipt.Receipt): bigint | undefined =>
  receipt.effectiveGasPrice === undefined
    ? undefined
    : receipt.gasUsed * receipt.effectiveGasPrice;
```

## Fields

| Field | Type | Notes |
| --- | --- | --- |
| `transactionHash` | `Hash` | |
| `transactionIndex` | `number` | the position of the transaction in its block |
| `blockHash` | `Hash` | |
| `blockNumber` | `bigint` | |
| `from` | `Address` | the sender |
| `to` | `Address \| null` | `null` when the transaction created a contract |
| `status` | `"success" \| "reverted"` (optional) | absent before Byzantium |
| `root` | `Hash` (optional) | the state root after the transaction, before Byzantium only |
| `type` | `Transaction.Type` or a `Hex` (optional) | the [type](https://ethect.dev/rpc/types/transaction/#types) of the transaction |
| `contractAddress` | `Address` (optional) | the contract the transaction created |
| `gasUsed` | `bigint` | the gas this transaction used |
| `cumulativeGasUsed` | `bigint` | the gas used in the block up to and including this transaction |
| `effectiveGasPrice` | `bigint` (optional) | the price paid per gas, in wei. Absent from a node that does not report it. |
| `blobGasUsed` | `bigint` (optional) | on a transaction that carries blobs |
| `blobGasPrice` | `bigint` (optional) | on a transaction that carries blobs |
| `logs` | `ReadonlyArray<`[`Log`](https://ethect.dev/rpc/types/log/)`>` | the logs the transaction emitted |
| `logsBloom` | `Hex` | |

## Behavior

- **A status is a name.** The node sends `"0x1"` or `"0x0"` and you read `"success"` or
  `"reverted"`. The code is matched by value: `"0x01"` is `"success"` too.
- **`effectiveGasPrice` can be absent.** A node that leaves it out or sends `null` gives a
  receipt without the key. anvil and current clients send it.
- **A reverted transaction has a receipt.** It was mined and paid for its gas. Only `status`
  tells it from a successful one.
- **`contractAddress` is absent, not `null`.** A node sends `null` when no contract was created,
  and the key is then left out of the object. Test it with
  `receipt.contractAddress !== undefined`.
- **`to` is `null` for a creation.** The same receipt then has a `contractAddress`.
- **No receipt while pending.** A method that looks a receipt up returns `null` until the
  transaction is mined: there is no pending form of this type.
- **Numbers.** Gas and prices are `bigint`. `transactionIndex` is a `number`. See
  [values on the wire](https://ethect.dev/rpc/guides/values/).
