GithubHelp home page GithubHelp logo

solana-ruby's Introduction

SolanaRuby

SolanaRuby is a lightweight Ruby client for interacting with the Solana blockchain through its JSON-RPC API. It allows developers to perform various queries on the Solana network such as fetching solana balance, acccount information, and more.

Installation

Add this line to your application's Gemfile:

gem 'solana_ruby', github: 'Build-Squad/solana-ruby', branch: 'main'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install specific_install
$ gem specific_install https://github.com/Build-Squad/solana-ruby.git

Usage

To start using the Solana RPC client, initialize it with or without the RPC URL. The default URL points to the Solana Mainnet. If you wish to connect to another network like Devnet or Testnet, you can specify the URL.

require 'solana_ruby'

# Initialize the client (defaults to Mainnet(https://api.mainnet-beta.solana.com))
client = SolanaRuby::HttpClient.new()

# Optionally, provide a custom RPC URL
# client = SolanaRuby::HttpClient.new("https://api.devnet.solana.com")

Fetch Solana Account Balance

Once the client is initialized, you can make API calls to the Solana network. For example, to get the solana balance of a given account:

# Replace 'pubkey' with the actual public key of the solana account

pubkey = 'Fg6PaFpoGXkYsidMpWxTWqSKJf6KJkUxX92cnv7WMd2J'

result = client.get_balance(pubkey)

puts result

Fetch Parsed Account Info

# Replace 'pubkey' with the actual public key of the account
pubkey = 'Fg6PaFpoGXkYsidMpWxTWqSKJf6KJkUxX92cnv7WMd2J'

# Example of options that can be passed:
options = {
  commitment: 'finalized',   # Specifies the level of commitment for querying state (e.g., 'finalized', 'confirmed', 'processed')
  encoding: 'jsonParsed'     # Specifies the encoding format (e.g., 'jsonParsed', 'base64', etc.)
}

result = client.get_parsed_account_info(pubkey, options)

puts result

Options Parameter

The options parameter is a hash that can include the following fields:

commitment: Specifies the level of commitment desired when querying state.

Options include:

'finalized': Query the most recent block confirmed by supermajority of the cluster.
'confirmed': Query the most recent block that has been voted on by supermajority of the cluster.
'processed': Query the most recent block regardless of cluster voting.

encoding: Defines the format of the returned account data. Possible values include:

'jsonParsed': Returns data in a JSON-parsed format.
'base64': Returns raw account data in Base64 encoding.
'base64+zstd': Returns compressed Base64 data.

By providing options, you can control the nature of the returned data and the reliability of the query.

Filters Parameter

The filters parameter allows you to specify conditions for querying token accounts. Some common filter types include:

# Mint Filter: Filter by a specific token mint. This retrieves accounts holding tokens of that mint.
filters = { mint: 'TokenMintPublicKey' }

# Program Filter: Filter by a specific program (e.g., the token program).
filters = { programId: 'TokenProgramPublicKey' }

Default Options

Several methods have optional parameters where default options are defined in the client. These options can be customized or overridden when calling the methods, but if left unspecified, the client will use its internal defaults.

Available Methods

The following methods are supported by the SolanaRuby::HttpClient:

get_balance(pubkey)
get_balance_and_context(pubkey)
get_slot()
get_epoch_info(options)
get_account_info(pubkey)
get_epoch_schedule()
get_genesis_hash()
get_inflation_governor()
get_inflation_rate()
get_inflation_reward(addresses, options)
get_leader_schedule(options)
get_minimum_ladger_slot()
get_max_retransmit_slot()
get_max_shred_insert_slot()
get_stake_activation(account_pubkey, options)
get_account_info(pubkey)
get_parsed_account_info(pubkey, options)
get_account_info_and_context(pubkey, options)
get_multiple_account_info(pubkeys, options)
get_multiple_account_info_and_context(pubkeys, options)
get_multiple_parsed_accounts(pubkeys, options)
get_largest_accounts(options)
get_program_accounts(program_id, options)
get_parsed_program_accounts(program_id, options)
get_vote_accounts(options)
get_parsed_token_accounts_by_owner(owner_pubkey, filters, options)
And more...

solana-ruby's People

Contributors

chinnabellamkonda avatar

Watchers

Shyam Visamsetty avatar Amarildo avatar  avatar

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.