1

I'm building an analytics app that tracks transactions on Ethereum and wondering how to get the most accurate timestamp for each transaction. Using the web3.js library I'm able to see the following metadata, but no actual timestamp related to the transactions.

{
  blockHash: '0xab8f0061300d73524ccdccc3107765e5d8d43c842d55a5ca5ffcfe0105e5f8df',
  blockNumber: 10953453,
  from: '0x3f5CE5FBFe3E9af3971dD833D26bA9b5C936f0bE',
  gas: 21000,
  gasPrice: '101000000000',
  hash: '0xf54f84224c76caa5fc34c54ba311469ae0449795933cd3ae2de422a87b0c2707',
  input: '0x',
  nonce: 5327011,
  r: '0xaaadd560f9e747e97cd0362a218ecebf15503371672db9ee0f7364bceb4db67b',
  s: '0x5ac12941aa048b7bf3ff3b4addaf205d23b5a721abd034fc9cd92f57b314a08d',
  to: '0x9B7C174e8970BAb168EbeBde1cf89Edf7066745C',
  transactionIndex: 121,
  v: '0x26',
  value: '735810720000000000'
}

What is the best way to get accurate timestamps for each transaction?

2

Every transaction in a block is processed at the exact same time. If you have the transaction information (which is the data you posted), you can use the blockNumber to look up the block information with getBlock() and find the timestamp of the block (which is also the timestamp of the transaction).

In your case, you would simply call:

web3.eth.getBlock(10953453)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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