<p>Use <code>adaOf</code></p>
<p>In a GHCi session with <code>plutus-ledger-api</code> in scope:</p>
<pre><code>&gt; import Plutus.V1.Ledger.Ada
&gt; adaOf 1
Lovelace {getLovelace = 1000000}
</code></pre>

CC BY-SA 4.0
2021-08-22T20:04:14.653Z
Great! So that constant I found in Marlowe appears to be a mistake, because it is introducing a second source-of-truth.
Kwaggy
CC BY-SA 4.0
2021-08-22T13:35:01.883Z
2021-08-23T04:09:06.323Z
2021-08-23T04:09:06.323Z
Sebastian Nagel
<p><code>adaOf</code> encodes Lovelace/Ada ratio in <a href="https://github.com/input-output-hk/plutus/blob/12099239d5bae033c914387257cb8d2c268838b3/plutus-ledger-api/src/Plutus/V1/Ledger/Ada.hs#L100" rel="nofollow noreferrer">phantom type <code>Micro</code></a></p>
<pre><code>adaOf :: Micro -&gt; Ada
type Micro = Fixed E6
newtype Fixed (a :: k) = MkFixed Integer
</code></pre>
<p>Question: Being that the ratio is already encoded in the type, can I somehow get it, such that I can have a function that takes actual <code>Ada</code> token quantity -- not <code>Lovelace</code> quantity -- and gives back <code>Ada</code>, <strong>without</strong> hardcoding?</p>
<pre><code>f :: Integer -&gt; Ada
f adaQty = Lovelace (1_000_000 * n) -- don't really want to do this
</code></pre>
<p>I actually found <a href="https://github.com/input-output-hk/plutus/blob/cc953b36ec9681cc28edf1accf08f48a31238e69/marlowe-playground-server/contracts/Swap.hs#L15" rel="nofollow noreferrer">the constant</a> in the <code>plutus</code> repo:</p>
<pre><code>lovelacePerAda = Constant 1000000
</code></pre>

CC BY-SA 4.0
2021-08-18T21:49:37.313Z
That constant you found probably isn't the one to use, since it's in the Marlowe libraries. Why are you interested in denominating in major units in your Plutus code? I could see the need in your UI.
Mitchell Turner
<plutus><ada>
adaOf encodes Lovelace/Ada ratio in phantom type
# adaOf encodes Lovelace/Ada ratio in phantom type

(Asked by: username_0 on 2021-08-18)

adaOf encodes Lovelace/Ada ratio in phantom type Micro
adaOf :: Micro -> Ada
type Micro = Fixed E6
newtype Fixed (a :: k) = MkFixed Integer

Question: Being that the ratio is already encoded in the type, can I somehow get it, such that I can have a function that takes actual Ada token quantity -- not Lovelace quantity -- and gives back Ada, without hardcoding?
f :: Integer -> Ada
f adaQty = Lovelace (1_000_000 * n) -- don't really want to do this

I actually found the constant in the plutus repo:
lovelacePerAda = Constant 1000000

**Tags:** plutus, ada
> **Comments:**
> **username_1**: That constant you found probably isn't the one to use, since it's in the Marlowe libraries. Why are you interested in denominating in major units in your Plutus code? I could see the need in your UI.  

---

## 1 answers

### Answer by username_2 on 2021-08-22. Score: 4 | Accepted answer

Use adaOf
In a GHCi session with plutus-ledger-api in scope:
> import Plutus.V1.Ledger.Ada
> adaOf 1
Lovelace {getLovelace = 1000000}

> **Comments:**
> **username_0**: Great! So that constant I found in Marlowe appears to be a mistake, because it is introducing a second source-of-truth.  

---

