Repositories
SteemRubyTutorial
All examples from this tutorial can be found as fully functional scripts on GitHub:
- SteemRubyTutorial
- radiator sample code: Steem-Print-SSC-Table-First.rb.
radiator
- Project Name: Radiator
- Repository: https://github.com/inertia186/radiator
- Official Documentation: https://www.rubydoc.info/gems/radiator
- Official Tutorial: https://developers.steem.io/tutorials-ruby/getting_started
Steem Engine
- Project Name: Steem Engine
- Home Page: https://steem-engine.com
- Repository: https://github.com/harpagon210/steem-engine
- Official Documentation: https://github.com/harpagon210/sscjs (JavaScript only)
- Official Tutorial: N/A
What Will I Learn?
This tutorial shows how to interact with the Steem blockchain, Steem database and Steem Engine using Ruby. When accessing Steem Engine using Ruby their only one APIs available to chose: radiator.
In this particular chapter you learn how to read a single row from the Steem Engine database tables.
Requirements
Basic knowledge of Ruby programming is needed. It is necessary to install at least Ruby 2.5 as well as the following ruby gems:
gem install bundler
gem install colorize
gem install contracts
gem install radiator
Difficulty
For reader with programming experience this tutorial is basic level.
Tutorial Contents
Steem Engine allows users to add token and contacts to the steem block chain. Currently only three predefined contracts are know: "tokens", "market", and "steempegged". Each contract has one or more database table to store their data.
In order to read the content of a table it is necessary to know the name of database tables to query. The Steem-Print-Print-SSC-Contract.rb from the previous part of the tutorial prints all data of a Steem Engine contract — including the database tables used by the contract.
The table names are found in the aptly named attribute “tables”. Each table name is prefixed with their contract name. Presumably to make them unique throughout the system. Here a list of the currently known tables names:
Unique name | Contact | Table |
---|---|---|
market_buyBook | market | buyBook |
market_metrics | market | metrics |
market_sellBook | market | sellBook |
market_tradesHistory | market | tradesHistory |
steempegged_withdrawals | steempegged | withdrawals |
tokens_balances | tokens | balances |
tokens_contractsBalances | tokens | contractsBalances |
tokens_params | tokens | params |
tokens_pendingUnstakes | tokens | pendingUnstakes |
tokens_tokens | tokens | tokens |
Implementation using radiator
As mentioned only radiator offers an API to access Steem Engine. For this radiator offerers a name space called Radiator::SSC
. To access the database tables their are two methods: Contracts.find_one
and Contracts.find
. The latter will be described in the next part of the tutorial.
Im this part of the tutorialContracts.find_one
is used to access the row of any table. The method has three mandatory parameters: contract
, table
and query
:
contract: The name of the contract. As mentione there are currently three known contracts: "tokens", "market", and "steempegged".
table: The name of the tables to query. See below.
query: A list of column names and values.
In order to just access the first row the query attribute is left empty and the result is just printed. There is no explicit error message, if the query fails no data is returned.
if ARGV.length == 0 then
puts "
Steem-Print-SSC-Table-Sample — Print first row of a steem engine table.
Usage:
Steem-Print-SSC-Table-Sample contract_name table_name
"
else
# read arguments from command line
_contract = ARGV[0]
_table = ARGV[1]
# the query attribute is mandantory, supply an empty query
# to receive the first row.
_row = Contracts.find_one(
contract: _contract,
table: _table,
query: {
}
)
if _row == nil then
puts "No data found, possible reasons:
⑴ The contract does not exist
⑵ The table does not exist
⑶ The table is empty
"
else
pp _row
end
end
Hint: Follow this link to Github for the complete script with comments and syntax highlighting : Steem-Print-SSC-Table-First.rb.
The output of the command for the table “tokens” of the contract “tokens” is:
The output of the command for the table “balances” of the contract “tokens” is:
From those output you can learn the names of the columns of the database and both tables will be used to update the Steem-Print-Balances.rb on GitHub script to print the Steem Engine Token in addition to Steem, Steem Dollar and VESTS.
Curriculum
First tutorial
Previous tutorial
Next tutorial
Proof of Work
- GitHub: SteemRubyTutorial Issue #14
Image Source
- Ruby symbol: Wikimedia, CC BY-SA 2.5.
- Steemit logo Wikimedia, CC BY-SA 4.0.
- Steem Engine logo Steem Engine
- Screenshots: @krischik, CC BY-NC-SA 4.0
Thank you for your contribution @krischik.
After analyzing your tutorial we suggest the following points below:
Your tutorial is quite short for a good tutorial. We recommend you aim for capturing at least 2-3 concepts.
Your tutorial is very well structured and explained. Good job!
Thank you for following our suggestions in your previous tutorial.
Looking forward to your upcoming tutorials.
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Chat with us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I agree it's short but I disagree on capturing multiple concepts. I prefer one method / concept at a time.
If you are worried about me spoiling for upvotes then please make the upvote smaller in accordance to the size of the particular chapter.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for your review, @portugalcoin! Keep up the good work!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi @krischik!
Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @krischik! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi, @krischik!
You just got a 4.79% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey, @krischik!
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit