首页/ AI 技能 / @skilllib/skill-2014279396561989634
Skill站外收录 @skilllib/skill-2014279396561989634

get-block-number

获取指定区块链的最新区块高度,通过读取环境变量中的 JSON-RPC 地址,利用 Web3.py 连接节点并实时查询链上数据,支持 Ethereum、Arbitrum、Base、Polygon 等多链环境。

0.0 (0) 257 次安装 原作者 编程导航
收录于 2026-01-22
区块链 AI 技能

Skills.MD

# Get latest block number This skill retrieves the latest block number from a blockchain using the configured JSON-RPC environment variables and Web3.py. ALWAYS USE SCRIPT. NEVER RELY ON THE HISTORICAL INFORMATION OR GUESS. ## Required inputs 1. **Chain name**: The blockchain to query (e.g., Ethereum, Arbitrum, Base, Polygon) ## Running the script Generate and run a Python script to fetch the block number. Run it Python commadn line inline, don't write a new file. ```python import os from web3 import Web3 from eth_defi.provider.multi_provider import create_multi_provider_web3 # Replace {CHAIN} with the uppercase chain name json_rpc_url = os.environ.get("JSON_RPC_{CHAIN}") if not json_rpc_url: raise ValueError("JSON_RPC_{CHAIN} environment variable not set") web3 = create_multi_provider_web3(json_rpc_url) block_number = web3.eth.block_number print(f"Latest block number: {block_number}") ``` Run the script with: ```shell source .local-test.env && poetry run python <script_path> ``` ## Display output Return the block number to the user in a clear format, e.g.: ``` Chain: Ethereum Latest block number: 19,234,567 ```

评论 0

还没有评论,来抢沙发。