Add bigint support to microalgosToAlgos()
and algosToMicroalgos()
#907
Labels
new-feature-request
Feature request that needs triage
Problem
The Algod and Indexer clients now use
bigint
for microAlgo amounts in v3. However, themicroalgosToAlgos()
andalgosToMicroalgos()
only supportnumber
s.Solution
Workaround No. 1
SDK users can workaround this issue for now by converting a
bigint
microAlgo value to anumber
before usingmicroalgosToAlgos()
oralgosToMicroalgos()
, but this can result in a loss of precision for large Algo values.Workaround No. 2
Do not use
microalgosToAlgos()
oralgosToMicroalgos()
and do the conversion calculations manually withbigint
s.Solution for
microalgosToAlgos()
Accept either a
bigint
ornumber
argument. Return anumber
(like before). This solution is backwards compatible and would not require SDK users to change their existing code.Solution No. 1 for
algosToMicroalgos()
Can continue to accept only a
number
argument, but I think it would be good for consistency to also allow abigint
argument like proposed solution formicroalgosToAlgos()
. Return abigint
, which may be another breaking change.Solution No. 2 for
algosToMicroalgos()
Accept the same argument types as Solution No. 1, but have an optional
returnBigInt
boolean argument that isfalse
by default. WhenreturnBigInt
istrue
, abigint
is returned, otherwise anumber
is returned (like before). This would keep backwards compatibility, but is slightly more work to implement and maintain.Dependencies
The
INVALID_MICROALGOS_ERROR_MSG
constant will need to be updated to reflectmicroalgosToAlgos()
being able to accept integers larger than 2^53 - 1.Urgency
Medium.
Web and mobile apps use
microalgosToAlgos()
andalgosToMicroalgos()
frequently to display Algo amounts and to receive an Algo amount from the user respectively.Misc.
I think "Solution for
microalgosToAlgos()
" and "Solution No. 2 foralgosToMicroalgos()
" are the best options. I can create a pull request for implementing those solutions.The text was updated successfully, but these errors were encountered: