Author

Topic: Litecoin/PHP: Can you pull an address balance via API? (Read 9676 times)

full member
Activity: 224
Merit: 100
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!
full member
Activity: 218
Merit: 100
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.
sr. member
Activity: 448
Merit: 254
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.
full member
Activity: 126
Merit: 100
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.
full member
Activity: 224
Merit: 100
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?
full member
Activity: 218
Merit: 100

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 ' 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?).

sr. member
Activity: 271
Merit: 250
Take a look at the PHP Bitcoin API. https://en.bitcoin.it/wiki/PHP_developer_intro

s/bitcoind/litecoind/

Should work.
legendary
Activity: 980
Merit: 1003
I'm not just any shaman, I'm a Sha256man
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
full member
Activity: 224
Merit: 100
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!
full member
Activity: 224
Merit: 100
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!
Jump to: