Bitcoin Forum
May 04, 2024, 09:42:33 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: checking balances with electrum  (Read 683 times)
Drauganaut (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
June 13, 2015, 09: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?
1714858953
Hero Member
*
Offline Offline

Posts: 1714858953

View Profile Personal Message (Offline)

Ignore
1714858953
Reply with quote  #2

1714858953
Report to moderator
1714858953
Hero Member
*
Offline Offline

Posts: 1714858953

View Profile Personal Message (Offline)

Ignore
1714858953
Reply with quote  #2

1714858953
Report to moderator
The Bitcoin software, network, and concept is called "Bitcoin" with a capitalized "B". Bitcoin currency units are called "bitcoins" with a lowercase "b" -- this is often abbreviated BTC.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
ThomasV
Moderator
Legendary
*
Offline Offline

Activity: 1896
Merit: 1353



View Profile WWW
June 13, 2015, 10: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

Electrum: the convenience of a web wallet, without the risks
zebedee
Donator
Hero Member
*
Offline Offline

Activity: 668
Merit: 500



View Profile
June 19, 2015, 01:00:55 PM
 #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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!