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

  • 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:


3. πŸͺ™ Currency Symbol and Token Name

These two identify Ada in a Value:

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

πŸ”— See in Haddock


4. πŸ—οΈ Creating and Extracting Ada

🧱 Construct Ada values

Function
Meaning

lovelaceOf 1000000

β†’ 1 Ada (raw integer)

adaOf (MkFixed 1)

β†’ 1 Ada (fixed-point)

πŸ” Extract amount


5. πŸ“¦ Working with Value

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

πŸ“€ To convert Ada β†’ Value:

πŸ“₯ To extract Ada ← Value:

πŸ§ͺ Value constructors

πŸ’‘ Tip:


6. βž— Arithmetic Operations on Ada

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

πŸ”Έ Divide two Ada values

πŸ”Ž Example:


7. πŸ§ͺ Utility Functions

❓ Is Ada value zero?

Examples:


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


Last updated