Author

Topic: No. of confirmation through API (Read 1377 times)

full member
Activity: 165
Merit: 102
December 29, 2013, 03:32:53 PM
#8
Sorry I looked quickly and assumed the rawtx call provided the block hash as well as the block height.

Its OK. Would u mind to tell me if this "main_chain":true happens to the block as soon as the tx is created ? Once I have "main_chain":true, can it be converted to "main_chain":false at a later state when I have got a few confirmations ?
donator
Activity: 1218
Merit: 1079
Gerald Davis
December 28, 2013, 05:14:25 PM
#7
Sorry I looked quickly and assumed the rawtx call provided the block hash as well as the block height.
full member
Activity: 165
Merit: 102
December 28, 2013, 03:40:10 PM
#6
But, in step 1, when I make a call to rawtx, I only get the block_height ...is not it ? Which one is the block_hash in this call ? e.g.

https://blockchain.info/rawtx/5bc9ed31d4cf09d31cf935cc9e2e4062a9f4cfc6fe48fec6d3961dcfc6e08515

Quote
{"block_height":154594,"time":1322130562,"inputs":[{}],"vout_sz":1,"relayed_by":"0.0.0.0","hash":"5bc9ed31d4cf09d31cf935cc9e2e4062a9f4cfc6fe48fec6d3961dcfc6e08515","vin_sz":1,"tx_index":2091476,"ver":1,"out":[{"n":0,"value":5002150000,"addr":"1AvVCRXzuBNTBR3UKjZNKGsGWjPqZnhX7H","tx_index":2091476,"spent":true,"type":0}],"size":135}

"block_height":154594

Which one is block hash ?


Thanks again for your response...
donator
Activity: 1218
Merit: 1079
Gerald Davis
December 28, 2013, 01:45:42 PM
#5
Thank u so much for the explanation. Would u mind to say how do I accomplish Point 2 using API ? I mean I have got my tx block hash, but how do I check if it is part of the main chain ?

Using blockchain.info API?
By looking for "mainchain" value in the rawblock RPC using the blockhash from step 1.

https://blockchain.info/rawblock/00000000000007d0f98d9edca880a6c124e25095712df8952e0439ac7409738a

Quote
{
   "hash":"00000000000007d0f98d9edca880a6c124e25095712df8952e0439ac7409738a",
   "ver":1,   
   "prev_block":"0000000000000a5d8e40fb83ef468e6d83d1bf5365a8dfad36c4271c4a68c7b5",
   "mrkl_root":"4850536df3c620972a07df5bd4896c61212776059ad6be4f6b583f9186bc98e9",
   "time":1322130562,
   "bits":437129626,
    "fee":2150000,
    "nonce":2984497136,
   "n_tx":99,
   "size":26700,
   "block_index":169706,
   "main_chain":true,
   "height":154594,
   "received_time":1322130562,
   "relayed_by":"127.0.0.1",
...

With blockchain.info the internals of their API are a blackbox so I wouldn't want to assume that however you can explicitly confirm that by
a) getting the blockhash of the tx (rawtx)
b) checking that block is still in the main chain (rawblock)
c) computing the confirmations as latestblock_height - txblock_height  (latestblock)

Combined that allows you to verify that the tx is in a block, that the block is in the main chain and has the required number of confirmations.

If you have the ability to run bitcoind (can be run without server knowing the decryption passphrase or even better with a watching wallet copy) you can get the same information easier and without having to trust a third party.   You can use the transaction and block callback to be notified when a tx is included in a block and when a block has found.  By checking the status of the tx you can confirm it is in the main chain (orphaned tx will show 0 confirms).

If you want an easier option and can't run bitcoind, blockchain.info also has a receive payments API.  Understand this isn't zero-trust as payments will be sent to an address which blockchain.info has the private key for and then forwarded on to an address you designate.  This means in theory funds could be stolen if blockchain.info is hacked or "hacked".  It does however provide an easier higher level API and the potential loss is limited to payments that haven't yet been forwarded to you.  Depending on your transaction value and risk tolerance this might be acceptable.  Do your own due diligence I haven't used or researched this API.
https://blockchain.info/api/api_receive
full member
Activity: 165
Merit: 102
December 28, 2013, 01:42:18 PM
#4
Thank u so much for the explanation. Would u mind to say how do I accomplish Point 2 using API ? I mean I have got my tx block hash, but how do I check if it is part of the main chain ?
donator
Activity: 1218
Merit: 1079
Gerald Davis
December 26, 2013, 10:50:40 AM
#3
It is a little more complex than that using the low level API.

1) The API call you referenced includes block height & block hash.
2) You can then check if the block (by block hash) is in the MAIN CHAIN by checking the block.
3) Getting the most recent block would give you the # of confirmations (recent_block_height - tx_block_height = #confirmations).

Step #2 is important as the chain can fork and your tx can be in a block which is orphaned off the main chain.  In most cases an orphaned tx (a tx confirmed in an orphaned block) will also be confirmed in a block in the main chain but in the event of a double spend it won't.

Still honestly I would use bitcoind directly rather than add a trusted third party into a network which is trustless.  With bitcoind you can use waletnotify & blocknotify to create callback functions which will fire whenever there is a new tx or new block.
full member
Activity: 165
Merit: 102
December 26, 2013, 10:42:29 AM
#2
any help ?
full member
Activity: 165
Merit: 102
December 26, 2013, 06:37:23 AM
#1
May I know the no. of confirmations through API ? I was reading this and did not find no. of confirmations...

https://blockchain.info/rawtx/83c1172ce6c6ec998fc4f1b010a1335ce6516928fb9142d3046f9444cbdf2356
Jump to: