If this is your own transaction in Bitcoin-Qt, you can get information about the block it was included in with the console command:
gettransaction 5602487e624ee14193f646e29a9ac203335bc962b30155b66d142ab15f79018c
{
"amount" : 0.10000000,
"fee" : -0.0001000,
"confirmations" : 3592,
"blockhash" : "00000000000000040e4c97bace0df699cabdf5ef68dce31ed62a07fdcb576e6b",
"blockindex" : 22,
"blocktime" : 1387048657,
"txid" : "5602487e624ee14193f646e29a9ac203335bc962b30155b66d142ab15f79018c",
"time" : 1387048401,
"timereceived" : 1387048401, ...
(fake example information above)
If it is an unspent transaction, you can get the transaction itself, but not information about the blockchain:
getrawtransaction 5602487e624ee14193f646e29a9ac203335bc962b30155b66d142ab15f79018c
010000000112e3e4d6554d49d58bb2ebea92cf503c478f3f4c9ac67089644521a7ef41da6000000 0006a47304402207b66a4d39a5e37e501afa84b6499e47928ef2e38bcc09ff079aa9ac08025ddd3 0220378843c39ec76d5f587e3d055a0df0422e66c7e0f6567d38537f59e67938ec8901210217231 bb72798cb5d42b77b8dec1831adf52cdc5a02d23684dd4827c28197a65effffffff021458725800 0000001976a914a41de2dfd3a06aa6ff11e6ff77cd7241df805b0788ac00c2eb0b000000001976a 914ece1ef04103991b1d1241209a37f5d6b84b906fd88ac00000000
Bitcoin does not store a database with more information than it needs to operate, you need to use other tools or a modified Bitcoin to make general queries about other's old transaction information.
You can just put the transaction hash in the front page search box of blockchain.info if you want to find out what block it was included in.
First of all thank you so much for taking your time to explain my query.
What am I trying to do ?
I am trying to get the no. of confirmations of any transaction through web api. I asked the question here => https://bitcointalksearch.org/topic/no-of-confirmation-through-api-385733 and it was almost answered by DeathAndTaxes except the method to find out block hash from tx hash. Block Hash was required to ensure that the transaction in question is still in the main chain, as u'll find in the thread I mentioned.
As you have mentioned above, if I were looking into my own transaction, I could get it using gettransaction through my own Bitcoin-QT. But, as I am writing a web app, I want to query a third party service like blockchain.info or blockexplorer.com, because with the current resource I have, I cant afford to run a Bitcoin-QT on my server.
As I have mentioned above, from rawtx on blockchain.info I even get the block height, but not the block hash. I used to find blockhash by querying blockexplorer.com through like the following...
http://blockexplorer.com/q/getblockhash/277586
But, for some unknown reason, it is now throwing Error !!!
Neways, my basic question remains the same. I need to find out the block hash from a given transaction through web api.
Hey Upal,
I wanted to confirm one thing, if you already have the blockheight can't you work out the no. of confirmations by latestblockheight - blockheight the transaction appeared in?