Skip to content

Instantly share code, notes, and snippets.

@gyorgybalazsi
Created August 29, 2022 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyorgybalazsi/1fab3792f9fb1bcaac2f04faa781c36f to your computer and use it in GitHub Desktop.
Save gyorgybalazsi/1fab3792f9fb1bcaac2f04faa781c36f to your computer and use it in GitHub Desktop.
Asset contract and setup script
module Main where
import Daml.Script
type AssetId = ContractId Asset
template Asset
with
issuer : Party
owner : Party
name : Text
where
ensure name /= ""
signatory issuer
observer owner
choice Give : AssetId
with
newOwner : Party
controller owner
do create this with
owner = newOwner
setup : Script AssetId
setup = script do
-- user_setup_begin
alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice")
bob <- allocatePartyWithHint "Bob" (PartyIdHint "Bob")
aliceId <- validateUserId "alice"
bobId <- validateUserId "bob"
createUser (User aliceId (Some alice)) [CanActAs alice]
createUser (User bobId (Some bob)) [CanActAs bob]
-- user_setup_end
aliceTV <- submit alice do
createCmd Asset with
issuer = alice
owner = alice
name = "TV"
submit alice do
exerciseCmd aliceTV Give with newOwner = bob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment