Default data return format for 4x rewrite #5120
Replies: 5 comments 1 reply
-
Since we plan to add the beacon api which contains values that overflow, number is probably not a viable option. |
Beta Was this translation helpful? Give feedback.
-
BigInt is preferred for all Truffle projects! There is a decimal type now though, so I'm not sure what to do about that. |
Beta Was this translation helpful? Give feedback.
-
Just coming in from the talk @nazarhussain just gave at ETH Prague 2022. I would suggest using |
Beta Was this translation helpful? Give feedback.
-
As discussed in web3.js team meeting, and also from feedback in this github discussion using BigInt as default return type for number type values in web3 is more good as there are no overflow errors, and no casting will be required ( in case we use hex extra step of casting is required). It will be breaking change but moving forward with it will be more convenient to use. |
Beta Was this translation helpful? Give feedback.
-
Marking the discussion as resolved: Consensus around this is to use BigInt as default return type. |
Beta Was this translation helpful? Give feedback.
-
Hi all,
Problem
In Web3.js 1.x releases we are using different data formats for number types data in the different API functions. e.g.
web3.eth.getBalance
returns number asstring
. Where asweb3.eth.getTransactionCount
returns the number asnumber
. So there are different expectations from users when they are expectingnumbers
data type.Solution
In 4.x rewrite we make it possible for users to get arbitrary data in different formats. For the data types which do have different structs and primitives available in Javascript. Currently we support following data types and their formats:
Bytes
Numbers
Use can define these formats to specify what format of data they need.
Choices
We are here we are looking for default return formats for the library. We decided hex string for the bytes data, as it's the native format for the Ethereum and compatible with the 1.x.
For numbers data we need to decide which format we should make the default. Each have different prose and cons.
2. Compatible with arithmetic
3. Higher adoption
2. No overflow error
2. No overflow error
2. Arithmetic can lead to mis behaviour and can't be detected
2. Compatible with arithmetic
3. Higher adoption
4. No overflow error
2. No IE support
Looking forward to your get your thoughts on what format should be default for the number data type in 4.x release.
Beta Was this translation helpful? Give feedback.
All reactions