Questions tagged [timestamp]

Questions related to the timestamp value of a block, or the use of Ethereum in timestamping.

Filter by
Sorted by
Tagged with
28
votes
3answers
6k views

Can a contract safely rely on block.timestamp?

How safe is it to use block.timestamp as contract expiration time? If a miner provides an incorrect timestamp in a block header, how much can it be off before it is rejected by other nodes? Is there a ...
27
votes
4answers
21k views

Is the block.timestamp value in Solidity seconds or milliseconds?

I'm looking to use block.timestamp in one of my contracts and I want to know whether the block.timestamp is seconds like in Python or milliseconds like in Java or some other value? Also, is it safe ...
17
votes
1answer
4k views

Is Solidity block.number more secure than timestamp?

In Solidity, some properties such as block.timestamp are attackable by miners and are not (strongly) protected by the protocol. How about block.number, could a miner introduce a randomly high number? ...
16
votes
3answers
4k views

How do Ethereum mining nodes maintain a time consistent with the network?

We have established that the timestamp on a parent block has to be before the timestamp of a child block in Can a child block have an earlier timestamp than the parent block?. How are differences in ...
14
votes
3answers
14k views

How do you work with Date and time on Ethereum platform

Is there a way to access Date object in solidity like in JS? If so, wouldn't it be wrong to call solidity deterministic? So i guess if it called so, you can't. So the question is - how do you work ...
13
votes
2answers
4k views

Is block.timestamp safe for longer time periods?

I would like to set a timer like uint timeout = now + 1 year; Is it possible that a miner cheats the timestamp of the block that it's included more then let's say a month. So if I need roughly 1 ...
9
votes
1answer
13k views

Solidity: Is there a way to get the timestamp of a transaction that executed?

Is there a way for a contract to be able to get the exact time someone called a function in it? For example, if someone sends funds to the contract address, is there a timestamp recorded by the ...
8
votes
2answers
16k views

How to get current time by solidity?

I'd like to describe time like Apr15th 10:00AM . I know how to describe time range as follows, but I am not sure how to call date of time. Could you tell me about it if you know? 1 == 1 second 1 ...
7
votes
2answers
2k views

Solidity: Timestamp dependency, is it possible to do safely?

My contract depends on checking to see if an expiration period has expired before sending the contracts balance. I was looking at the ConsenSys best practices here and it says: Timestamp Dependence ...
7
votes
2answers
541 views

Can a child block have an earlier timestamp than the parent block?

From From EIP 2, the Homestead difficulty adjustment algorithm is: block_diff = parent_diff + parent_diff // 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99) + int(2**...
7
votes
1answer
1k views

How does Ethereum regulate the time between blocks?

I was reading "Explanation of genesis file" and I found the description of the timestamp: A scalar value equal to the reasonable output of Unix’ time() function at this block inception. This ...
7
votes
1answer
692 views

What is “Universal Hash Time”?

What is "Universal Hash Time" which is presented by Jeff Coleman at DEVCON1? What is the purpose? What is the problem it will solve? What is the solution? How does it work?
6
votes
2answers
2k views

How does CryptoKitties track time?

I'm looking at KittyBreeding.sol and see /// @dev Set the cooldownEndTime for the given Kitty, based on its current cooldownIndex. /// Also increments the cooldownIndex (unless it has hit the ...
6
votes
1answer
681 views

Can I retrieve the timestamp the contract was mined on, inside of the contract?

I'm aware of the now keyword that aliases block.timestamp (uint): current block timestamp and the time units But I fail on finding a way to get the block timestamp of when the contract was mined. ...
6
votes
1answer
2k views

How to avoid block.timestamp warning?

I am aware that miner can have influence on block.timestamp My question is, how to avoid this warning?
5
votes
1answer
7k views

How to get the current time in Solidity

How can I get the current time in Solidity. I don't need the current block's time given by now and block.timestamp, but rather the actual current time. Thank you for your help!
5
votes
3answers
1k views

