You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Cosmpy模块无法通过区块高度获取区块,求正确调用方法

解决Cosmpy中GetBlockByHeight()的调用问题

GetBlockByHeight()是CosmosBaseTendermint类的实例方法,不能直接通过类名调用(直接调用会要求传入self参数,这是实例方法的特性),正确的做法是先创建类的实例,再通过实例调用该方法。

正确调用代码示例

from cosmpy.tendermint.interface import CosmosBaseTendermint

# 创建CosmosBaseTendermint实例,传入你的Tendermint节点RPC地址
tendermint_client = CosmosBaseTendermint("http://localhost:26657")

# 替换为你要查询的区块高度
target_height = 12345

# 通过实例调用方法获取区块详情
block_info = tendermint_client.GetBlockByHeight(target_height)

print(block_info)

注意事项

  • 请将代码中的RPC地址替换为你实际使用的Tendermint节点地址,本地节点通常默认是http://localhost:26657
  • 确保你的节点处于运行状态,且能正常访问RPC接口

内容的提问来源于stack exchange,提问作者giacomomaraglino

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 15:34:55