To get specific block timestamp by tx hash you can query a middleware instance or any known node with the transaction hash at this endpoint:
/v2/transactions/{tx_hash}
You’ll get back a json object, from which you can get the block number which the tx was included in:
{
"block_height": 193952,
"block_hash": "mh_2BXn9dpuKKfMcn5me5Vwx4mb1DtJ38rjK8At2mqQHmqhxpPyWQ",
"hash": "th_2BGm5bbsvum3hDuVP7RvLkdYLbp4aAQZT6qDjq1Ah8bB43Djzu",
"signatures": ["sg_SgxLS3D8YbM1ZYQCPT5nZcFX7CS9xGv9Vydh95BQkhmyVQhLe2QfHwXa9dtgymEFX6jXUwR16XAgxDFy6DMp73YswNXee"],
"tx": {
"amount": 6e+22,
"fee": 16860000000000,
"nonce": 18,
"payload": "ba_Xfbg4g==",
"recipient_id": "ak_Tmwf23kcVVXvJwb79G68wBtyEL9iTSGQRzZz4DJxwTxJWbM1",
"sender_id": "ak_3jgongnfUibKiXBUVCtwXMWbM8hzifRm6C1E4Fp3mKbAT7ZQ9",
"type": "SpendTx",
"version": 1
}
}
After getting the block_height
field you can query again the node at /v2/key-blocks/height/{block_height}
to get the timestamp of this key-block:
{
"beneficiary": "ak_nv5B93FPzRHrGNmMdTDfGdd5xGZvep3MVSpJqzcQmMp59bBCv",
"hash": "kh_dUa6zZYwZj3yxSoF3PkuJXTqiPFKu8z3tPF3R1nmksJ993Tog",
"height": 193952,
"info": "cb_AAAAAj0XPPM=",
"miner": "ak_2jAhFrNdd5RAFd7XguSs9my5DbXUBNCm9mfUGZWmcBo4z3quiR",
"nonce": 7995623650721608000,
"pow": [ ... ],
"prev_hash": "mh_yV6aUhubotT4iuVA1XqwYoVfCBAQdKKw2HiQML95QT3WX5fDn",
"prev_key_hash": "kh_ZZqnCFQ9Y7e9iGzMrh4udNdVNhXDvggpZ8HyMFLufLhjCX6Rn",
"state_hash": "bs_F1GcGpEQpn3pWTo1t58LFCMdETwyMCdaZGZ9FfTYc9TqJGFAX",
"target": 504641518,
"time": 1578378213434,
"version": 4
}
Or as @philipp.chain suggested by the time I wrote this you can also query the /v2/key-blocks/current
endpoint to get the latest block and get the time
.
Refs: