Skip to main content

NEAR Data Examples

Worked investigation

Catch a new block early, then confirm it after finality

Use this investigation when you want to notice a new block as early as possible, but the final answer still needs a finalized block and sometimes an exact RPC read.

Strategy

Let NEAR Data tell you something changed, then reuse the same block family for the stable confirmation.

01block-optimistic or last-block-optimistic gives the earliest useful signal.

02block or last-block-final confirms whether the same observation survived into finalized history.

03RPC block is only the last step, once you know the exact height or hash that matters.

Goal

  • Notice a recent block quickly, then check the same thing again once finality catches up.
SurfaceEndpointHow we use itWhy we use it
Fastest detectionNEAR Data block-optimisticPoll optimistic block reads to notice a new block-family change as early as possibleGives the earliest useful signal before finalized confirmation exists
Latest optimistic helperNEAR Data last-block-optimisticUse the redirect helper when the client should always follow the newest optimistic targetKeeps the polling client simple when “latest” matters more than explicit heights
Stable confirmationNEAR Data block or last-block-finalRe-check the same block family once finality catches upConfirms that the observed optimistic change survived into finalized history
Light block summaryNEAR Data block-headersRead header-level data if only timing or progression is neededAvoids wider block payloads when header-level confirmation is enough
Exact RPC follow-upRPC Block by ID or Block by HeightFetch the exact block once you know which one mattersThis is the point where RPC becomes useful if you need the protocol's own block object

What a useful answer should include

  • which optimistic observation first triggered the investigation
  • when the same observation became finalized
  • whether the exact RPC block changed the interpretation

Finalized block follow-up shell walkthrough

Use this when you want the helper route to pick the latest finalized block for you, but you still want to confirm the exact block in RPC.

What you're doing

  • Inspect the redirect returned by GET /v0/last_block/final.
  • Fetch the resolved block document.
  • Extract block.header.height with jq.
  • Reuse that height in RPC block by height.
NEARDATA_BASE_URL=https://mainnet.neardata.xyz
RPC_URL=https://rpc.mainnet.fastnear.com

FINAL_LOCATION="$(
  curl -s -D - -o /dev/null "$NEARDATA_BASE_URL/v0/last_block/final" \
    | awk 'tolower($1) == "location:" {print $2}' \
    | tr -d '\r'
)"

printf 'Redirect target: %s\n' "$FINAL_LOCATION"

curl -s "$NEARDATA_BASE_URL$FINAL_LOCATION" \
  | tee /tmp/neardata-final-block.json \
  | jq '{height: .block.header.height, hash: .block.header.hash}'

BLOCK_HEIGHT="$(jq -r '.block.header.height' /tmp/neardata-final-block.json)"

curl -s "$RPC_URL" \
  -H 'content-type: application/json' \
  --data "$(jq -nc --arg block_height "$BLOCK_HEIGHT" '{
    jsonrpc: "2.0",
    id: "fastnear",
    method: "block",
    params: {
      block_id: ($block_height | tonumber)
    }
  }')" \
  | jq '{height: .result.header.height, hash: .result.header.hash, chunks: (.result.chunks | length)}'

Why this next step?

The redirect helper is the easiest way to poll for “latest finalized.” Once it gives you a concrete block height, RPC is the natural next read if you want the exact block object the protocol would return.

Common jobs

Monitor the optimistic head

Start here

Next page if needed

Stop when

  • You can report the latest optimistic head or detect freshness drift.

Switch when

Track finalized block progress safely

Start here

Next page if needed

Stop when

  • You can show finalized progress without pulling in deeper protocol detail.

Switch when

  • The user needs exact block fields or transaction semantics. Move to RPC Reference.

Use redirect helpers in a polling client

Start here

Next page if needed

  • Follow the block URL returned by the helper and keep reading from there.

Stop when

  • The client can reliably follow the helper route and consume the final block resource.

Switch when

  • Redirect behavior itself becomes a problem for the client. Move to the direct block routes instead.

Move from recent block polling to exact RPC inspection

Start here

  • Use the relevant NEAR Data block route to find the recent block or block-family event of interest.

Next page if needed

Stop when

  • You can clearly name the recent block that deserves RPC follow-up.

Switch when

  • The user asks for the exact protocol structure, not just recent block polling.

Common mistakes

  • Treating NEAR Data like a push stream instead of a polling API.
  • Starting with RPC when the real need is a recent block monitor.
  • Forgetting that redirect helpers may return 401 before redirecting if the key is invalid, or may be awkward for some HTTP clients.
  • Staying on NEAR Data when the user has already asked for exact protocol-native block details.