Hive Developer Portal
Search Accounts
How to call a list of user names from the Hive blockchain
Introduction
In this tutorial, we will see how to get accounts list start with the selected string. We made this with hive-php-lib. You can also find the result PHP file in the /resources/examples/searchAccounts.php
file in hive-php-lib
folder.
Also see:
Preparation
Before start to code, don’t forget to read the PHP: Getting Started tutorial to see how to prepare your code for hive-php-lib. If you want a shortcut, just start your PHP file with:
<?php
/* Load Composer for autoload libs */
require __DIR__ . '/vendor/autoload.php';
/* Declase use statement to add Hive Condenser lib */
use Hive\PhpLib\Hive\Condenser as HiveCondenser;
/* Create config array and fill with settings */
$config = [
"debug" => false,
"disableSsl" => false,
"heNode" => "api.hive-engine.com/rpc",
"hiveNode" =>"anyx.io",
];
/* Instantiate Hive Condenser object */
$hiveApi = new HiveCondenser($config);
Query
Now, use the lookupAccounts
function. This function must have 2 arguments:
$lowerBound
: (string) the selected string,$limùit
:(int)number of records to display.
$lowerBound = 'bamb';
$limit = 10;
$result = $hiveApi->lookupAccounts($lowerBound, $limit);
Now, you have an array ($result
) with 10 first accounts name started with “bamb”. To display them, just print_r()
:
print_r($result);