0

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
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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