<p>Bitcoin transactions do not have a failure state, unlike ethereum. They are either mined, or they are not.</p>

<p>In general, a transaction should be considered final when:</p>

<ol>
<li>It is included in a block, let's say with block number n</li>
<li>There are 5 blocks after this (current height >= n+5)</li>
</ol>

<p>You don't really even need to loop every second. You can use the zmq feature of Bitcoin Core, or one of the numerous websocket APIs, or just poll for new blocks every 10 minutes. Once you see your tx in a block, you have one confirmation. Then, you simply need to check the next blocks to make sure they build upon the block with your tx.</p>

CC BY-SA 4.0
2018-06-04T04:39:17.373Z
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
CC BY-SA 4.0
2018-06-04T04:43:24.583Z
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
CC BY-SA 4.0
2018-06-04T05:19:46.160Z
6 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
CC BY-SA 4.0
2018-06-04T05:36:45.610Z
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
CC BY-SA 4.0
2018-06-04T05:39:32.133Z
I recall their being a few websocket APIs around, I believe blockchain.info has one.
Raghav Sood
CC BY-SA 4.0
2018-06-04T06:33:57.713Z
I don't see that the web socket able to watch a specific transaction id or block id. How do you watch it.
vincentsty
CC BY-SA 4.0
2018-06-04T06:35:00.833Z
You could just watch for new blocks in general, and check them for your tx id.
Raghav Sood
CC BY-SA 4.0
2018-06-04T04:10:16.070Z
2018-06-04T04:10:16.070Z
Raghav Sood
<p>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.</p>

<p>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.</p>

<p>To summarize <br>
1) How do i ensure that a transaction is in pending or completed state<br>
2) How do i ensure that a transaction is in success or failure state after completed.<br></p>

<p>What I did in ethereum to confirm the transaction is completed and success: <br>
1) Keep looping and call the txid api every x seconds to get tx detail until it returns non-null object<br>
2) if it returns an object, i can check the status (which is success or failure) to confirm that the transaction is success.<br></p>

<p>How it is done in bitcoin way?</p>

<p>Sample output of insights api tx:</p>

<pre><code>{
    "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
}
</code></pre>

<transactions><bitcoin-core>
How to confirm that a bitcoin transaction is confirmed and success?
vincentsty
# How to confirm that a bitcoin transaction is confirmed and success?

(Asked by: username_0 on 2018-06-04)

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
}

```

**Tags:** transactions, bitcoin-core


---

## 1 answers

### Answer by username_1 on 2018-06-04. Score: 4 | Accepted answer

Bitcoin transactions do not have a failure state, unlike ethereum. They are either mined, or they are not.

In general, a transaction should be considered final when:

1. It is included in a block, let's say with block number n
2. There are 5 blocks after this (current height >= n+5)

You don't really even need to loop every second. You can use the zmq feature of Bitcoin Core, or one of the numerous websocket APIs, or just poll for new blocks every 10 minutes. Once you see your tx in a block, you have one confirmation. Then, you simply need to check the next blocks to make sure they build upon the block with your tx.

> **Comments:**
> **username_0**: 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?  
> **username_0**: 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?  
> **username_1**: 6 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.  
> **username_0**: 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  
> **username_1**: I recall their being a few websocket APIs around, I believe blockchain.info has one.  
> **username_0**: I don't see that the web socket able to watch a specific transaction id or block id. How do you watch it.  
> **username_1**: You could just watch for new blocks in general, and check them for your tx id.  

---

