Skip to content

Eth.syncing

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

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. The examples below leave the transport out.

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

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}`,
),
);

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

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");
});

Effect<SyncStatus.SyncStatus, Method.Error, Transport>

false, or a SyncStatus.Progress with currentBlock, highestBlock and, where the client reports it, startingBlock.

None.

  • 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 instead of asking again.

eth_syncing