WorldOfBitcoin (OP)
Member
Offline
Activity: 102
Merit: 10
|
|
October 03, 2012, 04:03:15 AM |
|
I'm new to PHP, looking though a lot scripts on the site and they seem to be doing a lot more then I need. I'm simply trying to get the JSON object for an imputed address and get an array of transactions. And store that data on my site.
Been fooling around with a couple shopping cart's and still trying to grasp what all the JSON-RPC PHP does. I'm thinking it im going a lot farther then I need to do this.
Any pointers or material you could link to me would be greatly Appreciated.
|
|
|
|
payb.tc
|
|
October 03, 2012, 04:14:57 AM |
|
|
|
|
|
WorldOfBitcoin (OP)
Member
Offline
Activity: 102
Merit: 10
|
|
October 03, 2012, 04:28:19 AM |
|
Uploaded the JSON RPC onto the site. Just left it in its folder Going though the example.php Should I make a new class say Transactions with this example? or once I got the jsonrpcphp folder in my root directory i can just call to it? something like? <?php $client=new jsonRPCClient(' http://blockchain.info/address/$bitcoin_address?format=json'); $txs=$client->gettxs(); ?>
|
|
|
|
payb.tc
|
|
October 03, 2012, 04:38:06 AM |
|
Uploaded the JSON RPC onto the site. Just left it in its folder Going though the example.php Should I make a new class say Transactions with this example? or once I got the jsonrpcphp folder in my root directory i can just call to it? something like? <?php $client=new jsonRPCClient(' http://blockchain.info/address/$bitcoin_address?format=json'); $txs=$client->gettxs(); ?> don't put the blockchain.info address URL in there... put the URL which points to bitcoind. eg. http://username:password@127.0.0.1:8332/ if you're running bitcoind on your own server or http://username:password@blockchain.info:80if you're using blockchain.info's api you don't need to make a new class. just call jsonRPCClient with whatever function you need to use.
|
|
|
|
WorldOfBitcoin (OP)
Member
Offline
Activity: 102
Merit: 10
|
|
October 03, 2012, 04:41:51 AM |
|
ahh, Im not even running bitcoind right now. Im just trying to keep track of an address linked to an offline wallet.
Ill start reading up on bitcoind.
|
|
|
|
payb.tc
|
|
October 03, 2012, 04:44:03 AM |
|
ahh, Im not even running bitcoind right now. Im just trying to keep track of an address linked to an offline wallet.
Ill start reading up on bitcoind.
if you're purely just keeping track of an address, you don't even need to use RPC... you could use cURL to read from blockchain.info's output, and then use PHP's functions to decode that JSON output into an object or array.
|
|
|
|
Severian
|
|
October 03, 2012, 04:44:46 AM |
|
Ill start reading up on bitcoind.
It's cool as hell.
|
|
|
|
payb.tc
|
|
October 03, 2012, 04:46:21 AM |
|
here's some code i did using cURL: <?php function get_address_info($address, $debug = false) { $url = 'http://blockchain.info/address/' . $address . '?format=json';
if ($debug) { echo 'Fetching URL: '.$url.'<br/>'; }
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $response = curl_exec($ch); curl_close($ch);
if ($debug) { echo '<pre>Curl Response: '; print_r($response); echo '</pre>'; }
return json_decode($response); }
no jsonRPCClient required.
|
|
|
|
WorldOfBitcoin (OP)
Member
Offline
Activity: 102
Merit: 10
|
|
October 03, 2012, 04:48:05 AM |
|
ahh, Im not even running bitcoind right now. Im just trying to keep track of an address linked to an offline wallet.
Ill start reading up on bitcoind.
if you're purely just keeping track of an address, you don't even need to use RPC... you could use cURL to read from blockchain.info's output, and then use PHP's functions to decode that JSON output into an object or array. awsome, I'm going to try and do that first. thanks, im adding your code. Ill report back
|
|
|
|
payb.tc
|
|
October 03, 2012, 04:48:57 AM |
|
cURL a thing or that just a typo? what would that php look like?>
it's a thing. although i don't remember what the 'c' stands for.
|
|
|
|
WorldOfBitcoin (OP)
Member
Offline
Activity: 102
Merit: 10
|
|
October 03, 2012, 04:56:19 AM |
|
<?php $address='13sFP2R1tENbxcxGtH72ceW7YCvFjdLJkT'; function get_address_info($address, $debug = false) { $url = ' http://blockchain.info/address/' . $address . '?format=json'; if ($debug) { echo 'Fetching URL: '.$url.'<br/>'; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $response = curl_exec($ch); curl_close($ch); if ($debug) { echo '<pre>Curl Response: '; print_r($response); echo '</pre>'; } return json_decode($response); } ?> Defined the address not outputting anything, tinkering
|
|
|
|
payb.tc
|
|
October 03, 2012, 04:59:28 AM |
|
your basic code is mal-formed.
try this:
$address = '13sFP2R1tENbxcxGtH72ceW7YCvFjdLJkT'; //sets the address $address_info = get_address_info($address); //gets the info about the address into $address_info var_dump($address_info); //outputs the contents of $address_info to the browser
(and include the get_address_info function too)
edit: actually, to start with, use this line in place of line 2 above: $address_info = get_address_info($address, true); //gets the info about the address into $address_info that way, you'll see some handy info on the screen to show what's going on.
|
|
|
|
bitvientiane
Newbie
Offline
Activity: 44
Merit: 0
|
|
October 03, 2012, 05:01:07 AM |
|
I wish someone would implement a full client in PHP. Although that's a lot of work of course.
|
|
|
|
WorldOfBitcoin (OP)
Member
Offline
Activity: 102
Merit: 10
|
|
October 03, 2012, 05:04:57 AM |
|
your basic code is mal-formed.
try this:
$address = '13sFP2R1tENbxcxGtH72ceW7YCvFjdLJkT'; //sets the address $address_info = get_address_info($address); //gets the info about the address into $address_info var_dump($address_info); //outputs the contents of $address_info to the browser
(and include the get_address_info function too)
hell yea, getting there. outputted data without formatting
|
|
|
|
payb.tc
|
|
October 03, 2012, 05:07:57 AM |
|
hell yea, getting there. outputted data without formatting
i usually do this instead of var_dump: echo '<pre>'; print_r($whatever); echo '</pre>'; makes for an easy visualisation of the variable's structure.
|
|
|
|
SuperP
|
|
October 03, 2012, 06:26:24 AM |
|
When I use the blockchain.info listaccounts() call, I get an array with all the bitcoin balances rounded to 3 decimal places. Is that something I have to handle properly? How can I get it to go to 8 decimal places?
|
|
|
|
WorldOfBitcoin (OP)
Member
Offline
Activity: 102
Merit: 10
|
|
October 03, 2012, 06:38:36 AM |
|
When I use the blockchain.info listaccounts() call, I get an array with all the bitcoin balances rounded to 3 decimal places. Is that something I have to handle properly? How can I get it to go to 8 decimal places?
im pretty sure im getting satoshi, the 3.75250000 yup 8, And a ton of other crap. with the Var_dump object(stdClass)#1 ( { ["hash160"]=> string(40) "1f710da1e75db36e0d47eda896a3b50d9e6c9279" ["address"]=> string(34) "13sFP2R1tENbxcxGtH72ceW7YCvFjdLJkT" ["n_tx"]=> int(2) ["n_unredeemed"]=> int(0) ["total_received"]=> int(375250000) ["total_sent"]=> int(375250000) ["final_balance"]=> int(0) ["txs"]=> array(2) { - => object(stdClass)#2 (12) { ["hash"]=> string(64) "9e7aa7fc7913cfd8ce899472e477451953827ffc9555ffb1bb7b540cadc8b92f" ["ver"]=> int(1) ["vin_sz"]=> int(1) ["vout_sz"]=> int(2) ["size"]=> int(226) ["relayed_by"]=> string(14) "68.118.161.168" ["tx_index"]=> int(19350109) ["result"]=> int(0) ["time"]=> int(1347001988) ["block_height"]=> int(197662) ["inputs"]=> array(1) {
- => object(stdClass)#3 (1) { ["prev_out"]=> object(stdClass)#4 (5) { ["type"]=> int(0) ["addr"]=> string(34) "13sFP2R1tENbxcxGtH72ceW7YCvFjdLJkT" ["value"]=> int(375250000) ["tx_index"]=> int(19347253) ["n"]=> int(0) } } } ["out"]=> array(2) {
- => object(stdClass)#5 (3) { ["addr"]=> string(33) "1oxCcHwsiREsmBs59nDf88xxjYPLttSkv" ["value"]=> int(275200000) ["type"]=> int(0) } [1]=> object(stdClass)#6 (3) { ["addr"]=> string(34) "1FEps6A6aAqyh4LmnnmuUdtGnfAq5JpgRK" ["value"]=> int(100000000) ["type"]=> int(0) } } } [1]=> object(stdClass)#7 (12) { ["hash"]=> string(64) "68b82640a6a5ed8564a64d22f361fb36f4b226c79b47531253858402b28728bd" ["ver"]=> int(1) ["vin_sz"]=> int(1) ["vout_sz"]=> int(2) ["size"]=> int(227) ["relayed_by"]=> string(14) "122.103.238.28" ["tx_index"]=> int(19347253) ["result"]=> int(-375250000) ["time"]=> int(1346999015) ["block_height"]=> int(197653) ["inputs"]=> array(1) {
- => object(stdClass)#8 (1) { ["prev_out"]=> object(stdClass)#9 (5) { ["type"]=> int(0) ["addr"]=> string(34) "1MdYdRzAYzcsWHyuS15jdiwH5eEn4BQ6Ck" ["value"]=> int(875300000) ["tx_index"]=> int(19343969) ["n"]=> int(0) } } } ["out"]=> array(2) {
- => object(stdClass)#10 (3) { ["addr"]=> string(34) "13sFP2R1tENbxcxGtH72ceW7YCvFjdLJkT" ["value"]=> int(375250000) ["type"]=> int(0) } [1]=> object(stdClass)#11 (3) { ["addr"]=> string(34) "197AmScUheUZFjVoDPJCXUfEjN6cgZy5s9" ["value"]=> int(500000000) ["type"]=> int(0) } } } } }
Man is that ugly. I'm going to poke around to I can find a way to output it to nice clean HTML like on blockchain.info
|
|
|
|
SuperP
|
|
October 03, 2012, 07:00:59 AM |
|
object(stdClass)#1 ( { ["hash160"]=> string(40) "1f710da1e75db36e0d47eda896a3b50d9e6c9279" ["address"]=> string(34) "13sFP2R1tENbxcxGtH72ceW7YCvFjdLJkT" ["n_tx"]=> int(2) ["n_unredeemed"]=> int(0) ["total_received"]=> int(375250000) ["total_sent"]=> int(375250000) ["final_balance"]=> int(0) ["txs"]=> array(2) { - => object(stdClass)#2 (12) { ["hash"]=> string(64) "9e7aa7fc7913cfd8ce899472e477451953827ffc9555ffb1bb7b540cadc8b92f" ["ver"]=> int(1) ["vin_sz"]=> int(1) ["vout_sz"]=> int(2) ["size"]=> int(226) ["relayed_by"]=> string(14) "68.118.161.168" ["tx_index"]=> int(19350109) ["result"]=> int(0) ["time"]=> int(1347001988) ["block_height"]=> int(197662) ["inputs"]=> array(1) {
- => object(stdClass)#3 (1) { ["prev_out"]=> object(stdClass)#4 (5) { ["type"]=> int(0) ["addr"]=> string(34) "13sFP2R1tENbxcxGtH72ceW7YCvFjdLJkT" ["value"]=> int(375250000) ["tx_index"]=> int(19347253) ["n"]=> int(0) } } } ["out"]=> array(2) {
- => object(stdClass)#5 (3) { ["addr"]=> string(33) "1oxCcHwsiREsmBs59nDf88xxjYPLttSkv" ["value"]=> int(275200000) ["type"]=> int(0) } [1]=> object(stdClass)#6 (3) { ["addr"]=> string(34) "1FEps6A6aAqyh4LmnnmuUdtGnfAq5JpgRK" ["value"]=> int(100000000) ["type"]=> int(0) } } } [1]=> object(stdClass)#7 (12) { ["hash"]=> string(64) "68b82640a6a5ed8564a64d22f361fb36f4b226c79b47531253858402b28728bd" ["ver"]=> int(1) ["vin_sz"]=> int(1) ["vout_sz"]=> int(2) ["size"]=> int(227) ["relayed_by"]=> string(14) "122.103.238.28" ["tx_index"]=> int(19347253) ["result"]=> int(-375250000) ["time"]=> int(1346999015) ["block_height"]=> int(197653) ["inputs"]=> array(1) {
- => object(stdClass)#8 (1) { ["prev_out"]=> object(stdClass)#9 (5) { ["type"]=> int(0) ["addr"]=> string(34) "1MdYdRzAYzcsWHyuS15jdiwH5eEn4BQ6Ck" ["value"]=> int(875300000) ["tx_index"]=> int(19343969) ["n"]=> int(0) } } } ["out"]=> array(2) {
- => object(stdClass)#10 (3) { ["addr"]=> string(34) "13sFP2R1tENbxcxGtH72ceW7YCvFjdLJkT" ["value"]=> int(375250000) ["type"]=> int(0) } [1]=> object(stdClass)#11 (3) { ["addr"]=> string(34) "197AmScUheUZFjVoDPJCXUfEjN6cgZy5s9" ["value"]=> int(500000000) ["type"]=> int(0) } } } } }
Is that what bitcoind gives as output for listaccounts()? The blockchain.info json rpc api gives me something that looks like: Array ( [1JzpGDthPGqfsdfeajN5iiVj2SLq4FKpL] => 0.002 [1sadfweHkPTFL2TogQJz7LbpEsvpQJ1dxfa] => 1.534 [1MCL86tPrhNCjEsdfwVcrqL7rAsRZZKrrq] => 0.003 )
I guess the blockchain.info api is simplified and higher precision isn't available?
|
|
|
|
payb.tc
|
|
October 03, 2012, 12:17:35 PM |
|
Man is that ugly. I'm going to poke around to I can find a way to output it to nice clean HTML like on blockchain.info
i usually do this instead of var_dump:
echo '<pre>'; print_r($whatever); echo '</pre>';
makes for an easy visualisation of the variable's structure.
|
|
|
|
|