Menu

Print Steem Engine Contracts

Martin Krischik

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


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.