Author

Topic: checking balances with electrum (Read 709 times)

donator
Activity: 668
Merit: 500
June 19, 2015, 08:00:55 AM
#3
I want to use electrum to check the balances of bitcoin addresses in my PHP application. Here is how I am currently doing this:

Code:
function get_address_balance($btcaddress) {
$output = shell_exec("electrum getaddressbalance ".escapeshellarg($btcaddress));

if ($output=='daemon is not connected'){return False;}

$balances = objectToArray(json_decode($output));

// $balances['confirmed'] and $balances['unconfirmed'];
return $balances;
}

This piece of code can take a very long time to execute, usually a minimum of one second but normally much longer than that. what is the best way to do this?
Electrum is an interpreted Python program.  You are restarting it on each run of this code.  The Python interpreter needs to load tons of Python scripts before it can even start doing anything useful.  Usually starting electrum and getting past initialization takes from 1.5 to 10 seconds, depending on your wallet size and computer speed, amongst other things.

If you want to go faster, you need to be asking a long-running daemon process of some kind, not an electrum client.
legendary
Activity: 1896
Merit: 1355
June 13, 2015, 05:17:22 PM
#2
are these addresses from a wallet, or just random addresses?
in the first case, you might want to try the jsonrpc interface that comes with version 2.3
newbie
Activity: 1
Merit: 0
June 13, 2015, 04:37:44 AM
#1
I want to use electrum to check the balances of bitcoin addresses in my PHP application. Here is how I am currently doing this:

Code:
function get_address_balance($btcaddress) {
$output = shell_exec("electrum getaddressbalance ".escapeshellarg($btcaddress));

if ($output=='daemon is not connected'){return False;}

$balances = objectToArray(json_decode($output));

// $balances['confirmed'] and $balances['unconfirmed'];
return $balances;
}

This piece of code can take a very long time to execute, usually a minimum of one second but normally much longer than that. what is the best way to do this?
Jump to: