Not sure if i'm missing something obvious but is there a simple-ish way to return a wallet balance in a php?
Just a simple return..
$xlmaddress = "GDS5etc";
$bal = $getBal($xlmaddress);
echo $bal; // returns balance
Stellar Stack Exchange is a question and answer site for developers and users of Stellar and the Stellar Distributed Exchange. It only takes a minute to sign up.
Sign up to join this communityI would simply query he horizon server using a GET request and parse the returned JSON data.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://horizon-testnet.stellar.org/accounts/GXXYOURADDRESS');
//return data instead of print
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//$contents variable has the returned data now
$contents = curl_exec($ch);
//decode the json
//you can use json_decode($contents, TRUE) to make it an associative array
$result = json_decode($contents);
//print the balances
print_r($result->balances);
//
//OUTPUT:
Array
(
[0] => stdClass Object
(
[balance] => 9999.9998400
[buying_liabilities] => 0.0000000
[selling_liabilities] => 0.0000000
[asset_type] => native
)
)
You may have multiple balances in the account, you could loop through this array.