Daml 101: Understanding Daml with... the Lion King? [2022]
Nothing is loaded from YouTube until you press play, and then without tracking cookies.
About this video
📚Check out Daml Learning Center: bit.ly/LearnDaml 📖Join our forum and get started: bit.ly/tryDaml
This is a multi episode series intended to take you from the brief context behind blockchain and smart contract to the development of smart contracts using a next-gen smart contract language called Daml. The entire series can be found here: bit.ly/damlone
Daml is a development framework for creating systems of record that securely connect across business processes and data boundaries while retaining privacy, guaranteeing data integrity, and enforcing strict authorization. Allowing such systems to cross boundaries — legal, regulatory, organizational, or other — enables them to form seamless economic networks.
Transcript
2,089 wordsCaptions as YouTube publishes them, usually machine-generated, so names such as Daml and Canton can be misheard.
- 0:00
one of the fastest way to learn a new technology or a platform or a device is to reverse engineer it to do it all the time in research labs at roswell so in this video we're going to do exactly that we're gonna take a demo template and break it into pieces and see how everything fits together so in this video we're gonna take a demo template and break it into pieces and see how everything fits together
- 0:31
and we'll do one better we will re-engineer it using one of the most iconic stories in our lifetime no not a notebook the lion king wait oh it's a leopard hi this is steve sale from digital asset in previous episodes we see that we could use templates to create projects very quickly so in the first half of this video we're going gonna use a template called skeleton and reverse engineer it to see how it looks like and how pieces fit
- 1:16
together in the second half of the video we're gonna use the lion king as an example and re-engineer that template and it will all make sense stay tuned don't go anywhere all right let's jump right in i'm going to start a new demo project and i'm going to use the default skeleton template by not specifying any template name so we'll use a skeleton by default now let's cd into our folder and then run demo studio which opens up vs
- 1:48
code now inside of vs code let's open up the demo folder and open up main.daml and let's dive deeper into what we see here let's save some space here and let's zoom in the first thing you see at the top of your demo file is the module this defines the entire module and it's important because you may need to import this module by this name main line three you see an import statement
- 2:20
that brings in a demo script we covered the script in previous videos line 5 defines a type that's going to be the output when we call the choices below and this is the asset template and the contract that it will produce so we'll go into that in a second starting at line seven you see template followed by a name called asset now there could be more than one template uh inside of a module in this case this module is this template is called asset
- 2:51
and it has input parameters of issuer owner and name now if we move down to line 13 you're gonna see one line to make sure that the name is not empty we'll go into that in future videos but line 14 is important signatory is the party that can authorize the creation while controller is the party that can take action in this case the owner can exercise a choice called give and this give will produce
- 3:23
a type call asset id which we define the top so essentially this is telling me that this contract when created will have an owner specified and this owner can take the action of giving it to a new owner and then that new owner can give it to the next owner and what happens when this choice is exercised it will trigger the create command now what is this this if you roll over it gives you a clue now this is scoped to the template so
- 3:56
this refers to the asset so when this is exercised it will create the another asset contract based off the asset template the second half of the demo file you'll find the script that will help us test our code lines 25 and 26 create two parties for us to play with alice and bob lines 28 alice creates an asset as a start in this case it's a tv in lines 34 alice is gonna give the tv to bob so bob
- 4:33
is the new owner and then lines 37 38 is another line of execution and it states that bob gives the tv back to alice now if you pay careful attention uh you'll see that lines 34 and 37 are nearly the same except for that in 34 it returns the results to a bob tv now if i were to open up the script output and go to show transaction view there are no errors reported at the top so i know we're doing things correctly now what's going on is this the lines 34 has a return value and then line 37 does
- 5:15
not if i were to force line 37 to be to return a value let's say alice tv again you will see on the right side that is an error now what's going on is this the last line 37 is actually returning the type specified at the top where it says script asset id so if i remove that it will automatically return this asset id so we don't have to make it return a type awesome now let's take the skeleton template and put the lion king story on
- 5:47
top of it to re-engineer it so we'll see how things fit together even clearer and if you have not seen the lion king spoiler alert okay the plot of the lion king involves how a lion king mustafa was preparing to hand over his kingdom to his boy simba of course there's a bad uncle who gets into the mix i think his name was scar or scarface and he got mustafa killed and now simba has to fight to get the kingdom back now there's one scene in the
- 6:21
beginning where simba woke up the father and said hey you promised to bring me to go watch the uh the sunrise so they go up to this cliff and the father while overlooking the vast expanse of land and said everything that the light touches is my kingdom um and and uh the boy goes awesome and and mustafa say one day all this will be yours except for that patch that's dark so this is like a smart contract you would expect simba in when he has his offspring to do the same to his offspring and bring them to
- 6:58
the cliff and say that one day all this will be yours so the smart contract remains the same the the king hands over to the successor and and then his successor will hand off to the successor so let's take a look at this template now but let's change some of the names and it will all click so we're going to imagine that musafa and the sun simba has a smart contract going on and here's this main demo again we're going to change a few things we're not
- 7:30
dealing with asset anymore we're moving kingdoms well we're moving ownership of kingdoms from one lion to another so let's call our asset kingdom and we will make the id kingdom id instead of asset id and anywhere where we have a occurrence of an asset id we're going to change it to kingdom id still the same thing we're not dealing with tvs we are dealing with everything that the light touches so all right template let's change it to kingdom as well
- 8:03
next let's take care of the uh input parameters in this case the issuer we'll start with the issuer wait a minute lines 29 uh let's change that to kingdom because we will be creating uh the kingdom contract okay let's go back to the issuer in this case the issuer is the current king whoever the king is who is going to pass on to the next king so current king will be what used to be issuer so now we'll say that the
- 8:35
signatory must be the current king the current king can authorize a transfer of kingdom so let's change it all in the script accordingly that's all we've got now let's go back now the owner in this case is who will receive the kingdom we will call it the future king the future king will uh be mentioned when a new kingdom is um created in this case uh over here we'll change that and the when the contract is created the future king will have the right to give
- 9:12
it to the next king the next future king the successor so we change that now for the name let's change that to kingdom name instead of just name so we are describing the asset right we're describing what is being transferred from one party to another in this case we will just call that party the successor who is the successor that will receive the new kingdom so let's change that make it let me just do a quick copy change that in our line
- 9:52
35 and change it in line 37 where we state a new successor now for the name let's go ahead and change the kingdom name to what mustafa said it was it's going to be what was it everything that the light touches right so that's a lot okay that's good enough now going back we want to ensure that a name is described so it cannot be empty and then the future king will be the input parameter
- 10:24
of successor in this case at the bottom you see that the successor was bob and the successor was alice in lines 35 and 38. but we don't want alice alice is not in this story so we're going to call it musafa oops musa if i can spell omu fasa and we're going to change that to mufasa over here and again in the party hint and then there's only two characters that we're dealing with the second character is not bob it's going to be
- 11:08
simba so let's change that to simba and one more time in the hint it will be simba now lines 28 will deal with the creation of well in this case we're going to pretend that the kingdom was created for a start so it has to be created so we're going to have mu fasa create the kingdom and give himself the the throne okay and lines 34 we are going to say that he has decided to give it to simba so let's change that to now when it's executed it's going to be
- 11:55
simba's kingdom it won't be mufasa's kingdom anymore so simba's kingdom will be the end result of this being exercised because he was named a successor now let's suppose that simba changes his mind because he watched the trailer of the lion king and go oh no i i don't want all that i'm going to give it back to you dad so simba will exit will exercise the give choice again and gives it right
- 12:28
back to his dad there you go and i believe we are done if i can spell there you go so what we have here is almost like the skeleton template and the story goes that mufasa created a kingdom and gave himself the throne so he is the current king and the future king who can act on it and he decided to act on it he decided to give it to simba and simba accept the contract and then decided to give it back to his dad now if we were
- 13:00
to look at the script output you see that it's clean there's no errors click on transaction view and you see a story being told of our version of the lion king the only mistake i made is that i think simba is not getting any kingdom i think he's getting alice's otv but you get the point so this this transfer of ownership really highlight the flow that the skeleton template is doing wasn't that a fun way to look at a smart contract
- 13:38
now your demo app will look very different and it will largely depend on your business logic your data model your architecture so before you write the first line of code you probably want to think through that who are the parties involved in the creation of contracts what are the rights and obligations of each of them and then finally the choices that can be exercised and what happens when they are exercised
- 14:04
i got more for you stay tuned for the next few episodes bye you