From 5f2d156a083dc3606d4787a7a72d24c08d3d1cb1 Mon Sep 17 00:00:00 2001 From: LumenSolutions Date: Mon, 15 Dec 2025 18:36:14 +0100 Subject: [PATCH] feat: add geth network info helper Added the geth-net-info.sh script, which displays the chainId and last block number for a running geth via RPC. --- scripts/geth-net-info.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 scripts/geth-net-info.sh diff --git a/scripts/geth-net-info.sh b/scripts/geth-net-info.sh new file mode 100644 index 0000000000..515e3341d3 --- /dev/null +++ b/scripts/geth-net-info.sh @@ -0,0 +1,31 @@ +```bash +#!/usr/bin/env bash +set -euo pipefail +``` + +# Prints basic network information by attaching to a running geth instance. +# +# Usage: +# ./scripts/geth-net-info.sh +# +# By default it attaches to http://127.0.0.1:8545. Override via: +# RPC_URL=http://host:port ./scripts/geth-net-info.sh + +RPC_URL="${RPC_URL:-http://127.0.0.1:8545}" + +echo "Using RPC URL: ${RPC_URL}" +echo + +payload='{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' +chain_id=$(curl -s -X POST "${RPC_URL}" -H "Content-Type: application/json" -d "${payload}" | jq -r '.result // empty') + +if [ -z "${chain_id}" ]; then + echo "Failed to fetch chainId. Is geth running and RPC enabled?" + exit 1 +fi + +payload_block='{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' +block_number=$(curl -s -X POST "${RPC_URL}" -H "Content-Type: application/json" -d "${payload_block}" | jq -r '.result // empty') + +echo "chainId: ${chain_id}" +echo "latest block: ${block_number}"