Bitcoin Forum
November 01, 2024, 05:16:07 AM *
News: Bitcoin Pumpkin Carving Contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Litecoin/PHP: Can you pull an address balance via API?  (Read 9667 times)
FatMagic (OP)
Full Member
***
Offline Offline

Activity: 224
Merit: 100



View Profile
April 13, 2013, 04:19:29 AM
 #1

Hi all

I've been tinkering with a few PHP pages for my Litecoin mining (I'm a PHP newb)... just pulling down my miner data via the API keys provided by popular pools. Fun stuff.

My question is this: I've been trying to figure out if it's possible to pull down the "balance" of a specific address. I'm want to pull my own Litecoin Wallet balance down into my PHP page via API, but I can't seem to figure it out. I've visited the Litecoin ABE Explorer, and the Litecoin Scout - but it's not clear to me how to pull the balance down. It seems they have API calls for other things, but nothing specifically for the balance - unless you have to pull down multiple pieces of data...

If anyone can point me in the right direction on how to tap into the API properly to pull an address balance - that would be great!

Just need a little help, I'm stumped!

Thanks!

FatMagic (OP)
Full Member
***
Offline Offline

Activity: 224
Merit: 100



View Profile
April 15, 2013, 04:28:26 PM
 #2

Any ideas/help? Should I post this in a different board for more exposure (couldn't figure out which one to post this question in)?

Thanks!

Xenland
Legendary
*
Offline Offline

Activity: 980
Merit: 1003


I'm not just any shaman, I'm a Sha256man


View Profile
April 15, 2013, 08:29:48 PM
 #3

I believe litecoin has the same API as Bitcoins so my BDKphp library could help, I can't say I've tested it on litecoin your welcome to try. It should work 100% in theory though; http://bitcoindevkit.com
diatonic
Sr. Member
****
Offline Offline

Activity: 271
Merit: 250


View Profile
April 22, 2013, 05:48:12 PM
 #4

Take a look at the PHP Bitcoin API. https://en.bitcoin.it/wiki/PHP_developer_intro

s/bitcoind/litecoind/

Should work.

#bitcoin-otc ratings: http://bitcoin-otc.com/viewratingdetail.php?nick=diatonic | Tips: 1DiATonicgGnUcsH6NpSuCEDwRRW3wecgs
w1R903
Full Member
***
Offline Offline

Activity: 218
Merit: 100


View Profile
April 22, 2013, 06:01:59 PM
 #5


Just need a little help, I'm stumped!

Thanks!

Are you wanting your wallet balance?  Or the balance of an address in your wallet?  Those two are very easy to do via the litecoind RPC interface (I assume it's the same as bitcoind's). 

The command 'getbalance' returns your wallet's balance (I'm assuming you're not using accounts).
The command 'getreceivedbyaddress <litecoin address here>' gets that litecoin address's balance.

You can find out info on these and other RPC calls here:
https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list

And information on JSON-RPC here (including some PHP code):
https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)

Now, if you are looking for the balance of arbitrary addresses -- addresses that are not in your wallet -- this is considerably more difficult.  You would have to build your own db of transactions by address, or somehow use an existing implementation that does so (maybe ABE for litecoin?).


4096R/F5EA0017
FatMagic (OP)
Full Member
***
Offline Offline

Activity: 224
Merit: 100



View Profile
April 22, 2013, 06:57:56 PM
 #6

Now, if you are looking for the balance of arbitrary addresses -- addresses that are not in your wallet -- this is considerably more difficult.  You would have to build your own db of transactions by address, or somehow use an existing implementation that does so (maybe ABE for litecoin?).

Yeah unfortunately, that's really what I was looking for. I didn't want to have to depend on running an external program on another PC.

Here's the situation. I have a PHP page that pulls the information for my miners, and for my brother's miners via the Pool API (Give Me LTC). This is running on my Raspberry Pi w/ LAMP. I've made the IP publically available so I can access it on my smart phone. This allows my brother and I to check our miner's status when we are out and about - making sure they are hashing, check outstanding balance w/ pool, etc.

Since everyone's wallet is essentially public - given you have their address - I assumed I could extract the Address balance via ABE @ http://explorer.litecoin.net or Litecoin Scout @ http://litecoinscout.com/-- and then output it on my PHP page. So at any given time, I could pull up my PHP page and it would show not only the Pool API information, but our wallet/address balances as well.

But I'm finding this harder than usual to pull off. ABE doesn't seem to provide this function, at least not easily.

Does that make sense?

thep33t
Full Member
***
Offline Offline

Activity: 126
Merit: 100


View Profile
April 22, 2013, 09:10:23 PM
 #7

Now, if you are looking for the balance of arbitrary addresses -- addresses that are not in your wallet -- this is considerably more difficult.  You would have to build your own db of transactions by address, or somehow use an existing implementation that does so (maybe ABE for litecoin?).

