title | author | patat | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
M01 - Plutus Emulator |
Walker Leite |
|
In this module we will introduce you to Cardano EUTxO, Nix and we'll play in Plutus Emulator.
To run this presentation type (you will need nix):
../../slide README.md
- LovelaceAcademy Discord
- StackExchange (:bulb: use the tag lovelace-academy)
- Plutonomicon Discord
- A programming language
- Although not essential, being familiar with a language will be beneficial in understanding the in-depth content of this course;
- Knowing JavaScript and HTML will be beneficial;
- Functional programming paradigm
- Although not essential, it will help in the understanding of the in-depth content of this course;
Web developers aiming to build DApps on Cardano.
Build your own javascript-backed DAapp using Plutus and CTL
- The package manager
nix-env
- The registry
nixpkgs
- The language
default.nix
- The OS
NixOS
let thing = "world"; in ''
Hello ${thing}!
This should be 2 spaces away.
''
let amount = 1000;
type = { name = "cake"; };
flavor = rec {
name = "lemon";
related = [ name "pistachio" ];
};
product = {
type = type.name;
flavor = flavor;
image = ./lemon-cake.jpg;
price = 14.99;
};
in [
product.flavor.name
product.image
product.price
amount
product.flavor.related
]
let
attr = { tires = 4; fuel = 100; };
car = { inherit attr; brand = "ferrari"; };
grid = { driver = { name = "alonso"; pos = 3; }; };
in {
inherit car;
inherit (grid) driver;
stops = with attr; [
{ inherit fuel; }
{ inherit fuel; inherit tires; }
];
}
/*
disqualified.nix
builtins is global
*/
driver: builtins.length driver.penalties > 0
let ended = total-laps: race: race.lap >= total-laps;
race-ended = ended 50;
# import is also global
disqualified = import ./disqualified.nix;
wins = race: driver: race-ended race
&& !disqualified driver
&& driver.pos == 1;
race = { lap = 50; };
in [
(wins race { pos = 1; penalties = []; })
(wins race { pos = 2; penalties = [ "false start"]; })
(wins race { pos = 3; penalties = []; })
]
Is the result (side-effect) of calling a function that takes a set of attributes, including but not limited to:
- system string (like "x86_64-linux")
- the name string
- builder derivation or path
💡 Every attribute is passed as environment variables to the builder, if a derivation attribute is passed, it will be evaluated (aka built) before being passed.
The builder is executed in a given environment where $out
is set to the path of that derivation.
#!/bin/sh
# build-cowsay.sh
echo "moo..." >> $out
# cowsay.nix
builtins.derivation {
system = "x86_64-linux";
name = "cowsay";
builder = ./build-cowsay.sh;
}
nix-build ./cowsay.nix
cat result
Run the default smart contract in the emulator
Bonus: Run also docs
git clone https://github.com/input-output-hk/plutus-apps.git
git checkout 6b8bd0d80115ed5379ada31eea9e4e50db31f126