Skip to content

Add bigint support to microalgosToAlgos() and algosToMicroalgos() #907

@No-Cash-7970

Description

@No-Cash-7970

Problem

The Algod and Indexer clients now use bigint for microAlgo amounts in v3. However, the microalgosToAlgos() and algosToMicroalgos() only support numbers.

Solution

Workaround No. 1

SDK users can workaround this issue for now by converting a bigint microAlgo value to a number before using microalgosToAlgos() or algosToMicroalgos(), but this can result in a loss of precision for large Algo values.

Workaround No. 2

Do not use microalgosToAlgos() or algosToMicroalgos() and do the conversion calculations manually with bigints.

Solution for microalgosToAlgos()

Accept either a bigint or number argument. Return a number (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 a bigint argument like proposed solution for microalgosToAlgos(). Return a bigint, 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 is false by default. When returnBigInt is true, a bigint is returned, otherwise a number 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 reflect microalgosToAlgos() being able to accept integers larger than 2^53 - 1.

Urgency

Medium.

Web and mobile apps use microalgosToAlgos() and algosToMicroalgos() 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 for algosToMicroalgos()" are the best options. I can create a pull request for implementing those solutions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions