# Eth.syncing

Returns `false` when the node is in sync, or how far it has come while it is still syncing.

## Usage

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

const status = await Eth.syncing().pipe(
  Effect.provide(Transport.http("http://127.0.0.1:8545")),
  Effect.provide(FetchHttpClient.layer),
  Effect.runPromise,
);
// false
```

The call works over every [transport](https://ethect.dev/guides/transports/). The examples below leave the
transport out.

### Read the progress

Compare the result with `false` first. What is left is the progress, with three block
numbers.

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

const progress = Eth.syncing().pipe(
  Effect.map((status) =>
    status === false
      ? "in sync"
      : `at block ${status.currentBlock} of ${status.highestBlock}`,
  ),
);
```

### Refuse to read from a node that is behind

A node that is syncing answers from old state. Fail before reading from it.

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

const ADDRESS = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");

const balance = Effect.gen(function* () {
  const status = yield* Eth.syncing();
  if (status !== false) return yield* Effect.fail("the node is still syncing");
  return yield* Eth.getBalance(ADDRESS, "latest");
});
```

## Returns

[`Effect<SyncStatus.SyncStatus, Method.Error, Transport>`](https://ethect.dev/rpc/method/#calling-a-method)

`false`, or a [`SyncStatus.Progress`](https://ethect.dev/rpc/types/sync-status/) with `currentBlock`,
`highestBlock` and, where the client reports it, `startingBlock`.

## Parameters

None.

## Behavior

- **`false` on a development node.** anvil has nothing to sync and answers `false`.
- **Three fields are kept.** A node that reports more than the three block numbers still
  decodes. The extra fields are not in the result.
- **To be told when it changes**, use
  [`Eth.subscribe.syncing`](https://ethect.dev/rpc/eth/subscribe/syncing/) instead of asking again.

## JSON-RPC method

`eth_syncing`
