1

I have a transaction ID and I need to get the time of input and the of output of that transaction (Unix timestamp) programatically using a block explorer or any API.

Is this possible ? If so how can I do that ?

1
  • 1
    Transactions don't have a time. You can look up the timestamp of the block it was included in (which itself may be minutes to an hour off of the real time it was created). Commented Jul 24, 2018 at 13:51

1 Answer 1

1

Transactions do not have an individual timestamp. The closest you can do is get the timestamp from the block that it was included in (but note Pieter's warning about accuracy).

API Example

Using blockchain.info, for example you can do:

https://blockchain.info/rawtx/$tx_hash

For $tx_hash = b6f6991d03df0e2e04dafffcd6bc418aac66049e2cd74b80f14ac86db1e3f0da this would return:

{
    "hash":"b6f6991d03df0e2e04dafffcd6bc418aac66049e2cd74b80f14ac86db1e3f0da",
    "ver":1,
    "vin_sz":1,
    "vout_sz":2,
    "lock_time":"Unavailable",
    "size":258,
    "relayed_by":"64.179.201.80",
    "block_height: 12200,
    "tx_index":"12563028",
    "inputs":[


            {
                "prev_out":{
                    "hash":"a3e2bcc9a5f776112497a32b05f4b9e5b2405ed9",
                    "value":"100000000",
                    "tx_index":"12554260",
                    "n":"2"
                },
                "script":"76a914641ad5051edd97029a003fe9efb29359fcee409d88ac"
            }

        ],
    "out":[

                {
                    "value":"98000000",
                    "hash":"29d6a3540acfa0a950bef2bfdc75cd51c24390fd",
                    "script":"76a914641ad5051edd97029a003fe9efb29359fcee409d88ac"
                },

                {
                    "value":"2000000",
                    "hash":"17b5038a413f5c5ee288caa64cfab35a0c01914e",
                    "script":"76a914641ad5051edd97029a003fe9efb29359fcee409d88ac"
                }

        ]
}

From there you can query the block height of the inputs the same way as above using the inputs[i].prev_out.hash field. Then, to get the timestamp for a block, just query the raw block by height. E.g. for the output timestamps, you would use block_height: 12200 for the example above:

https://blockchain.info/block-height/12200?format=json

The timestamp would be returned in blocks[0].time

Note: Transactions technically can have an individual timestamp. When they do, it is the locktime property, see Bitcoin Wiki - Transaction. However, the locktime is most likely not going to be the time that it was created, rather, the time it is available for spending:

if non-zero and sequence numbers are < 0xFFFFFFFF: block height or timestamp when transaction is final

Your Answer

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

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