Coder Social home page Coder Social logo

casper-ruby-sdk's Introduction

Casper Ruby SDK

The Ruby SDK enables developers to interact with the Casper Network.

Requirements

Click rbenv or here (Steps: 1, 2, 3) to install dependencies.

# Install bundler
gem install bundler

How to install

# There are two options to install casper_sdk

# Option 1:
# Install casper_sdk that is available in the https://guides.rubygems.org/
gem install casper_sdk

# Option 2:
git clone [email protected]:saitgulmez/casper-ruby-sdk.git
cd casper-ruby-sdk
# It automatically installs all the required gems located in the Gemfile
bundle install
# Install casper_sdk gem from repository
# casper_sdk-X.Y.Z.gem will be generated after running below command
gem build casper_sdk.gemspec
# (X, Y, Z depends on s.version described in the casper_sdk.gemspec)
gem install casper_sdk-X.Y.Z.gem

How to build

gem build casper_sdk.gemspec

How to run tests

# Install RSpec
gem install rspec
# Run the test
rspec spec/client_spec.rb

How to generate docs

gem install rdoc
# Generate documentation from source code
rdoc lib/casper_sdk.rb

Usage examples

Get 5 peer IP addresses randomly

require 'casper_sdk'

# In order to interact with casper network we should give a valid ip address to the constructor
# One of an ip address available in the network 
node_ip_address = "74.208.245.69"
client = CasperClient.new(node_ip_address)

# Select 5 peers randomly from the network
peers = client.info_get_peers.sample(5)


# Store ip addresses of these peers into an array
ips = []
peers.select do |item|
  ip = item["address"]
  ips << ip[0, ip.index(':')]
end

# Print
ips.each do |ip_address|
  # Create a client object for each iteration
  client = CasperClient.new(ip_address)
  puts client.info_get_peers
  puts client.chain_get_StateRootHash
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.