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

1 Answer 1


I 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
    [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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.