Hive Developer Portal
Search Accounts
How to call a list of user names from the Hive blockchain
Full, runnable src of Search Accounts can be downloaded as part of: tutorials/ruby (or download just this tutorial: devportal-master-tutorials-ruby-15_search_accounts.zip).
This tutorial will return account names matching the input given, up to a specified limit.
Also see:
Sections
- Making the api call - performing the lookup
- Example api call - make the call in code
- Example api call using script - using our tutorial script
- Example Output - output from a successful call
- To Run - Running the example.
Making the api call
To request the a list of accounts starting with a particular lookup pattern, we can use the lookup_accounts
method:
api = Radiator::Api.new
api.lookup_accounts(lower_bound_name, limit) do |accounts|
puts accounts.join(' ')
end
Notice, the above example can request up to 1000 accounts as an array.
Example api call
If we want to get the accounts starting with “alice” …
api.lookup_accounts("alice", 10) do |content| ...
Example api call using script
And to do the same with our tutorial script, which has its own default limit of 10:
ruby search_accounts.rb alice
Example Output
From the example we get the following output from our script:
alice alice-22 alice-is alice-labardo alice-mikhaylova alice-n-chains alice-radster alice-sandra alice-thuigh alice-way
Example api call using script, with limit
And to do the same with our tutorial script, which has its own default limit of 10:
ruby search_accounts.rb bob 1
Example Output, with limit
From the example we get the following output from our script:
bob
Final code:
require 'rubygems'
require 'bundler/setup'
Bundler.require
api = Radiator::Api.new
lower_bound_name, limit = ARGV
limit = (limit || '10').to_i
api.lookup_accounts(lower_bound_name, limit) do |accounts|
puts accounts.join(' ')
end
To Run
First, set up your workstation using the steps provided in Getting Started. Then you can create and execute the script (or clone from this repository):
git clone https://gitlab.syncad.com/hive/devportal.git
cd devportal/tutorials/ruby/15_search_accounts
bundle install
ruby search_accounts.rb <lower-bound-name> [limit]