How can I mock the time for solidity tests?

My contract has an expiration date that I'd like to unit test but I don't know how to go about doing that. If I could mock the time of the contract that would be dope. Google search provided no ...
4
votes
2answers
1k views

What is the timestamp of a confirmed transaction based on?

Specifically, if we look at any transaction on the Ethereum blockchain, is the TimeStamp based on when the transaction is generated (like when you click generate transaction on MEW), or is it based on ...
4
votes
4answers
1k views

How to get the block number which is the closest to a given timestamp?

Is there any method(ology) in web3 which allows to get the block number at a given date? In particular, I have two dates as an input and I want to effectively get all events between those two dates. ...
4
votes
2answers
403 views

How Geth and Parity resolve timestamps when validating block headers?

Geth and Parity nodes differ in a fundamental way when they validate block headers. Background According to the yellow paper 4.3 timestamp: A scalar value equal to the reasonable output of Unix's ...
4
votes
2answers
822 views

How does time in the blockchain work?

I hope this question is not bad one, but this has been something I have been having trouble understanding. How does time in the blockchain work, and how can I utilize variables like block.timestamp ...
4
votes
1answer
455 views

Is block's timestamp current block's or previous block's timestamp?

When I call function giveTime, is the time stamp "now" from the block where my call is mined or from the previous block? contract Time { uint time; function giveTime() { time=now; } ...
4
votes
1answer
587 views

How Can I Convert Between A Solidity Timestamp And Year/Month/Day Hour:Minute:Second?

Solidity provides the uint256 now or block.timestamp Special Variable. How can I convert between this Solidity timestamp and year/month/day hour:minute:second?
4
votes
2answers
554 views

Check that the timestamp of the block is greater than that of the previous block and less than 2 hours into the future?

I am reading the White Paper of Ethereum. And at the Mining Section, I do not understand the this part "less than 2 hours into the future" of the following sentence: Check that the timestamp of the ...
4
votes
1answer
127 views

Timestamp in Ethereum

I have a smart contract where the user inputs temperature readings, I'd like to add a time stamp to relate those reading with a current time of submission. I understand that in Ethereum we only have ...
4
votes
2answers
118 views

Balance of an address depending on a time variable

is there a way to compare the balance of an address at two different times or in general check the balance of an address at a specific time? I would like to do something like... uint256 public ...
3
votes
1answer
313 views

Is “now” UTC time in Solidity?

The now keyword in Solidity returns a uint256 with the current block timestamp. Is the timestamp in UTC time? (ie. the number of seconds since 1st January 1970)
3
votes
1answer
992 views

How to do a contract with expire time?

I'm trying to do some modification to a test contract and i want to do it valid until a period of time like defining startingTime= 25/08/2017; endingTime= 27/08/2017; is this possible in some way ...
3
votes
1answer
250 views

Why time values should be used as uint256?

Is there a reason to use the time value as uint256? Is not uint128 enough? UnixTime...
3
votes
1answer
969 views

How does Ethereum avoid inaccurate timestamps in blocks?

A contract can reference the currently being mined contract's timestamp. This means that changing the timestamp of an in-progress to be mined block requires executing all contracts referencing that ...
3
votes
1answer
122 views

Setting time requirements in Solidity

I want a function to only be able to be called after a certain specific period of time has passed from the contract's inception. Generally, I was using block.number for that. As in: require(block....
2
votes
2answers
173 views

Understanding ganache timestamps

Sometimes, when I use the ganache specific evm_increaseTime method and advance to the next block, the next timestamp is NOT: current timestamp + advanced time But instead: current timestamp + ...
2
votes
1answer
3k views

Block time and confirmation time

I have been reading in different papers and comments these two concepts and I would like to know the difference between them(if there is, sometimes it is a bit confusing). I understand that the block ...
2
votes
1answer
997 views

Calculate approximative block height at a certain time?

What would be a formula for calculating the block height at a certain point in time, approximative How would I calculate the block height for a date like next Christmas 0h midnight?
2
votes
1answer
437 views

What recommended amount of storage for storing timestamps?

E.g: uint8, uint16, uint32, uint64, uint128, uint256? Which of these is best recommended to future-proof the application? And given each uint, what year is the furthest it could be stored?
2
votes
2answers
198 views

Get latest update time-stamp of contract variable

Is it possible to get latest update time of contract variable without preserving the transaction hash, contract Demo{ uint numb; function setNumb(uint var1){ numb=var1 } } in above contract ...
2
votes
3answers
65 views

How to get the actual time of occurrence for ethereum transaction in block

I used the API of Ethereum to download some transactions info. The timestamp is included, however I found the timestamp not mean the transaction time but the block which this transaction is located ...
2
votes
1answer
125 views

How can I increase EVM time in web3.py?

When working with web3.js, Truffle and Ganache, I can do this: web3.currentProvider.send({method: "evm_increaseTime", params: [numOfSeconds]}); How can I do the equivalent in web3.py? When I do: ...
2
votes
1answer
512 views

What types do “now” and “block.timestamp” return?

Is it a uint256 in the form of a standard UNIX timestamp? Thanks
2
votes
1answer
40 views

How to Calculate How Long an Address Has Held A Token? (for paying interest/rewards)

I'm writing a smart contract function that rewards users some rate of interest/reward for holding my stablecoin over owning competitors (Dai, Tether, etc). What is the most efficient manner to ...
2
votes
1answer
50 views

Can the block number be set back in ganache?

I know about tools like ganache-time-traveler that let you advance the block number. But is it possible to go back to a lower value?
2
votes
1answer
46 views

Are block timestamps decentralized?

One thing I don't understand about the Ethereum protocol is how timestamps work. If I, as miner, have a reason to fiddle with timestamps (such as adding a few minutes to decrease the mining difficulty)...
2
votes
1answer
76 views

Are the timestamps of blocks for Ethereum only accepted when they are monotonically increasing?

Are the timestamps of blocks for Ethereum only accepted when they are monotonically increasing? If yes, why? And why other blockchains like Bitcoin and other blockchains with shorter block time can ...
2
votes
0answers
454 views

Working with time in smart contracts

I know there have been quite a few questions surrounding time, and the use of block.timestamp. However, I still have a few questions design-wise. At what point exactly is it 'dangerous' to use block....
2
votes
0answers
612 views

Parity - scheduled TX on local time zone

Looks like the Parity Browser doesn't show the local time zone for a "send after Date & Time' functionality. Questions: What is the time zone for a scheduled TX on Parity? If the scheduled ...
1
vote
1answer
219 views

How can i implement deadlines in smartContract?

Suppose I am running a gallery and ask participants to submit there paintings before a specific date. After passing that date participant should not be able to submit their entry. How can I implement ...
1
vote
2answers
290 views

Slackness issue and time in smart contracts

At a high level, slackness issue says, it is not possible to guarantee that at any given point in time all honest miners see exactly the same blockchain length [1]. On the other hand, as we know the ...
1
vote
2answers
77 views

How can I send eth on specific time?

How can I send eth on specific time? In case the ICO crowd sale starts on 9:00:00 UTC, how can I make txid on 9:00:00 exactly when I send eth?
1
vote
1answer
474 views

How can you add a certain number of months to a timestamp (uint)?

I am writing a contract that will calculate interest on a periodic basis using the exact number of days in each period. So, for example, if I use Jan 1st 2018 to March 31st 2018 as an example, there ...
1
vote
1answer
204 views

Ethereum extract transactions based on timestamp

I am trying to extract all transactions of Ethereum using the eth scan API. But I need transactions for specific time periods only. I tried running the API for all the blocks to try and extract all ...