First Steps On The Steemit Blockchain - Programming in Ruby - Part 1

in #programming8 years ago (edited)

A recount of my very first programmatic interaction with the blockchain to extract some useful data.

code sample 2
image source

Let's Get Started

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!

Configuration

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

Getting Followers

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" )

Let's put it together!

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


More Articles like this:
Do you want know about Google alternatives?(Read article)
Do you want to know more about free and open software? (Read article)

Thank you for visiting my blog! If you enjoy my content, you are welcome to follow me for more updates. ᕦ(ò_óˇ)ᕤ
- Nick ( @cryptonik ) -

Cryptonik-Logo
Sort:  

This was very helpful. I had always thought writing codes on the blockchain would be some herculian task. I guess I should go back and research better. I code in .NET but I was able to relate to this tutorial...thank you

Well it's actually very messy and unpolished right now. But then there are really awesome people like @inertia that write these libraries for us that make life easy :) Go for it! Maybe you can contribute some cool tool to the ecosystem.

We need more folks sharing stuff like this to get people inspired to look under the hood. I just started playing with the API myself, but I'm a JavaScript guy, so everything is node / steem-js. My challenge is the lack of documentation. The API is documented as far as what functionality is available, but it's like pulling teeth to try and find the specifications for some of the objects that the methods require as arguments. I started writing up and sharing my efforts last night, hope to post more soon.

Why thank you @sha246md5, I agree we need to get more developers in here to make steemit super awesome. Looking forward to what you can share with us.

Wow - this is exactly what I was looking for, almost exactly when I was looking for it. I've dabbled in Ruby programming, and was re-introduced to Steemit about a week ago.

I'm intrigued by the idea of the Steem blockchain, and having been mulling the idea of setting up a gigging service like "Thumbtack" or "Gigmasters", only free and in the Blockchain. Basically, it would be an Uber sort of service, but for jobs other than driving. The service would need to keep some sort of reputation/review of its participants (both the people doing the hiring, and the people getting hired).

Thanks for the inspiration and the starting point. Following @cryptonik now! :-D

Haha wow! Good timing that is then. Have a browse through the github links below and the docs you can find, there is a lot to discover. Would love to see you contribute something cool to the steem ecosystem :)

Is your stuff posted to Github? Is that where the cool kids play?

Of course that's where the cool kids are at! I will link when I make some interesting scripts! Have a look at the end of my article I placed some links to github repo's. In the /steem/ repo you will find many libraries like steem-python, steem-js, and much more. Steem source code is completely open-source by the way^^ Have fun!

upvoted my friend :)

Appreciate it :)

Wow, this is a pretty underrated post! Keep up the good work!

Cool stuff, upvoted. Keep up the good work!

Very cool, I wish I had more time for stuff like this. It is almost over my head but not quite.

There are libraries for different languages that make it easy for us like: Steem-python or Steem-js. In my case I am using Radiator which is Steem-Ruby.

Without these libraries it would be much harder, thanks to these hard-working wizards who made them!

Interesting. Thanks for breaking this stuff down for us commoners.

Coin Marketplace

STEEM 0.04
TRX 0.33
JST 0.077
BTC 62042.63
ETH 1628.63
USDT 1.00
SBD 0.41