Author

Topic: Help understanding payment verification via blockchain.info JSON API (Read 1577 times)

full member
Activity: 120
Merit: 100
Hello Again

If anyone does know how i can get bitcoind to provide me details on any address i would be very interested.

After spending the past week integrating a "kind of new ecommerce" system with blockchains JSON API, today i start further development to notice blockchain JSON API is not working......

I should have known better to rely on 3rd parties....

Ford
full member
Activity: 120
Merit: 100
I would be very interested to know if i can get transactions via bitcoind that are not in the same account/wallet (just like blockchain.info somehow manage to do...)
At present i have managed to do it via the BlockChain JSON API, but i worry about scalability (i.e how will blockchain cope if i try to send 10,000+ calls per hour...)

You can do this (look at the options for indexing all tx's that were introduced after the levelDB introduction).

To be able to query any tx you'll need to "re-index" (this is another option).


Hello and thanks for the reply

I think i may have worded things wrong by saying "transactions" what i meant is "address" as i dont know the transaction numbers.....
I had tried enabling txindex and re-indexed but it still would not bet details on an "address" that was not in my wallet.
If i have still got this wrong and can get the balance of ANY address please do reply.

Thanks
Ford
legendary
Activity: 3682
Merit: 1580
Another thing is that there is a question mark on the accuracy of blockchain.info's output when using getreceivedbyaddress. Blockexplorer is correct in this instance:

18+ http://blockexplorer.com/q/getreceivedbyaddress/1H9uAP3x439YvQDoKNGgSYCg3FmrYRzpD2

15+ http://blockchain.info/q/getreceivedbyaddress/1H9uAP3x439YvQDoKNGgSYCg3FmrYRzpD2

I created the following script and it outputs the blockexplorer number both times even when using blockchain.info data:

Code:
$target_address '1H9uAP3x439YvQDoKNGgSYCg3FmrYRzpD2';
$tx json_decodefile_get_contents"http://blockchain.info/address/$target_address?format=json" ), true );

//print_r( $tx );
$sum 0;
foreach( 
$tx'txs' ] as $transaction ) {
foreach( $transaction'out' ] as $output ) {
if( $output'addr' ] == $target_address ) {
//echo $output[ 'value' ]/100000000 . "\n";
$sum += $output'value' ];
}
}
}

echo 
"blockchain.info sum of received: " $sum/100000000;

$bec json_decodefile_get_contents"http://blockexplorer.com/q/mytransactions/$target_address"), true );

//print_r( $bec );
$bec_sum 0;
foreach( 
$bec as $transaction ) {
foreach( $transaction'out' ] as $output ) {
if( $output'address' ] == $target_address ) {
$bec_sum += $output'value' ];
}
}
}

echo 
"\n" "Blockexplorer.com received sum: $bec_sum";
legendary
Activity: 3682
Merit: 1580
I looked into this a little more and you might be better off using getreceivedbyaddress:

https://blockchain.info/q
http://blockexplorer.com/q

You can see an implementation of this in the function BWWC__getreceivedbyaddress_info in bwwc-utils.php of this WP plugin:

http://wordpress.org/plugins/bitcoin-payments-for-woocommerce/
legendary
Activity: 3682
Merit: 1580

I am going to issue a unique payment address to all sales and get the total received to enter into my DB/ecommerce system, but what if someone then pays on the same unique address. is there a better way that i can get the amount actually received rather than the total received? (as if some one can break things, i find they usually will)

Any help at all or advice would be great (and if anyone finds this code or thread useful, great feel free to use it)

Best Regards
Ford

First up I had no idea you could query blockchain.info data in json format like that. So thanks for that.

Second the solution to your problem is to use a separate address for each transaction. This is actually the recommended way to do things. It will help you to track individual transactions and assign credit to different customers.
legendary
Activity: 1890
Merit: 1086
Ian Knowles - CIYAM Lead Developer
I would be very interested to know if i can get transactions via bitcoind that are not in the same account/wallet (just like blockchain.info somehow manage to do...)
At present i have managed to do it via the BlockChain JSON API, but i worry about scalability (i.e how will blockchain cope if i try to send 10,000+ calls per hour...)

