1
Coming from ethereum background, I am used to the underlying ethereum tx concept where tx id is not available (returns null) until it is being mined. And after the tx is being mined it have three status which are pending, success and failure, which refers to the transaction state.
Is this the same as bitcoin as I could not see the state of transaction in bitcoin. I can't find any status of the transaction in txid of api returns (i use insight api). How could i ensure that the transaction is in pending/complete state and how can i ensure that the transaction is success or failure. I am thinking of checking 6 confirmations but I don't think that this is a "safe" and proper way as confirmation numbers varies.
To summarize
1) How do i ensure that a transaction is in pending or completed state
2) How do i ensure that a transaction is in success or failure state after completed.
What I did in ethereum to confirm the transaction is completed and success:
1) Keep looping and call the txid api every x seconds to get tx detail until it returns non-null object
2) if it returns an object, i can check the status (which is success or failure) to confirm that the transaction is success.
How it is done in bitcoin way?
Sample output of insights api tx:
{
"txid": "",
"version": 2,
"locktime": 0,
"vin": [
...
],
"vout": [
...
],
"blockhash": "0000000000000000000586ebc988140383fd557f9bbc09ca0ac10cff2cb0fafd",
"blockheight": 525860,
"confirmations": 9,
"time": 1528080051,
"blocktime": 1528080051,
"valueOut": 3.27637624,
"size": 290,
"valueIn": 3.27737624,
"fees": 0.001
}
Thanks for the suggestion. I don't think so i can make use of zmq feature as i am not hosting my own full node. Probably not websocket api as well (correct me if i am wrong). what do you mean by poll for new blocks every 10 minutes and how can i do that? – vincentsty – 2018-06-04T04:39:17.373
and also based on your explanation i need to wait around 1 hour before considered the bitcoin transaction is success since each block is 10 minutes and 6 blocks is required. Am i correct? – vincentsty – 2018-06-04T04:43:24.583
16 is the most commonly used number, but for small amounts you could get by with 2 or 3 as well (naturally, it is less secure).
Polling is simply calling any API that gives you the latest block information every 10 minutes in a loop. – Raghav Sood – 2018-06-04T05:19:46.160
I see. thanks for the explaination. is there any web socket or zmq that i can use without using own hosted bitcoin node? as i think probably a pub/sub is a better approach then retrying every x minutes – vincentsty – 2018-06-04T05:36:45.610
I recall their being a few websocket APIs around, I believe blockchain.info has one. – Raghav Sood – 2018-06-04T05:39:32.133
I don't see that the web socket able to watch a specific transaction id or block id. How do you watch it. – vincentsty – 2018-06-04T06:33:57.713
You could just watch for new blocks in general, and check them for your tx id. – Raghav Sood – 2018-06-04T06:35:00.833