marlowe-ts-sdk icon indicating copy to clipboard operation
marlowe-ts-sdk copied to clipboard

Helper function to parseADA to Lovelace

Open nhenin opened this issue 1 year ago • 1 comments

Discussed in https://github.com/input-output-hk/marlowe-ts-sdk/discussions/143

Originally posted by nstanford5 December 21, 2023 Most DApps will present users with the ability to input token amounts to a UI component. Users typically think in terms of ADA amounts, but we need to send Lovelace amounts to the blockchain.

Should the SDK include a simple helper function to parseADA to Lovelace?

Something like..

const parseADA = (num: number) => { return num * 1000000; };

On the other side of that, when querying the blockchain for amounts -- it will return Lovelace that needs to be formatted to ADA to present to users.

Should we also include a formatLovelace function?

nhenin avatar Jan 10 '24 10:01 nhenin

As I responded in the discussion, I believe this should be part of a bigger thing that we can call TemplateParameters/ContractScheme/etc that is similar to the Marlowe Extended feature.

This could allow us to define a DSL for contract parameters with assertions (amount > x, deadline 1 > deadline 2, etc), with a human description (that can help us with Marlowe to english explainer) and with a proper serialization mechanism so we can simplify this type of code.

The proposed function parseADA is misleading as it is not parsing anything, it could be called lovelaceToAda, but multiplying a number for 1 Million is trivial and does not belong in the SDK IMO.

hrajchert avatar Jan 11 '24 14:01 hrajchert