1

Is the timestamp of a block referring to the time that block is created or when it's mined by a miner?

Suppose I subscribe to new incoming blocks using the following NodeJS code (with web3):

web3.eth.subscribe('newBlockHeaders', function(error, block){
    console.log(block.number);
    console.log(block.timestamp);
    console.log(...computer unix timestamp...);
}

the block number I'am printing is referring to the latest block that was mined?

If I am correct, why if I fetch that block Timestamp and I compare it with the current Unix Time they are different?

For example from the code above i get:

Mined Block number: 11263715
Mined Block timestamp: 1605460505
Unix current timestamp: 1605460537
0

Is the timestamp of a block referring to the time that block is created or when it's mined by a miner?

Yes.

the block number I'am printing is referring to the latest block that was mined?

It is referring to whatever block is the latest block on your node. This information is different across the network until there is some statistical confirmation few blocks later. Blocks can reorganise and minor reorganisations for a new chain tip happens often.

f I am correct, why if I fetch that block Timestamp and I compare it with the current Unix Time they are different?

If you are not a miner, the block you are seeing as the latest block has taken some time to propagate across the network.

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.