6

What's the fastest way to display the current Monero block height with a shell script? Doesn't matter which scripting language. The idea is to call this script or block from other scripts, so it should just return the value.

seek adventure
  • 2,239
  • 14
  • 52
dpzz
  • 4,539
  • 4
  • 22
  • 46

3 Answers3

6

I propose the following with simple bash scripting using curl and jq.


First, install jq (to parse json)


Then, write a simple bash script

Using the moneroclub public node:

#!/bin/bash

INFO=($(curl -sS -X POST http://node.moneroclub.com:8880/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"\
get_info"}' -H 'Content-Type: application/json' | jq '.result.height'))

echo $INFO

Alternatively, using moneroblocks.info:

#!/bin/bash

INFO=($(curl -sS -X GET http://moneroblocks.info/api/get_stats/ | jq '.height|tonumber'))

echo $INFO
bigreddmachine
  • 3,747
  • 1
  • 11
  • 30
5

Currently, I am using ruby to parse the JSON returned from moneroblocks.info:

ruby << END_OF_RUBY
require 'open-uri'
require 'json'
open ("http://moneroblocks.info/api/get_stats/") { |src|
      puts JSON.parse(src.read)["height"]
}
END_OF_RUBY

Which right nows returns: 1140328

dpzz
  • 4,539
  • 4
  • 22
  • 46
4

If you have a daemon running on your own machine, use:

height=$(monerod print_height)

This will save the height as the shell variable $height.

I see now that the question was for using a block explorer. Oh well.

Ginger Ale
  • 5,694
  • 2
  • 19
  • 46