SOCI4L

Walking the blocks

Step 1 of 2
0 of 2 goals

Fetch a block

getBlock takes a number or a tag:

const latest = await client.getBlock()
console.log(latest.number, latest.transactions.length)

By default you get transaction hashes only. Pass includeTransactions: true and you get the full objects instead — more data over the wire, so ask for it only when you need it.

const full = await client.getBlock({
  blockNumber: latest.number - 4n,
  includeTransactions: true,
})

Remember 4n: latest.number is a bigint and mixing it with a plain number throws.

// This chain is short enough to walk end to end.

Press Run, or hit the button above. Output lands here.

Goals

The code runs without throwing
run the code to check this
Fetch a block and print something from it
run the code to check this
Run the code to load this lesson’s chain.