iota.lib.rb
iota.lib.rb copied to clipboard
Ruby Library for IOTA with core and wrapper api implementation.
[Archived Project] This Gem only supports IOTA 1.0 APIs. Post-chrysalis apis are not supported.
IOTA Ruby Gem
This is the unofficial Ruby gem for the IOTA Core. It implements both the official API, as well as newly proposed functionality (such as signing, bundles, utilities, conversion, multi signature support and reattch/promote).
Installation
Add this line to your application's Gemfile:
gem 'iota-ruby'
And then execute:
$ bundle
Or install it yourself as:
$ gem install iota-ruby
Documentation
You can find basic documentation at: https://vivekmarakana.gitbooks.io/iota-ruby
Getting Started
After you've successfully installed the library, it is fairly easy to get started by simply launching a new instance of the IOTA object with an optional settings object. When instantiating the object you have the option to decide the API provider that is used to send the requests to and you can also connect directly to the Sandbox environment.
The optional settings object can have the following values:
host:StringHost you want to connect to. Can be DNS, IPv4 or IPv6. Defaults tolocalhostport:Integerport of the host you want to connect to. Defaults to 14265.user:Stringusername for host if required.password:Stringpassword for host if required.provider:StringIf you don't provide host and port, you can supply the full provider value to connect tosandbox:BooleanOptional value to determine if your provider is the IOTA Sandbox or not.token:StringToken string in case you are using sandbox.timeout:IntegerTimeout in seconds for api requests to full node. Defaults to 120.batch_size:IntegerBatch size for apis likegetTrytes,getBalancesetc. Defaults to 500.local_pow:BooleanShould PoW be done local machine or not. Defaults tofalsei.e. remote PoW.
You can either supply the remote node directly via the provider option, or individually with host and port, as can be seen in the example below:
require 'iota'
# Create client with host and port as provider
client = IOTA::Client.new(host: 'http://localhost', port: 14265)
# Create client directly with provider
client = IOTA::Client.new(provider: 'http://localhost:14265')
# now you can start using all of the functions
status, data = client.api.getNodeInfo
Overall, there are currently four subclasses that are accessible from the IOTA object:
api: Core API functionality for interacting with the IOTA core.utils: Utility related functions for conversions, validation and so onvalidator: Validator functions that can help with determining whether the inputs or results that you get are valid.multisig: Functions for creating and signing multi-signature addresses and transactions.
How to use the Library
All API calls are executed synchronously and returns array with 2 entries. First entry is status and second is data. However, you can use it by passing block to it as well.
Here is a simple example of how to access the getNodeInfo function:
# Method 1
client.api.getNodeInfo do |status, data|
if !status
# If status is `false`, `data` contains error message...
puts data
else
# If status is `true`, `data` contains response...
puts data.inspect
end
end
# Method 2
status, data = client.api.getNodeInfo
if !status
puts data
else
puts data.inspect
end
Local PoW Support
If you want to use this gem with public full node which does not support remote PoW on host, you can set local_pow to true when initialising the client.
require 'iota'
# With remote PoW
client = IOTA::Client.new(provider: 'https://node.iota-tangle.io:14265')
# If you use `client.api.attachToTangle` api here, you'll get error saying that attachToTangle command is not allowed
# With local pow
client = IOTA::Client.new(provider: 'https://node.iota-tangle.io:14265', local_pow: true)
# Now you can use `client.api.attachToTangle` api, which will do the proof-of-work on transaction and return the trytes that needs to be broadcasted
Compatibility
Tested on Travis CI on following environment configurations