Files
ethereum-rpc-docker/get-block.sh
squidbear 8954702640 fix
2025-03-24 05:10:04 +01:00

19 lines
546 B
Bash
Executable File

#!/bin/bash
is_decimal() {
[[ $1 =~ ^[0-9]+$ ]]
}
block_input=${2:-latest}
if is_decimal "$block_input"; then
# Convert decimal to hexadecimal
block_input="0x$(printf "%x" "$block_input")"
fi
request="{\"jsonrpc\":\"2.0\",\"method\":\"eth_getBlockByNumber\",\"params\":[\"${block_input}\",false],\"id\":1}"
echo "${request}"
curl -s -X POST "${1}" -H "Content-Type: application/json" --data "'${request}'" | jq -r '.result.number, .result.hash' | gawk '{if (NR==1) print "Block Number:", strtonum($0); else print "Block Hash:", $0}'