marlowe-ts-sdk
marlowe-ts-sdk copied to clipboard
Helper function to parseADA to Lovelace
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?
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.