Block Hash

This Bash script is designed to compare the hash of a specific block from the Heimdall blockchain on your local instance with the hash of the same block obtained from an external API.

#!/bin/bash


latest_block_height=$(curl -s localhost:26657/status | jq -r '.result.sync_info.latest_block_height')


hash_value_local=$(curl -s "localhost:26657/block?height=$latest_block_height" | jq -r '.result.block_meta.block_id.hash')


hash_value_api=$(curl -s "https://heimdall-api.polygon.technology/blocks/$latest_block_height" | jq -r '.block_meta.block_id.hash')


echo "Hash of the block (Local): $hash_value_local"
echo "Hash of the block (API): $hash_value_api"

# Comparing the hash values
if [ "$hash_value_local" = "$hash_value_api" ]; then
    echo "The hashes are equal."
else
    echo "The hashes are different."
fi

Requests Installation:

Run the script in an environment with curl and jq installed.

sudo apt-get install jq 

Script Execution:

Make the script executable using chmod +x script.sh

Run the Script:

In the terminal or command prompt, navigate to the directory where the script is located. Execute the script using the following command:

./script.sh

Last updated