wallet/getblockbylatestnum
Get a range of recent blocks counting backwards from the latest block.
Endpoint
POST /wallet/getblockbylatestnum
Parameters
Required Parameters
Parameter | Type | Description |
---|---|---|
num | number | Number of recent blocks to retrieve (max: 99) |
Response
Returns an array of block objects, each containing:
blockID
- Block hash identifierblock_header
- Block header informationraw_data
- Raw block datanumber
- Block heighttxTrieRoot
- Transaction trie rootwitness_address
- Block producer addressparentHash
- Parent block hashtimestamp
- Block timestamp (milliseconds)version
- Block version
witness_signature
- Witness signature
transactions
- Array of transactions in each block
Implementation Examples
- JavaScript
- Python
- cURL
// 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`);
import requests
from datetime import datetime
url = "https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/getblockbylatestnum"
# Get last 10 blocks
payload = {
"num": 10
}
response = requests.post(url, json=payload)
blocks = response.json()
print(f"Retrieved {len(blocks)} recent blocks")
# Analyze blocks
for block in blocks:
block_num = block['block_header']['raw_data']['number']
tx_count = len(block.get('transactions', []))
timestamp = datetime.fromtimestamp(
block['block_header']['raw_data']['timestamp'] / 1000
)
print(f"Block {block_num}: {tx_count} txs at {timestamp}")
# Get more blocks for statistics
stats_payload = {
"num": 30
}
stats_response = requests.post(url, json=stats_payload)
stats_blocks = stats_response.json()
# Calculate statistics
total_txs = sum(len(b.get('transactions', [])) for b in stats_blocks)
avg_txs_per_block = total_txs / len(stats_blocks)
print(f"\nAverage transactions per block: {avg_txs_per_block:.2f}")
# Get last 5 blocks
curl -X POST https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/getblockbylatestnum \
-H "Content-Type: application/json" \
-d '{
"num": 5
}'
# Get last 20 blocks
curl -X POST https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/getblockbylatestnum \
-H "Content-Type: application/json" \
-d '{
"num": 20
}'
# Get maximum allowed (99 blocks)
curl -X POST https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/getblockbylatestnum \
-H "Content-Type: application/json" \
-d '{
"num": 99
}'
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
Related Methods
- wallet/getnowblock - Get single latest block
- wallet/getblockbynum - Get specific block by height
- wallet/getblockbyid - Get block by hash ID
- wallet/gettransactionbyid - Get transaction details