All examples from this tutorial can be found as fully functional scripts on GitHub:
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.
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
For reader with programming experience this tutorial is basic level.
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.
There are two main components to each contract:
In addition to those there is a small set of meta data like the owner and hash code of the contract.
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:
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.