Module
Blocks — 1 credit
Query blockchain block information — the latest block or a specific block by number. Both methods cost 1 credit.
API Key or JWT
latest()
GET
1 credit
Get the most recently confirmed block on the network, including block number, hash, timestamp, and transaction count.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
$network | ?string | No | Network name. Defaults to WEB3_DEFAULT_NETWORK |
Example
$block = Web3Api::blocks()->latest(network: 'polygon');
echo $block['number']; // 12345678
echo $block['hash']; // "0xabc..."
echo $block['timestamp']; // 1700000000 — Unix timestamp
echo $block['transaction_count']; // 120
echo $block['network']; // "polygon"
Response
[
'number' => 12345678,
'hash' => '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
'timestamp' => 1700000000, // Unix epoch
'transaction_count' => 120,
'network' => 'polygon',
]
get()
GET
1 credit
Get a specific block by its number. Returns the same shape as latest().
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
$blockNumber | int | Yes | Block number to retrieve |
$network | ?string | No | Network name. Defaults to WEB3_DEFAULT_NETWORK |
Example
$block = Web3Api::blocks()->get(
blockNumber: 12345678,
network: 'polygon',
);
Example — check if transaction is confirmed
// Get latest block number to calculate confirmations
$latest = Web3Api::blocks()->latest(network: 'polygon');
$tx = Web3Api::transactions()->status(txHash: '0x...', network: 'polygon');
if ($tx['block_number'] !== null) {
$confirmations = $latest['number'] - $tx['block_number'];
echo "Confirmed {$confirmations} blocks ago";
}