Yeah unfortunately, that's really what I was looking for. I didn't want to have to depend on running an external program on another PC.

Here's the situation. I have a PHP page that pulls the information for my miners, and for my brother's miners via the Pool API (Give Me LTC). This is running on my Raspberry Pi w/ LAMP. I've made the IP publically available so I can access it on my smart phone. This allows my brother and I to check our miner's status when we are out and about - making sure they are hashing, check outstanding balance w/ pool, etc.

Since everyone's wallet is essentially public - given you have their address - I assumed I could extract the Address balance via ABE @ http://explorer.litecoin.net or Litecoin Scout @ http://litecoinscout.com/-- and then output it on my PHP page. So at any given time, I could pull up my PHP page and it would show not only the Pool API information, but our wallet/address balances as well.

But I'm finding this harder than usual to pull off. ABE doesn't seem to provide this function, at least not easily.

Does that make sense?

Unless I am misunderstanding you, you could simply use the litecoin api on your pool server, and run all queries through that. Shouldnt be too hard to do given the code already floating around.

Feathercoin Pool - http://feathercoin.is-a-geek.com - [PPLNS][0% Fees]
FTC: 6sf5CgurY5axcd2cwDHmiwdVMdAF9fw6pU       BTC: 1J74TaaKuNMoy25TP5vXKG2Jw8yg1sqyyQ       BTE: 8QZ2XiantPF8eWmzayo5WaXyYC8unBq5ZC     LTC: LatpwWc4GQyF2teKegZHiDGEGdNEKqEPTT
scintill
Sr. Member
****
Offline Offline

Activity: 448
Merit: 254


View Profile WWW
April 22, 2013, 09:23:06 PM
 #8

You could do it with two calls here: http://explorer.litecoin.net/q

Pulling a random address out.  Get http://explorer.litecoin.net/chain/Litecoin/q/getreceivedbyaddress/LbfSCZE1p9A3Yj2JK1n57kxyD2H1ZSXtNG
Take that, then subtract this value: http://explorer.litecoin.net/chain/Litecoin/q/getsentbyaddress/LbfSCZE1p9A3Yj2JK1n57kxyD2H1ZSXtNG
(Balance = received - sent)  Seems to match what the human-readable page says.  (Depending on the timing and how fast those two numbers update something weird could happen if the balance is changing while you're querying.)  Bummer they don't have a single call for this that I can see.  You could maybe scrape the HTML of the human page and get the balance out of that.

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
w1R903
Full Member
***
Offline Offline

Activity: 218
Merit: 100


View Profile
April 22, 2013, 10:09:08 PM
 #9

Unless I am misunderstanding you, you could simply use the litecoin api on your pool server, and run all queries through that. Shouldnt be too hard to do given the code already floating around.

This is correct.  If you are only interested in the balances of addresses in *your* wallet, you absolutely can find these using the litecoin api on your pool server using the calls I mentioned above.

It's only if you're interested in the balances of addresses *not* in your wallet that you have to worry about building a db or calling an external API of another site that has done this.

4096R/F5EA0017
FatMagic (OP)
Full Member
***
Offline Offline

Activity: 224
Merit: 100



View Profile
April 23, 2013, 12:56:46 PM
 #10

You could do it with two calls here: http://explorer.litecoin.net/q

Pulling a random address out.  Get http://explorer.litecoin.net/chain/Litecoin/q/getreceivedbyaddress/LbfSCZE1p9A3Yj2JK1n57kxyD2H1ZSXtNG
Take that, then subtract this value: http://explorer.litecoin.net/chain/Litecoin/q/getsentbyaddress/LbfSCZE1p9A3Yj2JK1n57kxyD2H1ZSXtNG
(Balance = received - sent)  Seems to match what the human-readable page says.  (Depending on the timing and how fast those two numbers update something weird could happen if the balance is changing while you're querying.)  Bummer they don't have a single call for this that I can see.  You could maybe scrape the HTML of the human page and get the balance out of that.

Ah right on, this is what I needed... I don't mind doing a bit of math to get the answer. That's great! I will give this a shot tonight..
I was considering scraping the HTML page, but that's no fun.

Unless I am misunderstanding you, you could simply use the litecoin api on your pool server, and run all queries through that. Shouldnt be too hard to do given the code already floating around.

This is correct.  If you are only interested in the balances of addresses in *your* wallet, you absolutely can find these using the litecoin api on your pool server using the calls I mentioned above.

It's only if you're interested in the balances of addresses *not* in your wallet that you have to worry about building a db or calling an external API of another site that has done this.

I didn't even consider this... I'm not even sure how to throw my queries against the pool's API (I'm a newb when it comes to PHP/API/etc stuff). I've just used the API they provided, and it provides a static set of information (hashrate, pool balance, lifetime payout, etc). I'm going to try using what Scintill mentioned - and if that doesn't work, I'll be back to figure out what you guys (w1R903 & thep33t) suggested.

Thanks all for the help!

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!