---
updatedAt: 2026-09-08T10:21:01.000Z
agentTools:
  projectIndex: https://cn.developers.tron.network/llms.txt
---

# GetBlockByLatestNum

从链头往回查询最近 N 个区块——用于实时同步、监听新块场景。

## 相关资源

* [GetNowBlock](https://cn.developers.tron.network/reference/wallet-getnowblock) —— 仅取最新一个区块
* [GetBlockByLimitNext](https://cn.developers.tron.network/reference/getblockbylimitnext) —— 按高度区间批量查询
* [GetBlockByNum](https://cn.developers.tron.network/reference/wallet-getblockbynum) —— 按单个高度查询
* [区块](https://cn.developers.tron.network/docs/block) —— 区块结构与复合区块 ID

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "全节点 HTTP API",
    "version": "4.8.0"
  },
  "servers": [
    {
      "url": "https://api.shasta.trongrid.io",
      "description": "Shasta 测试网"
    },
    {
      "url": "https://nile.trongrid.io",
      "description": "Nile 测试网"
    },
    {
      "url": "https://api.trongrid.io",
      "description": "TRON 主网（真实资产）"
    }
  ],
  "components": {
    "schemas": {
      "NodeHttpBusinessError": {
        "title": "错误信息",
        "type": "object",
        "description": "请求处理发生异常时，java-tron 可能随 HTTP 200 返回此格式；具体错误信息位于 `Error` 字段。",
        "required": [
          "Error"
        ],
        "properties": {
          "Error": {
            "type": "string",
            "description": "java-tron 返回的错误信息。"
          }
        },
        "examples": [
          {
            "Error": "Invalid request parameters."
          }
        ],
        "additionalProperties": false
      },
      "StringInt64MapEntry": {
        "type": "object",
        "description": "映射条目。TRON 的 HTTP API 将 protobuf `map<string, int64>` 序列化为 `{key, value}` 对象数组（而非使用动态键的 JSON 对象）。",
        "properties": {
          "key": {
            "type": "string"
          },
          "value": {
            "type": "integer",
            "format": "int64"
          }
        }
      },
      "Transaction": {
        "type": "object",
        "description": "TRON 交易对象。完整结构参见 [wallet-gettransactionbyid](https://cn.developers.tron.network/reference/wallet-gettransactionbyid)。",
        "properties": {
          "txID": {
            "type": "string",
            "description": "交易 ID，即 raw_data protobuf 字节的 SHA-256。"
          },
          "raw_data": {
            "type": "object",
            "properties": {
              "ref_block_bytes": {
                "type": "string"
              },
              "ref_block_num": {
                "type": "integer",
                "format": "int64"
              },
              "ref_block_hash": {
                "type": "string"
              },
              "expiration": {
                "type": "integer",
                "format": "int64"
              },
              "auths": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/TransactionAuthority"
                }
              },
              "data": {
                "type": "string"
              },
              "contract": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "parameter": {
                      "type": "object",
                      "properties": {
                        "type_url": {
                          "type": "string"
                        },
                        "value": {
                          "type": "object",
                          "additionalProperties": true
                        }
                      }
                    },
                    "provider": {
                      "type": "string"
                    },
                    "ContractName": {
                      "type": "string"
                    },
                    "Permission_id": {
                      "type": "integer",
                      "format": "int32"
                    }
                  }
                }
              },
              "scripts": {
                "type": "string"
              },
              "timestamp": {
                "type": "integer",
                "format": "int64"
              },
              "fee_limit": {
                "type": "integer",
                "format": "int64"
              }
            }
          },
          "raw_data_hex": {
            "type": "string"
          },
          "signature": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "ret": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "fee": {
                  "type": "integer",
                  "format": "int64"
                },
                "ret": {
                  "type": "string",
                  "enum": [
                    "SUCESS",
                    "FAILED"
                  ]
                },
                "contractRet": {
                  "type": "string"
                },
                "assetIssueID": {
                  "type": "string"
                },
                "withdraw_amount": {
                  "type": "integer",
                  "format": "int64"
                },
                "unfreeze_amount": {
                  "type": "integer",
                  "format": "int64"
                },
                "exchange_received_amount": {
                  "type": "integer",
                  "format": "int64"
                },
                "exchange_inject_another_amount": {
                  "type": "integer",
                  "format": "int64"
                },
                "exchange_withdraw_another_amount": {
                  "type": "integer",
                  "format": "int64"
                },
                "exchange_id": {
                  "type": "integer",
                  "format": "int64"
                },
                "shielded_transaction_fee": {
                  "type": "integer",
                  "format": "int64"
                },
                "orderId": {
                  "type": "string"
                },
                "orderDetails": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/MarketOrderDetail"
                  }
                },
                "withdraw_expire_amount": {
                  "type": "integer",
                  "format": "int64"
                },
                "cancel_unfreezeV2_amount": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/StringInt64MapEntry"
                  }
                }
              }
            }
          },
          "visible": {
            "type": "boolean"
          }
        }
      },
      "TransactionAuthority": {
        "type": "object",
        "description": "交易 raw_data 中的授权账户标识。",
        "properties": {
          "account": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "address": {
                "type": "string"
              }
            }
          },
          "permission_name": {
            "type": "string"
          }
        }
      },
      "MarketOrderDetail": {
        "type": "object",
        "description": "市场订单撮合明细。",
        "properties": {
          "makerOrderId": {
            "type": "string"
          },
          "takerOrderId": {
            "type": "string"
          },
          "fillSellQuantity": {
            "type": "integer",
            "format": "int64"
          },
          "fillBuyQuantity": {
            "type": "integer",
            "format": "int64"
          }
        }
      },
      "Block": {
        "type": "object",
        "description": "TRON 区块对象。完整结构参见 [/wallet/getblock](https://cn.developers.tron.network/reference/getblock-1)。",
        "properties": {
          "blockID": {
            "type": "string"
          },
          "block_header": {
            "type": "object",
            "properties": {
              "raw_data": {
                "type": "object",
                "properties": {
                  "timestamp": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "txTrieRoot": {
                    "type": "string"
                  },
                  "parentHash": {
                    "type": "string"
                  },
                  "number": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "witness_id": {
                    "type": "integer",
                    "format": "int64"
                  },
                  "witness_address": {
                    "type": "string"
                  },
                  "version": {
                    "type": "integer",
                    "format": "int32"
                  },
                  "accountStateRoot": {
                    "type": "string"
                  }
                }
              },
              "witness_signature": {
                "type": "string"
              }
            }
          },
          "transactions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Transaction"
            }
          }
        }
      }
    }
  },
  "security": [
    {}
  ],
  "paths": {
    "/wallet/getblockbylatestnum": {
      "post": {
        "summary": "GetBlockByLatestNum",
        "description": "返回区块对象列表。",
        "operationId": "wallet-getblockbylatestnum",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "num": {
                    "type": "integer",
                    "description": "要检索的最近区块数量。示例：`5`",
                    "default": "",
                    "format": "int32"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "请求正常完成时，响应体为接口返回结果；请求处理发生异常时，HTTP 状态仍可能为 200，此时仅返回包含 `Error` 字段的错误信息。",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "title": "返回结果",
                      "not": {
                        "type": "object",
                        "required": [
                          "Error"
                        ]
                      },
                      "type": "array",
                      "description": "区块对象列表，按最新优先排列。",
                      "items": {
                        "$ref": "#/components/schemas/Block"
                      }
                    },
                    {
                      "$ref": "#/components/schemas/NodeHttpBusinessError"
                    }
                  ]
                },
                "examples": {
                  "Result": {
                    "value": "{}"
                  }
                }
              }
            }
          },
          "400": {
            "description": "400",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          }
        },
        "deprecated": false,
        "security": [],
        "x-readme": {
          "code-samples": [
            {
              "language": "javascript",
              "code": "$.post('https://api.trongrid.io/wallet/getblockbylatestnum', {\"num\":5}, function(data) {\n    console.log(data);\n});",
              "name": "JavaScript"
            }
          ],
          "samples-languages": [
            "javascript"
          ]
        }
      }
    }
  },
  "x-readme": {
    "headers": [],
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "x-readme-fauxas": true
}
```