Skip to content
CCPEDIAby Unity Nodes
VideosWhat are Updates in DAML?

What are Updates in DAML?

Nothing is loaded from YouTube until you press play, and then without tracking cookies.

About this video

๐Ÿ“– Get started with Daml: bit.ly/tryDaml ๐Ÿ“š Learn more about Daml Smart Contracts: bit.ly/learn_daml ๐Ÿ“ฎCheck out our blogs: bit.ly/daml-blog-engineering ๐Ÿ“‹ Become a Daml certified expert: bit.ly/daml-certification

#Updates specify the transactions that will be committed to the ledger. Updates are described within a do block.

#DAML is an open-source smart contract language designed to build composable applications on an abstract ledger model.

DAML is a high level language that focuses on data privacy and authorization of distributed applications. These concepts are represented first class in the language.

By abstracting data privacy and authorization, DAML takes the burden off the programmer to think about concrete cryptographic primitives and lets her focus on workflow logic.

DAML is a statically typed functional language.

Applications specified in DAML can be deployed on a growing number of platforms including Amazon Aurora , VMWare Concord , R3 Corda , Hyperledger Fabric , Hyperledger Sawtooth , Project DABL and PostgreSQL .

We will show how to: do create exercise exerciseByKey fetch fetchBtKey lookupByKey abort assert getTime return let this forA

#distributedapplications #smartcontracts

Transcript

1,450 words

Captions as YouTube publishes them, usually machine-generated, so names such as Daml and Canton can be misheard.

  1. 0:00

    welcome to our next video I'm Anthony I have worked on the abdominal team as a developer advocate previously we were talking about what was supported talking about contract keys and how to find contracts by key and today we're actually going to be talking about updates and keys work into some of this so if you haven't seen that video go check it out but you don't necessarily need to watch it right this moment in

  2. 0:25

    order to understand this one so what are updates updates are basically any transaction that you're going to commit to the ledger so much the same way that you might make and update to a sequel database you can also make updates to Ledger's and a variety of different ways but that give you different types of guarantees at different types of data persistence than a regular sequel database play so the two major types of

  3. 0:51

    updates are create and exercise so create is when you're taking a contract template and you're actually making a contract out of it you're instantiating it so that's basically you would go ahead and you would call create and you would give it the name of the template and you would give it whatever parameters you need to in order to create it can I actually see a little example up here and then once your contract was created you would it would presumably have choices that you could

  4. 1:23

    exercise on it so that would basically be you know you want to take that contract and you want to exercise the choice on it so you would say exercise and you would give it the e contract ID of the contract assuming you had it and if you didn't have it I'll show you how another way you can find it and you can also and then you give it the name of the choice that you want exercised on

  5. 1:46

    the contract and whatever arguments that you need to provide to it and so sometimes though you know a contract exists but you don't actually have its contract ID depending on how your workflow is going you might just have a key to it that you know I want to reference this key and get the latest version of this contract which is a fairly common thing because you may not always be keeping track of every single

  6. 2:11

    update to a contract but then when you want to use a contract you'll still need a way to access it so the way you would do this is exercise by key an exercise by key is very similar to exercise in that you can go ahead and say hey I want to exercise my key and I'm going to give you the contract type and then the contract key and then the name of the choice that we're going to exercise so basically you're doing essentially the same thing you're doing

  7. 2:37

    here except rather than giving it the contract ID directly you are telling a the type of contract and you're also telling it the key on the contract that you want but you want to reference that specific instance of that type of contract so we actually have a lot of example here so here is an exercise by key and there is a type of contract called an equity option stock split rule and this is in one of our this is actually an hour look finance library if

  8. 3:08

    you want to go check it out so this is basically saying hey here's the type of the contract I want to exercise here's the key for it and you know I want to call I want to exercise this choice on the contract and with these options and so then that'll go ahead and I'll do it and it'll work much like a regular exercise does and then you have similar things here for fetch fetch basically is you want the actual contract itself and

  9. 3:40

    you know the contract ID so you go ahead and you say here's the contract ID give me the actual the actual contract itself that this way when you you can go ahead and call you can for example use you you can grab the contract with it and do a variety of things with it and then you also have fetched by key which works much the same way as exercised by key and then look up by key is similar in that you can go ahead and check whether

  10. 4:09

    or not a contract with a key exists and if it does then you'll get back the contract ID so fetch by key gets you the actual contract itself from a key lookup by key gets you the contract ID from a key so just keep that in mind when you're writing it sometimes it's a fairly common source of confusion where you'll right fetch Mikey when you look up by key or vice versa and then we have

  11. 4:33

    some very you know a fairly similar updates so you can abort a transaction with an error message if it's not going to be committed to a ledger so if you're going to you know encounter some some error case that you don't want that you want executions of stuff you can import you can also though what I more commonly do is I will assert that a predicate holes using assert this works like a cert and most other languages where you

  12. 4:59

    basically say you know this has and is true and if the statement is sign assert doesn't and this true then then we abort the transaction we fail we also have get time which can get to the ledger effective time so between heed the time from the ledger this is the function you would use for that time on distributive Ledger's is a little funky sometimes and it's something to keep in mind when you're working with distributed Ledger's but you can still get the time from the

  13. 5:30

    ledger it's just something that you probably want to go to dogsleds and welcome and read a little bit more about how time works on a ledger because it it's a bit beyond the scope of this this video and then you also have return which is basically whatever you're doing a do block so for example over here we have a do that's doing fetch by key and actually this one doesn't return but if

  14. 5:52

    we had some sort of value at the end that we want its propagate up to and be recorded somewhere or use somewhere we would return a value at the end and lastly we have two very useful useful pieces of syntax one is lek which basically allows you to define a local variable that's only going to exist inside of that do block so for example over here inside this new block we have let L my M and this these these

  15. 6:28

    declarations only exist inside the do block they're not going to end up anywhere else so this is basically how you scope things to certain sections just by prefixing them with what and lastly we have this and this is a helper function much like self we there's also a self in exam oh that's not discussed here but this essentially refers to the current contract data that's contained in a choice that you're exercising so let me

  16. 6:57

    actually see if there is this news okay but essentially if you were to for example over here inside of this this choice you would have you could use this and you could say you know this dot P or this that's five and that would give you the data that was stored here it would it would give you access to the parties here so basically you're able to refer to the contract data that's contained within the contract itself when your whatever you're doing a choice and this

  17. 7:34

    is a good example here where you can actually take your old contract and recreate it and reuse some of the data in it so for example here where do we're creating a contract through a choice and basically we're going to replace that the old contract with a new contract and we're going to say we're going to make the new contract but we're going to actually use the owner of the old contract and that's that's that's how this works it's very similar to to self and a lot of other languages like Python

  18. 8:07

    and yeah so thank you very much for watching and stay tuned for the next one