Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native Assets transaction Amount don't support decimal #389

Open
mackieq opened this issue Apr 22, 2024 · 1 comment
Open

Native Assets transaction Amount don't support decimal #389

mackieq opened this issue Apr 22, 2024 · 1 comment

Comments

@mackieq
Copy link

mackieq commented Apr 22, 2024

The Amount Object is:

public class Amount {

    private String unit;
    private BigInteger quantity;
}

When the transfer amount includes decimals, how should it be handled?

The Current Example code:


        PaymentTransaction paymentTransaction =
                PaymentTransaction.builder()
                        .sender(sender)
                        .receiver(receiver)
                        .amount(BigInteger.valueOf(3000))
                        .unit("57fca08abbaddee36da742a839f7d83a7e1d2419f1507fcbf3916522534245525259")
                        .build();
@satran004
Copy link
Member

@mackieq
Cardano Native tokens are represented as whole number (BigInteger in Java). So during transfer you can't use decimal.

You can also get the decimal info of an existing mainnet token from token registry and convert it to a whole number using that. Please check info about token registry here https://developers.cardano.org/docs/native-tokens/cardano-token-registry/

Btw, PaymentTransaction api is now deprecated.

Please look into "QuickTx" api which is quite simple and flexible.

Here are some examples of QuickTx api.

https://github.com/bloxbean/cardano-client-examples/blob/main/src/test/java/com/bloxbean/cardano/client/example/quicktx/SimplePayment.java

Blog post: https://satran004.medium.com/introducing-new-quicktx-api-in-cardano-client-lib-0-5-0-beta1-5beb491282ce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants