2

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
}

1 Answer 1

3

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.

7
  • 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
    Jun 4, 2018 at 4:39
  • 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
    Jun 4, 2018 at 4:43
  • 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. Jun 4, 2018 at 5:19
  • 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
    Jun 4, 2018 at 5:36
  • I recall their being a few websocket APIs around, I believe blockchain.info has one. Jun 4, 2018 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.