BigInteger blockNum = web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send()

Long.MAX_VALUE (9223372036854775807) is more than enough to hold block number.

It is easier and efficient to iterate over long than BigInteger. There are use-cases when we need to iterate over blocks; for example - to find N latest blocks.

Also addition, deletion and comparison is easier with long.


You're right, using a 'long' would be more efficient to store a value such as block number.

In fact, if you look at Ethereumj (Java implementation of Ethereum protocol) you'll see that they have used 'long' to represent the block number in the BlockHeader class.

/* A scalar value equal to the number of ancestor blocks.
* The genesis block has a number of zero */
private long number;

Web3j EthBlock class stores the block number as a string and converts it to a BigInteger when needed. My only idea of why their using this method is because of some of the operations their performing in JsonRpc2_0Rx. They seem to be very specific so that they can successfully communicate with the Geth node.

I agree with you, long should be used for many reasons. Perhaps it's worth asking the Web3j team on their gitter channel?

  • @dev ツ I've just notice that you already posted in their gitter. Let me know how it goes 👍 – Malone Nov 6 '17 at 19:00
  • 1
    Yes, I am waiting for a reply from any of the core team member. – Dev Nov 6 '17 at 19:27

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.