Daml 101: Meet Your Tools: Script, Sandbox, & Navigator [2021]
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,245 wordsCaptions as YouTube publishes them, usually machine-generated, so names such as Daml and Canton can be misheard.
- 0:00
hi this is steve cial from digital asset in this video we're going to go through three sdk tools that you should be aware of as you embark on your journey to learn demo development don't go anywhere your experience as a developer learning a new framework or programming language is as good as the tooling that's available to you for demo we've paid particular attention to making sure that you have a set of sdk tools that will help you be
- 0:33
successful in writing your demo code hi this is steve sia from digital asset in this video we're going to go through three sdk tools that you should be aware of as you embark on your journey to learn demo development the first tool is demo script demo script gives you a very simple way to test your code and get immediate feedback from inside of the demo studio which is the customized version of visual studio code for demo development
- 1:12
the script doesn't really interact with any ledger so no data is persistent think of it as a ledger simulator so the first thing i want to do is to fire up the terminal and check my demo version i've not used this mac for a while so i may be behind sure enough i have a 1.12 now you can go to our web page demo.com and go to documentation and see that what version we're running in this case we are at 1.16 at the time of recording so i'm gonna
- 1:43
have to upgrade it back in the terminal we can see what commands are available by doing demo help in this case we're looking for a demo install you wouldn't find a demo upgrade but if you were to go to demo install you will see a list of choices available to you and we really want the first one that says demo install latest so let's go ahead and run demo install latest and i'm going to speed up my frames four times but it's a fairly
- 2:15
quick download and install if i run demo version again i should have both sdks in there but the latest one will be default for the for new projects i'm going to create a new project now the command is demo new name of the project which i'm going to call my first demo app and notice that it has been created using a template called skeleton next i'm going to cd into my project folder which is something that people miss a lot and run demo studio
- 2:47
visual studio opens up and if you go into the demo folder you see a main.demo with pre-written code for you now first thing i want to pay attention to is the import statement the second thing to pay attention to is between lines 23 and 24 for this particular demo file and then the third piece is the from 23 to 38 which is the script that you would write to test your code click on the script results and you get an output on the right that shows you the transactions this is a table view so first we have a main which is the
- 3:20
module name followed by asset which is the template name and below below that you would see a table that has an id that identifies the transaction a status indicating that's an active contract and the fields that are involved in this particular template and then there are the parties involved and ex indicates who can see this particular contract click on show archive and you will see that it will show you a
- 3:52
history of transactions and now we see that the first two are archived because they have been overwritten by transaction number two which is the current active contract for this particular template remember there can only be one because the rest are archived click on the show transaction view button and you see a more detailed breakdown of this transaction so first we have tx transaction zero which is when alice created a new asset called tv so that is the first entry
- 4:25
the second transaction tx1 tells us that she exercised a choice called give which is her giving the tv to bob the new owner and that triggers a create command which created a new owner from alice to bob so that will be 1.1 so this demo script output really shows you a breakdown of transaction as you expect it according to your script to me demo script feels like a console output and a unit testing tool rolled into a ledger simulator is incredibly useful
- 5:04
so let's move to the next tool if you have done web development or consumed apis from services like twilio you would be familiar with the concept of a sandbox a sambox is a an isolated testing environment that you can use to quickly test your code or pieces of your code sandboxes are typically implemented locally on your computer or up in the cloud demo sandbox runs locally on your computer and allows you to quickly send up a ledger that can hold your data and
- 5:46
test your model but it is not persistent there are ways to persist data if you use postgres but we reserve that for another video let's take a closer look at the sandbox so for this i'm going to create a second demo project and i'm going to use a template called create demo app it's created let's cd into that directory and run demo studio which brings up vs code and surprise you see that you get a free ui that has been written for you in this
- 6:23
template we're gonna have to build it of course but let's uh go back to our terminal and do one more thing we're gonna build the particular demo file into a and compile it into a dar file by running demo build and once we have that we are good to go ahead and build that ui so let's cd into the ui and first let me check my npm version i've not used this macbook for a while so i'm gonna have to update my npm version so let me just
- 6:55
fast forward the screens here as i get the latest npm version let me run version again i should get version 3 7.23 that's great now i can go ahead and do a npm install inside of this ui directory so speeding up the frames for you to save time and it is done all right i can run npn start to fire up a local server to serve out that ui give it a couple of seconds and you should see a ui just like that and from this point you can type in any username there's no password required and you can start to
- 7:38
play with the ui that will then interact with the templates and create contracts but the more important part is that i want you to take a look at what happens behind the scenes now let's go back to the terminal where we started the demo start command or the sandbox identify where the big sandbox uh writing is and you will see right very close to the top a ledger id for the sandbox has been assigned for this project and it is running so back at the ui you can log in with
- 8:11
any name and you can start interacting with it and data will actually start to be inserted into that sandbox ledger so we're gonna have alice follow bob and then we can log out and then have bob login on his side and look at what's going on he sees that he's connected to alice great now let's look at how this looks like behind the scenes while the sandbox is running so i'm going to put these two screens side by side as you can tell they're already activity going on so let's put it
- 8:50
next to each other and i'm going to repeat what we just saw i'm going to log in as bob and once i'm in you see that their activity that has already been inserted into the ledger and if i were to follow alice back and click a follow exercise that choice and again data is logged into the sandbox ledger so having the sandbox available really allows you to quickly test your data model and your logic without standing up
- 9:20
a real ledger let's move on to the next tool writing the front end is not trivial don't let the back end people tell you otherwise in demo development sometimes it's good to focus on the demo backend the business logic the data model the architecture and while you're working on that it's good to have a ui that you can quickly test against to see that your contracts your templates are working as designed for that we give you demo navigator we're gonna go back to our first demo
- 10:03
app and run demo start and we'll see that something is a little different than the second project we see that we have a sam box automatically invoked here as well as a new thing called navigator that we have not seen before and when that is finished running you see a ui that automatically pops up now we have not seen this in the previous um second project why is that so let's take a closer look let's go into our second demo app
- 10:34
and fire up demo studio and this vs code should open right up if you go into the demo.yaml file you will see that there is one line that says start navigator uh false now that suppresses the navigator from firing and that's why we did not see in that second project in the first project it's not there so by default it is going to start the navigator so navigator comes for free unless you turn it off so back at the navigator
- 11:06
you will see that it will allow you to pick a row and by default you are going to see alice and bob so i can log into alice and let's expand this let's take a closer look here we see contracts and templates let's click on template and in this particular project we only have one template asset that makes sense now remember 13 d okay let's uh step back and go into one of the contracts this is the active
- 11:37
one but we can see all the archive one as well and let's dig into one of the contracts and let's look at the first one that was generated in the chain and you will see that it is generated from the 13d template correct so let's go into the active one and you see that again it's generated from the 13d template it makes sense because templates creates contracts but this contract ends with 4c0 is the active one if you go to the next the one
- 12:10
before that you see 807 so the ids are changing because that has been archived and a new one has been created so this is identical to what you see in the script output but where on earth this come from this should be a blank ledger right we just started the ledger and why is it why are there transactions already so if you look at a demo remember this part here that is the script
- 12:41
the script was executed along with the ledger as it was standing up because that was in your dar file and you see alice and bob that part is specified in your demo.yaml file right here where you see parties these this party uh field here is just for the navigator so we can add charlie you can add daisy you can add ethan and that means that the navigator will have these five pre-baked parties for you to log into
- 13:20
so now we can go to our navigator refresh it and we should see five names right wrong why is it only alice and bob where are the other three names that i added well remember that when you write your code you are writing the demo file and it compiles to a dar file right it says that i can just simply click r to rebuild the ledger let's do that let's click r and it's resetting the ledger compiling it to a dar and uh so that should work right we
- 13:51
should add those five names but oops big gnarly error here there is a problem if you scroll to the top uh the first few lines give it away it says that party already exists why is that now the party already exists because we already have alice and bob so let's um have let's restart the ledger by doing a fresh clean start and do a demo start now it recompiles to the dar file it just doesn't add to the ledger it
- 14:26
restarts the sandbox restarts the navigator and once that is loaded let's refresh it how cool is that i hope this video has given you a great overview of your three new best friends in demo development demo script demo sandbox and demo navigator i'll see you in the next episode ciao you