Skip to content

kompendium-ano/factom-ruby-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby JSON-RPC client for Factom API

Build Status Coverage Status Gem License

A JSON-RPC Ruby client for the Factom protocol. Each response has special ADT(algebraic data type) that automatically converted from JSON response and suitable for further usage in business logic. All responses are available in Response directory along with convinient converters.

Installation

Ruby Gem:

gem install factom-rb

Git:

git clone https://github.com/kompendium-llc/factom-ruby.git

Config

You can set multiple types of connections not only local but a remote one.

    # Change default node url or ports
    require_relative './factom-ruby/lib/config'
    config = Config.new

    config.setHost("https://factomd.net")
    config.setPort(8000)
    config.setWalletdPort(8009)

Usage

As a result of each response you'll get a unique structure that available for use in business logic right away.

Retreiving a balance

    require_relative './factom-ruby/lib/Factomd/FactomBalance'
    balance = FactomBalance.new(config)

    # get ec address balance
    result = balance.getECAddressBalance "EC2dTBH2Nc9t9Y7RFD3FYMN5ottoPeHdk6xqUWEc6eHVoBPj6CmH"
    puts result

Reading Entry Data

    require_relative './factom-ruby/lib/Factomd/ReadFactomChain'

    rdChain = ReadFactomChain.new(config)
    readChain = rdChain.readChainEntry "b11bb4e1dacea726224c05bf863092ba02d301de55c08039f381e6e0ad1cef0d"
    puts readChain

Writing an Entry

    require_relative './factom-ruby/lib/FactomWalletd/Compose'
    require_relative './factom-ruby/lib/Factomd/Chains'

    compose = Compose.new(config)
    puts(compose.composeEntry("48e0c94d00bf14d89ab10044075a370e1f55bcb28b2ff16206d865e192827645","EC2DKSYyRcNWf7RS963VFYgMExo1824HVeCfQ9PGPmNzwrcmgm2r"))

    chains = Chains.new(config)

    commitEntry = chains.commitEntry("00016dcfd0983146e5259a21586d887816878126d2e1dd28d446a11d6ab7987f4dc78f2e4e5c17d763ad62244461094efc15bd4f1b2a899e01037416545862d9990806e17e5fe246310ceacb573703b7a8e7f59e11351a23ad48bc22062ff28246748e90231e980bfe58514d89325855ba189f585c259aaaa4b7a420b3c6704fe692cdd49cc4a962e1fe07569bb35841e98b2aae647aff2c163f67722d51024a28e7f05635d07b61f0093a50289281b4a22bb1dc65bfe4a7ecb74f7bff9c58c580c48943c86b9a0e")
    puts commitEntry

    revealChain = chains.revealEntry "007E18CCC911F057FB111C7570778F6FDC51E189F35A6E6DA683EC2A264443531F000E0005746573745A0005746573745A48656C6C6F20466163746F6D21"
    puts revealChain

Block Height and Current Minute

    require_relative './factom-ruby/lib/Factomd/Factoid'
    require_relative './factom-ruby/lib/Factomd/Chains'

    factoid = Factoid.new(config)
    heights = factoid.heights
    puts heights

    chains = Chains.new(config)
    currentMinute = chains.currentMinute
    puts currentMinute

Sending A Transaction

    require_relative './factom-ruby/lib/Factomd/Transaction'
    txn = Transaction.new(config)
    data = [
        "txname" => "test1",
        "inputAddress" => "FA2jK2HcLnRdS94dEcU27rF3meoJfpUcZPSinpb7AwQvPRY6RL1Q",
        "inputAmount" => 1000012000,
        "outputAddress" => "FA2yeHMMJR6rpjRYGe3Q4ogThHUmByk3WLhTjQDvPrxDoTYF8BbC",
        "outputAmount" => 1000000000
    ]
    rs = txn.sendTransaction data
    puts rs

Accessing fields by key

    debug = Debug.new(config)

    # eg. holdingQueue
    response = debug.holdingQueue
    p response.result.Messages

Testing

    ruby tests/Factomd.test.rb
    ruby tests/FactomWalletd.test.rb
    ruby tests/Debug.test.rb

Development

Please, feel free to contribute, fork the repo and submit PR. To contribute to the factom-ruby-client library, clone the repository, create a feature branch and submit a PRfor review.

Additional support for the Factom Protocol or library usage can be found on discord

Learn

Contributions

The Library developed by Kompendium, LLC in partnership with Kelecorix, Inc and Sergey Bushnyak for the good of the Factom community. While we see the usage of the libraries over the months, the Factom community decided not to support this work in the form of a grant either upfront or as backpay on multiple occasions (1, 2, 3)

If you're an active user or find it useful we strongly encourage you to support our efforts and ensure long maintenance by contributing a small donation to one of the following cryptocurrency addresses:

BTC: 39oVXpsgsyW8ZgzsnX3sV7HLdtXWfT96qN
ETH: 0x9cDBA6bb44772259B3A3fb89cf233A147a720f34
FCT: FA38cwer93mmPw1HxjScLmK1yF9iJTu5P87T2vdkbuLovm2YXyss