get-block-number
Get the latest block number for a blockchain using Web3.py and JSON-RPC environment variables
How do I install this agent skill?
npx skills add https://github.com/tradingstrategy-ai/web3-ethereum-defi --skill get-block-numberIs this agent skill safe to install?
- Gen Agent Trust Hubwarn
This skill generates and executes Python code at runtime to interact with blockchain RPC providers. It accesses environment variables which may contain sensitive API keys and sources a local environment file (.local-test.env), which presents a risk of credential exposure or local command execution if the environment file is modified or untrusted.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
- Runlayerwarn
1/1 file flagged
What does this agent skill do?
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
- 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.
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:
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
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/tradingstrategy-ai/web3-ethereum-defi/get-block-number">View get-block-number on skillZs</a>