A recount of my very first programmatic interaction with the blockchain to extract some useful data.
I was eager to get my hands dirty and start programming on the steemit blockchain but I haven't found the time to get started so far. Until today! I ran my first script and would like to share my experiments with you.
Hopefully I can inspire someone else to get programming and developing cool things for steem too! :)
You can approach the blockchain from different angles but my weapon of choice is Ruby. Easily one favorite languages because of the awesome Rails framework. Turns out, making calls is really easy with the help of the Radiator API client provided by the generous wizard @inertia.
So let's make our first Steem-Ruby script!
I'm assuming you are on a Linux system.
You will need Ruby with minimum version 2.2 for this. You can install it from the terminal like this:
$ sudo apt-get install ruby-full git openssl libssl1.0.0 libssl-dev
$ gem install bundler
Then you can install the 'Radiator' ruby gem on your system:
$ gem install radiator
Alternatively, if you want to run it in a rails app you can include it in your gemfile.
gem 'radiator'
And running:
$ bundle install
I want to get a list and number of my followers from the steem blockchain. Looking at the API docs, there is a great example to get started:
api = Radiator::FollowApi.new
api.get_followers('inertia', 0, 'blog', 100) do |followers|
followers.map(&:follower)
end
Let's change the account_name so I can get my followers:
api.get_followers('cryptonik', 0, 'blog', 100) do |followers|
The third argument limits the amount of user's to be fetched. To get all my followers let's change it to something bigger.
api.get_followers('cryptonik', 0, 'blog', 1000) do |followers|
We want to print the full list to the terminal:
puts followers.map(&:follower)
What about the number of followers? We could loop through the list followers. However, since this is Ruby, we can just call the length method on the followers object provided by the map method. Map gives us an array that holds all users that are following our account.
$ sum=followers.length
puts("You have = #$sum followers" )
Make a file in your editor of choice and save it with the *.rb extension.
require 'radiator'
api = Radiator::FollowApi.new
api.get_followers('cryptonik', 0, 'blog', 1000) do |followers|
puts followers.map(&:follower)
$sum=followers.length
puts("You have = #$sum followers" )
end
Let's see it work:
$ ruby myfollowers.rb
Success! Damn right I have 479 followers :^D
So what can you expect from my blog, now that I have acquired these powers?
Bot-nets, loads and loads of steem bot-nets. Just kidding. Or am I?
Feel free to try this at home and if you get stuck you can always ping me.
Resources:
Radiator docs
Radiator github
Steem github