Using Steem-API with Ruby Part 12 — Print Steem Engine ContractssteemCreated with Sketch.

in #utopian-io5 years ago (edited)

Steemit_Ruby_Engine.png

Repositories

SteemRubyTutorial

All examples from this tutorial can be found as fully functional scripts on GitHub:

radiator

Steem Engine

steem-engine_logo-horizontal-dark.png

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 smart contracts from the Steem Engine side chain.

img_train.png

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". Additional contracts can be added but you have to get into contact with the Steem Engine team.

img_steem-engine_overview.png

There are two main components to each contract:

  • The contract source code written in Java Script.
  • A collection of database tables where the contract can store its data.

In addition to those there is a small set of meta data like the owner and hash code of the contract.

Implementation using radiator

As mentioned only radiator offers an API to access Steem Engine. For this radiator offerers a name space called Radiator::SSC


Reading the contract information is fairly simple. First an instance Radiator::SSC::Contracts needs to be created.

begin
   # create an instance to the radiator contracts API which
   # will give us access to Steem Engine contracts.

   Contracts = Radiator::SSC::Contracts.new

rescue => error
   # I am using Kernel::abort so the code snipped including
   # error handler can be copy pasted into other scripts

   Kernel::abort("Error reading global properties:\n".red + error.to_s)
end

Then the contract is read using the contract method which takes the name of the contract as parameter. As usually the script allows more then one contract name to passed on the command line and a loop is added to get the contract of all names passed.

if ARGV.length == 0 then
   puts "
Steem-Print-SSC-Contract — Print Steem Engine contracts.

Usage:
   Steem-Print-SSC-Contract contract_name …
"
else
   # read arguments from command line

   _names = ARGV

   # Loop over provided contact names and print the steen
   # engine contracts.

   _names.each do |_name|

      # read the contract

       _contract = Contracts.contract _name

      # print the contract

      pp _contract
   end
end

Hint: Follow this link to Github for the complete script with comments and syntax highlighting : Steem-Print-Print-SSC-Contract.rb.

The output of the command mostly consists of the actual contract written in JavaScript:

Screenshot at Jun 05 11-21-40.png

The 2nd important attribute is the table attribute the end of the output which contains the list of tables from the contract which we will need in the next part of the tutorial.

Screenshot at Jun 05 11-22-39.png

Curriculum

First tutorial

Previous tutorial

Next tutorial

Proof of Work

Image Source

Beneficiary

Beneficiary.png

comment votes posts level payout commented voted

Sort:  

Thank you for your contribution @krischik.
After analyzing your tutorial we suggest the following points below:

  • An interesting tutorial how to interact with the Steem blockchain, Steem database and Steem Engine using Ruby.

  • Tutorial is very well structured, but would be welcome to have more detailed information.

Thank you for your work in developing this 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]

Thank you for your review, @portugalcoin! Keep up the good work!

Thanks. I added a more informations on the structure of contracts. Next two parts will on contract tables. Then I plan to show how to print steem engine token balances. Which might take several parts depending if I can include current exchange rates in the print out.

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

Hi, @krischik!

You just got a 5.56% 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.

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!

Coin Marketplace

STEEM 0.17
TRX 0.13
JST 0.027
BTC 61226.21
ETH 2715.69
USDT 1.00
SBD 2.45