I am trying to write a simple test to validate a condition, however it fails saying 'toNumber is not a function'

Here is the test condition

const quorum = await wallet.quorum;
assert(quorum.toNumber() === 2);

quorum is a public uint256 variable defined in the contract

uint256 public quorum;

Any idea, what could be missing here?


1 Answer 1


Nevermind, I figured it out. it was a silly mistake. Missed the round brackets when calling the public variable.

  const quorum = await wallet.quorum();
  • 1
    take care the uint can be very very big and JavaScript cannot handle it. Better to use big numbers libraries
    – Majd TL
    Commented Jan 30, 2022 at 19:04
  • do you mean something like BN.toNumber() ??? Commented Jan 31, 2022 at 4:42
  • 1
    no "quorum" is uint256 therefore it is already a bignumber. my point take care when convert BigNumber to Number is not safe :) if you are using etherjs 5 then "This will throw an error if the value is greater than or equal to Number.MAX_SAFE_INTEGER or less than or equal to Number.MIN_SAFE_INTEGER." docs.ethers.io/v5/api/utils/bignumber/…
    – Majd TL
    Commented Jan 31, 2022 at 8:23
  • how to convert big numbers in case of web3.js Commented Feb 1, 2022 at 12:07
  • Is this a correct way of doing using web3js --- web3.utils.toBN(quorum).toNumber() Commented Feb 1, 2022 at 12:18

Your Answer

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

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