⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

wallet/getblockbylatestnum

Get a range of recent blocks counting backwards from the latest block.

Endpoint

POST /wallet/getblockbylatestnum

Parameters

Required Parameters

ParameterTypeDescription
numnumberNumber of recent blocks to retrieve (max: 99)

Response

Returns an array of block objects, each containing:

  • blockID - Block hash identifier
  • block_header - Block header information
    • raw_data - Raw block data
      • number - Block height
      • txTrieRoot - Transaction trie root
      • witness_address - Block producer address
      • parentHash - Parent block hash
      • timestamp - Block timestamp (milliseconds)
      • version - Block version
    • witness_signature - Witness signature
  • transactions - Array of transactions in each block

Implementation Examples

// Get last 5 blocks
const response = await fetch('https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/getblockbylatestnum', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
num: 5
}),
});

const blocks = await response.json();
console.log(`Retrieved ${blocks.length} recent blocks`);

// Process recent blocks
blocks.forEach(block => {
console.log(`Block ${block.block_header.raw_data.number}: ${block.transactions.length} transactions`);
});

// Get larger range for analysis
const analysisResponse = await fetch('https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/getblockbylatestnum', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
num: 50 // Get last 50 blocks
}),
});

const analysisBlocks = await analysisResponse.json();

// Analyze block production
const blockTimes = analysisBlocks.map(block => block.block_header.raw_data.timestamp);
const avgBlockTime = (blockTimes[0] - blockTimes[blockTimes.length - 1]) / (blockTimes.length - 1);
console.log(`Average block time: ${avgBlockTime}ms`);

Example Response

[
{
"blockID": "0000000003787ac94d9bb8f8c9c59ac3f3e3b9b8c9e3e8f9c8d7e8f9c8d7e8fa",
"block_header": {
"raw_data": {
"number": 58234569,
"txTrieRoot": "8e9bb8f8c9c59ac3f3e3b9b8c9e3e8f9c8d7e8f9c8d7e8f9c8d7e8f9c8d7e8fa",
"witness_address": "41a614f803b6fd780986a42c78ec9c7f77e6ded13c",
"parentHash": "0000000003787ac84d9bb8f8c9c59ac3f3e3b9b8c9e3e8f9c8d7e8f9c8d7e8f9",
"version": 27,
"timestamp": 1702456795000
},
"witness_signature": "b4e6b8c9d7f8e9c8d7e8f9c8d7e8f9..."
},
"transactions": []
},
{
"blockID": "0000000003787ac84d9bb8f8c9c59ac3f3e3b9b8c9e3e8f9c8d7e8f9c8d7e8f9",
"block_header": {
"raw_data": {
"number": 58234568,
"txTrieRoot": "7e9bb8f8c9c59ac3f3e3b9b8c9e3e8f9c8d7e8f9c8d7e8f9c8d7e8f9c8d7e8f9",
"witness_address": "41928c9af0651632157ef27a2cf17ca72c575a4d21",
"parentHash": "0000000003787ac74d9bb8f8c9c59ac3f3e3b9b8c9e3e8f9c8d7e8f9c8d7e8f8",
"version": 27,
"timestamp": 1702456792000
},
"witness_signature": "a4e5b8c9d7f8e9c8d7e8f9c8d7e8f9..."
},
"transactions": [
{
"txID": "8d3e5f9a7b6c4d2e1f0a9b8c7d6e5f4a3b2c1d0e9f8a7b6c5d4e3f2a1b0c9d8e",
"raw_data": {
"contract": [
{
"parameter": {
"value": {
"amount": 2000000,
"owner_address": "41d1e7a6bc354106cb410e65ff8b181c600ff14292",
"to_address": "41e552726909b5c951a9e0d365674e5a48b46f79d3"
},
"type_url": "type.googleapis.com/protocol.TransferContract"
},
"type": "TransferContract"
}
],
"ref_block_bytes": "7ac7",
"ref_block_hash": "5d9bb8f8c9c59ac4",
"expiration": 1702456852000,
"timestamp": 1702456792000
},
"signature": ["c8c9d7e8f9c8d7e8f9c8d7e8f9..."]
}
]
}
]

Use Cases

  • Real-time Monitoring: Track latest blockchain activity
  • Transaction Confirmation: Check recent blocks for transaction inclusion
  • Network Health: Monitor block production rate and consistency
  • Statistical Analysis: Analyze recent blockchain metrics
  • Block Explorer: Display recent blocks on explorer homepage