Plutus: Ada
πΈ Plutus Tutorial: Working with Ada in Smart Contracts
Ada in Smart ContractsποΈ Table of Contents
π Introduction
π° What is
AdaandLovelaceπͺ Currency Symbol and Token Name
ποΈ Creating and Extracting
Adaπ¦ Working with
Valueβ Arithmetic Operations on
Adaπ§ͺ Utility Functions
π Glossary
π 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
AdanewtypeEasy constructors and extractors
Helpers for conversion and arithmetic
2. π° What is Ada and Lovelace
Ada and LovelaceAdais just a wrapped integer calledLovelace1 Ada = 1,000,000 Lovelace
β
Ada derives:
Eq,Ord,ShowNum,Real,IntegralFromData,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
Adaπ§± Construct Ada values
Ada valueslovelaceOf 1000000
β 1 Ada (raw integer)
adaOf (MkFixed 1)
β 1 Ada (fixed-point)
π Extract amount
5. π¦ Working with Value
ValuePlutus transactions use the Value type to represent tokens and Ada.
π€ To convert Ada β Value:
Ada β Value:π₯ To extract Ada β Value:
Ada β Value:π§ͺ Value constructors
π‘ Tip:
6. β Arithmetic Operations on Ada
AdaSince Ada derives Num, Semigroup, Monoid, etc., you can:
πΈ Divide two Ada values
Ada valuesπ Example:
7. π§ͺ Utility Functions
β Is Ada value zero?
Examples:
8. π Glossary
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