0

I have a function inside my smart contract that fetches the timestamp of the block it's in:

function getTime() public returns (uint256 time){
    return block.timestamp;;
}

According to how I understand timestamps, this should return one value. Yet when I deploy the contract and test that method it returns two values:

truffle(development)> contract.getTime.call({from: accounts[1]})
BN {
  negative: 0,
  words: [ 41810542, 23, <1 empty item> ],
  length: 2,
  red: null
}

Why is this happening/ what do the two values represent if only one of them is the timestamp?

| improve this question | | | | |
  • where do you see two numbers? – Lauri Peltonen Mar 27 at 13:20
  • Inside the array labeled words - I see 41810542 and 23 in addition to the length being equal to 2 – Nicolas Schapeler Mar 27 at 13:22
1

That BN stands for BigNumber. It's a JavaScript framework for representing..well...big numbers.

If you simply console.log a BigNumber it will give you such internal data of the single BigNumber, such as those length and words. Those are not trivially interpretable.

So what you should do it simply .toString() it to get the actual number. It really is just one number and what you are now seeing is an object representation of the single number. Here's some more info: https://ethereum.stackexchange.com/a/70926/31933

| 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.