> For the complete documentation index, see [llms.txt](https://haskell-plutus.gitbook.io/coxygen-global/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://haskell-plutus.gitbook.io/coxygen-global/plutus-ada.md).

# Plutus: Ada

## 💸 Plutus Tutorial: Working with `Ada` in Smart Contracts

***

### 🗂️ Table of Contents

1. 🔍 Introduction
2. 💰 What is `Ada` and `Lovelace`
3. 🪙 Currency Symbol and Token Name
4. 🏗️ Creating and Extracting `Ada`
5. 📦 Working with `Value`
6. ➗ Arithmetic Operations on `Ada`
7. 🧪 Utility Functions
8. 📚 Glossary
9. 🔗 References

***

### 1. 🔍 Introduction

Plutus contracts often need to handle ADA — the native currency of Cardano. This module simplifies how you represent, create, and manipulate `Ada` values and convert them to/from `Value`.

The module gives you:

* Strong type safety via the `Ada` newtype
* Easy constructors and extractors
* Helpers for conversion and arithmetic

***

### 2. 💰 What is `Ada` and `Lovelace`

```haskell
newtype Ada = Lovelace { getLovelace :: Integer }
```

* `Ada` is just a wrapped integer called `Lovelace`
* `1 Ada = 1,000,000 Lovelace`

✅ `Ada` derives:

* `Eq`, `Ord`, `Show`
* `Num`, `Real`, `Integral`
* `FromData`, `ToData`, etc.

🧠 Example:

```haskell
Lovelace 1000000  -- 1 Ada
```

***

### 3. 🪙 Currency Symbol and Token Name

These two identify Ada in a `Value`:

```haskell
adaSymbol :: CurrencySymbol  -- ""
adaToken  :: TokenName       -- ""
```

They're both empty, because **Ada is the default native currency**.

🔗 [See in Haddock](https://intersectmbo.github.io/plutus-apps/main/plutus-ledger-api/html/Plutus-V1-Ledger-Value.html)

***

### 4. 🏗️ Creating and Extracting `Ada`

#### 🧱 Construct `Ada` values

```haskell
lovelaceOf :: Integer -> Ada
adaOf      :: Micro   -> Ada
```

| Function             | Meaning               |
| -------------------- | --------------------- |
| `lovelaceOf 1000000` | → 1 Ada (raw integer) |
| `adaOf (MkFixed 1)`  | → 1 Ada (fixed-point) |

#### 🔍 Extract amount

```haskell
getAda :: Ada -> Micro
```

***

### 5. 📦 Working with `Value`

Plutus transactions use the `Value` type to represent tokens and Ada.

#### 📤 To convert `Ada → Value`:

```haskell
toValue :: Ada -> Value
```

#### 📥 To extract `Ada ← Value`:

```haskell
fromValue :: Value -> Ada
```

#### 🧪 Value constructors

```haskell
lovelaceValueOf :: Integer -> Value
adaValueOf      :: Micro   -> Value
```

💡 Tip:

```haskell
lovelaceValueOf == toValue . lovelaceOf
adaValueOf      == toValue . adaOf
```

***

### 6. ➗ Arithmetic Operations on `Ada`

Since `Ada` derives `Num`, `Semigroup`, `Monoid`, etc., you can:

```haskell
a + b
a - b
a * 2
```

#### 🔸 Divide two `Ada` values

```haskell
divide :: Ada -> Ada -> Ada
divide (Lovelace a) (Lovelace b) = Lovelace (P.divide a b)
```

🔎 Example:

```haskell
divide (Lovelace 5000000) (Lovelace 1000000) == Lovelace 5
```

***

### 7. 🧪 Utility Functions

#### ❓ Is Ada value zero?

```haskell
isZero :: Ada -> Bool
```

Examples:

```haskell
isZero (Lovelace 0)      -- ✅ True
isZero (Lovelace 100000) -- ❌ False
```

***

### 8. 📚 Glossary

| Term             | Definition                                        |
| ---------------- | ------------------------------------------------- |
| `Ada`            | Native Cardano currency type                      |
| `Lovelace`       | Smallest unit of Ada (1 Ada = 1,000,000 Lovelace) |
| `CurrencySymbol` | Empty for Ada, identifies custom currencies       |
| `TokenName`      | Empty for Ada, identifies specific tokens         |
| `Value`          | Multi-asset value container in Plutus             |
| `Micro`          | Fixed-point decimal used for precise Ada amounts  |
| `MkFixed`        | Constructor for `Micro`, wraps an Integer         |
| `getLovelace`    | Access raw integer from `Ada`                     |

***

### 9. 🔗 References

* [📄 Plutus.Script.Utils.Ada (source)](https://github.com/IntersectMBO/plutus-apps/blob/main/plutus-script-utils/src/Plutus/Script/Utils/Ada.hs)
* [📄 `Value` API - Plutus.V1.Ledger.Value](https://intersectmbo.github.io/plutus-apps/main/plutus-ledger-api/html/Plutus-V1-Ledger-Value.html)
* [📄 `Fixed` from Data.Fixed](https://hackage.haskell.org/package/base/docs/Data-Fixed.html)

***
