# Blobs

The two methods that return the blobs of EIP-4844 transactions a test node has seen: one blob
by its versioned hash, or every blob of a transaction.

| Method | JSON-RPC | Returns | Description |
| --- | --- | --- | --- |
| [`getBlobByHash`](#getblobbyhash) | `anvil_getBlobByHash` | `Hex \| null` | A blob the node has seen, by its versioned hash. |
| [`getBlobsByTransactionHash`](#getblobsbytransactionhash) | `anvil_getBlobsByTransactionHash` | `Hex[] \| null` | The blobs a transaction carried. |

Each takes one [`Hash`](https://ethect.dev/reference/primitives/hash/) and returns an
[`Effect<…, Method.Error, Transport>`](https://ethect.dev/rpc/method/#calling-a-method). A blob is not part
of a block: a transaction only carries the versioned hashes of its blobs, and these methods
give the data back.

## getBlobByHash

Returns a blob by its versioned hash, as listed in the `blobVersionedHashes` of an EIP-4844
transaction.

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

const firstBlob = (hash: `0x${string}`) =>
  Effect.gen(function* () {
    const transaction = yield* Eth.getTransactionByHash(hash);
    if (transaction?.type !== "eip4844") return null;
    const [versionedHash] = transaction.blobVersionedHashes;
    if (versionedHash === undefined) return null;
    return yield* Anvil.getBlobByHash(versionedHash);
  });
```

- **JSON-RPC:** `anvil_getBlobByHash`
- **Parameters:** `versionedHash` ([`Hash`](https://ethect.dev/reference/primitives/hash/)).
- **Returns:** `Hex | null`. The blob as hex, or `null` when the node has seen no blob with
  that hash.

## getBlobsByTransactionHash

Returns the blobs a transaction carried.

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

const blobSizes = (hash: `0x${string}`) =>
  Anvil.getBlobsByTransactionHash(hash).pipe(
    Effect.map((blobs) => (blobs === null ? [] : blobs.map(Hex.size))),
  );
```

- **JSON-RPC:** `anvil_getBlobsByTransactionHash`
- **Parameters:** `hash` ([`Hash`](https://ethect.dev/reference/primitives/hash/)), the hash of the transaction.
- **Returns:** `ReadonlyArray<Hex> | null`. `null` when the node knows no blob transaction with
  that hash, which is also the answer for a transaction that carried no blob.

## Behavior

- **The two hashes are not interchangeable.** `getBlobByHash` given a transaction hash and
  `getBlobsByTransactionHash` given a versioned hash both return `null`.
- **Sending a blob transaction.** [`Eth.sendTransaction`](https://ethect.dev/rpc/eth/send-transaction/)
  takes the blobs with their commitments and proofs in the `blobs`, `commitments` and `proofs`
  fields of the [request](https://ethect.dev/rpc/types/transaction-request/). ethect computes none of the
  three: they come from a KZG library.