You can do this (look at the options for indexing all tx's that were introduced after the levelDB introduction).

To be able to query any tx you'll need to "re-index" (this is another option).
newbie
Activity: 19
Merit: 0
Hey,
I would not worry about this.  Cool

cheers,
full member
Activity: 120
Merit: 100
You might wanna to also use the original bitcoin rpc api listtransactions or listsinceblock to get transactions for specific address. check out in here: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list

Tried that, but it only returns transactions for the accounts held within the bitcoind client, and i did not want to do this as hackers may be able to steel my shiny coins then
I planned to have payments made to an offline wallet.
Please do correct me if i am wrong!
I would be very interested to know if i can get transactions via bitcoind that are not in the same account/wallet (just like blockchain.info somehow manage to do...)
At present i have managed to do it via the BlockChain JSON API, but i worry about scalability (i.e how will blockchain cope if i try to send 10,000+ calls per hour...)
member
Activity: 98
Merit: 10
Invest NASDAQ in Bitcoin
You might wanna to also use the original bitcoin rpc api listtransactions or listsinceblock to get transactions for specific address. check out in here: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list
full member
Activity: 120
Merit: 100
Hey man,
For me it seems:
"value The value of the payment received in satoshi (not including fees). Divide by 100000000 to get the value in BTC."

You can find nearly everything in the documentation:
http://blockchain.info/de/api/blockchain_wallet_api



cheers,
Gary

Hi Gary

Thanks for the reply

I am not using the RPC connection as i am after transactions/addresses that are not in the block chain wallet and i think it will only give me details on addresses within the wallet.

I can get the full value form the JSON API, but im wondering out of the various transactions that are returned how to get the transaction that i am after, other than just getting the full received amount
newbie
Activity: 19
Merit: 0
Hey man,
For me it seems:
"value The value of the payment received in satoshi (not including fees). Divide by 100000000 to get the value in BTC."

You can find nearly everything in the documentation:
http://blockchain.info/de/api/blockchain_wallet_api



cheers,
Gary
full member
Activity: 120
Merit: 100
Hi All

Im a simple web developer and trying to understand how to verify payments/transactions.

Can anyone comment on the php code i have so far / test code (i am far from a good php programmer, but get by usually)
And the output as i am not fully understanding it.....
(sorry if these sound dumb questions, but i am loving BitCoin and want to start using it on many more sites!)

Code:


$resultBlockHeight 
=  json_decode(file_get_contents('http://blockchain.info/latestblock'));
$current_block_height $resultBlockHeight->height;

$resultBlockChain json_decode(file_get_contents('http://blockchain.info/address/12TsxgagKmaU4ydLP1PesHFiJHvxyZpo7L?format=json'));
$total_received =  $resultBlockChain->total_received;
$number_of_transactions $resultBlockChain->n_tx;

if(
$number_of_transactions 0){
$transaction $resultBlockChain->txs;
foreach($transaction as $id){

$transaction_date =  date('d-m-Y G:i:s'$id->time);

if($id->block_height == ''){
$confirmedTransactions 0;
}
else {
$transaction_block_height $id->block_height;
$confirmedTransactions = ($current_block_height $transaction_block_height 1);
}

// test results / output
echo '$total_received '.$total_received.'
'

echo '$transaction_date '.$transaction_date .'
'
;
echo '$current_block_height '.$current_block_height.'
'
;
echo '$transaction_block_height '$transaction_block_height .'
'
;
echo '$confirmedTransactions = ' .$confirmedTransactions.'
'
;
// raw array output for $id/traansactions
echo '// trasnsactions output';
echo '
 ';
echo print_r($id);
echo '
'
;

}
}else {
// if number_of_transactions !> 0 
}

if(
$number_of_transactions >= 2){
// fuck knows what to do as it should only be 1.....
}

echo 
'// full object output';
echo 
'
';
echo 
print_r($resultBlockChain);
echo 
'
'
;


?>



This generates the following output (with my notes and some questions to the side)

Code:

$total_received 10000
$transaction_date 11-07-2013 22:58:02
$current_block_height 246206
$transaction_block_height 246159
$confirmedTransactions = 48

// transactions output
 stdClass Object
(
    [result] => 0  // result number
    [block_height] => 246159 // blockchain height at time of first confirmed transaction
    [time] => 1373601482 // datetime
    [inputs] => Array
        (
            [0] => stdClass Object
                (
                    [prev_out] => stdClass Object // what does prev_out mean?
                        (
                            [n] => 0
                            [value] => 1030000 // i assume this is the total funds moved including spent, change and transaction fee
                            [addr] => 1B5W3zqE3cfnR6Zz5kDokNr1ur1hcc21Ge
                            [tx_index] => 80631906
                            [type] => 0
                        )

                )

        )

    [vout_sz] => 2 // what is this?
    [relayed_by] => 5.9.24.81
    [hash] => d83b05e28786f37700ee10277dde4e485e38f14b25925944dd60b5c4da73d13c
    [vin_sz] => 1  // what is this?
    [tx_index] => 80634444
    [ver] => 1  // what is this?
    [out] => Array
        (
            [0] => stdClass Object
                (
                    [n] => 0
                    [value] => 1010000 // i assume this is change less transaction fee
                    [addr] => 194QwtJQZjzmacigpJnWMqKWp6GQBh7ZAa
                    [tx_index] => 80634444
                    [type] => 0
                )

            [1] => stdClass Object
                (
                    [n] => 1
                    [value] => 10000 // this is the amount i received
                    [addr] => 12TsxgagKmaU4ydLP1PesHFiJHvxyZpo7L
                    [tx_index] => 80634444
                    [type] => 0
                )

        )

    [size] => 225
)
1

// full object output
stdClass Object
(
    [hash160] => 100d7ae73d621b011eabcb91fd5cd368bf53ea18
    [address] => 12TsxgagKmaU4ydLP1PesHFiJHvxyZpo7L
    [n_tx] => 1
    [total_received] => 10000
    [total_sent] => 0
    [final_balance] => 10000
    [txs] => Array
        (
            [0] => stdClass Object
                (
                    [result] => 0
                    [block_height] => 246159
                    [time] => 1373601482
                    [inputs] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [prev_out] => stdClass Object
                                        (
                                            [n] => 0
                                            [value] => 1030000
                                            [addr] => 1B5W3zqE3cfnR6Zz5kDokNr1ur1hcc21Ge
                                            [tx_index] => 80631906
                                            [type] => 0
                                        )

                                )

                        )

                    [vout_sz] => 2
                    [relayed_by] => 5.9.24.81
                    [hash] => d83b05e28786f37700ee10277dde4e485e38f14b25925944dd60b5c4da73d13c
                    [vin_sz] => 1
                    [tx_index] => 80634444
                    [ver] => 1
                    [out] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [n] => 0
                                    [value] => 1010000
                                    [addr] => 194QwtJQZjzmacigpJnWMqKWp6GQBh7ZAa
                                    [tx_index] => 80634444
                                    [type] => 0
                                )

                            [1] => stdClass Object
                                (
                                    [n] => 1
                                    [value] => 10000
                                    [addr] => 12TsxgagKmaU4ydLP1PesHFiJHvxyZpo7L
                                    [tx_index] => 80634444
                                    [type] => 0
                                )

                        )

                    [size] => 225
                )

        )

)
1


I am going to issue a unique payment address to all sales and get the total received to enter into my DB/ecommerce system, but what if someone then pays on the same unique address. is there a better way that i can get the amount actually received rather than the total received? (as if some one can break things, i find they usually will)

Any help at all or advice would be great (and if anyone finds this code or thread useful, great feel free to use it)

Best Regards
Ford
Jump to: