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?

2
  • where do you see two numbers? Commented Mar 27, 2020 at 13:20
  • Inside the array labeled words - I see 41810542 and 23 in addition to the length being equal to 2
    – user49342
    Commented Mar 27, 2020 at 13:22

1 Answer 1

0

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

1
  • That did the trick. Thank you so much!
    – user49342
    Commented Mar 27, 2020 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.