# Issue with MultiParty Contract

**URL:** <https://forum.canton.network/t/issue-with-multiparty-contract/4698>\
**Category:** App Development\
**Created:** [June 8, 2022, 5:21pm UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698 "2022-06-08T17:21:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Konscious7](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/konscious7/32/3974_2.png) [@Konscious7](https://forum.canton.network/u/Konscious7)\
**Post date:** [June 8, 2022, 5:21pm UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698/1 "2022-06-08T17:21:56Z")

</div>

Hello, I am new to Daml and building one of the design patterns in Daml and have been having trouble with one line and making parties. Can someone explain to me what I am doing wrong?

 ![Screen Shot 2022-06-08 at 13.20.19](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/0/0b95d91be8a8e8d4ea623b6485684137dd21ace6.png)

Here is the output when I run daml build or daml start

 ![Screen Shot 2022-06-08 at 13.21.44](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/e/e1f9b9cbd3a3489d56d9a59d960dbdf5ce4eaa9c.png)

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [June 8, 2022, 5:39pm UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698/2 "2022-06-08T17:39:55Z")

</div>

Can you share the full file, in particular the part above the line with the error?

---

<div class="post-metadata">

**Author:** ![Konscious7](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/konscious7/32/3974_2.png) [@Konscious7](https://forum.canton.network/u/Konscious7)\
**Post date:** [June 8, 2022, 8:16pm UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698/3 "2022-06-08T20:16:59Z")

</div>

Yeah sure, thanks for the quick response

 ![Screen Shot 2022-06-08 at 16.16.23](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/8/89bbf45a037a6e93268e4abafbc865a8af5a0b21.png)  
 ![Screen Shot 2022-06-08 at 16.16.45](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/b/b11a1b769320337074d4142263d707f3b231d0b0.png)

---

<div class="post-metadata">

**Author:** ![Stephen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/stephen/32/102_2.png) [@Stephen](https://forum.canton.network/u/Stephen)\
**Post date:** [June 8, 2022, 9:14pm UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698/4 "2022-06-08T21:14:40Z")

</div>

@Konscious7 I strongly recommend pasting the text, rather than posting screenshots. For example, it is still difficult to see from your screenshots whether there is a scoping error. You can enclose code blocks between ``` lines to ensure they are not wrapped by the forum software, [as explained here](https://discuss.daml.com/t/how-to-ask-questions/304).

---

<div class="post-metadata">

**Author:** ![Konscious7](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/konscious7/32/3974_2.png) [@Konscious7](https://forum.canton.network/u/Konscious7)\
**Post date:** [June 9, 2022, 12:39am UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698/5 "2022-06-09T00:39:18Z")

</div>

```nohighlight
import Daml.Script

template GovermentContract
  with
    signatories: [Party]
  where
    signatory signatories
    ensure
      unique signatories

template Pending
  with
    finalContract : GovermentContract
    alreadySigned: [Party]
  where
    signatory alreadySigned
    observer finalContract.signatories
    ensure
      -- Can't have duplicate signatories
      unique alreadySigned

    -- The parties who need to sign is the finalContract.signotories with alreadySigned filtered out
    let toSign = filter (`notElem` alreadySigned) finalContract.signatories

    choice Sign : ContractId Pending with 
        signer : Party
      controller signer
        do
          -- Check the controller is in the toSign list, and if theu are, sign the Pending contract
          assert (signer `elem` toSign)
          create this with alreadySigned = signer :: alreadySigned
    
    choice Finalize : ContractId GovermentContract with
        signer : Party
      controller signer
        do
          -- Check that all the required signotories have signed Pending
          sort alreadySigned == sort finalContract.signatories
          create finalContract 

    
parties@[person1, person2, person3, person4, person5, person6] <- makePartiesFrom ["harris", "tom", "lee", "martin", "lisa", "bob"]
let finalContract = GovermentContract with signatories = parties

-- Parties cannot create a contract already signed by someone else
initialFailTest <- person1 `submitMustFail` do 
  createCmd Pending with finalContract; alreadySigned = [person1, person2]

-- Any party can create a contract a pending contract provided they list themeselves as the only signatory
pending <- person1 `submit` do
  createCmd Pending with finalContract; alreadySigned = [person1]

-- Each signatory of the finalContract can Sign the Pending contract
pending <- person2 `submit` do
  exerciseCmd pending Sign with signer = person2

pending <- person3 `submit` do
  exerciseCmd pending Sign with signer = person3

pending <- person4 `submit` do
  exerciseCmd pending Sign with signer = person4

pending <- person5 `submit` do
  exerciseCmd pending Sign with signer = person5

pending <- person6 `submit` do
  exerciseCmd pending Sign with signer = person6

-- A party can't sign the Pending contract twice
pendingFailTest <- person3 `submitMustFail` do
  exerciseCmd pending Sign with signer = person3

-- A party can't sign on behalf of someone else
pendingFailTest <- person3 `submitMustFail` do 
  exerciseCmd pending Sign with signer = person4

person1 `submit` do 
  exerciseCmd pending Finalize with signer = person1

```

---

<div class="post-metadata">

**Author:** ![Konscious7](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/konscious7/32/3974_2.png) [@Konscious7](https://forum.canton.network/u/Konscious7)\
**Post date:** [June 9, 2022, 12:39am UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698/6 "2022-06-09T00:39:42Z")

</div>

Thanks for the advice!!

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [June 9, 2022, 4:23am UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698/7 "2022-06-09T04:23:37Z")

</div>

It looks like you put your script code at the top-level rather than within a single script definition. Take a look at the section on [daml script](https://docs.daml.com/daml/intro/2_DamlScript.html) in the daml intro for some examples of how to setup it up.

---

<div class="post-metadata">

**Author:** ![Konscious7](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/konscious7/32/3974_2.png) [@Konscious7](https://forum.canton.network/u/Konscious7)\
**Post date:** [June 10, 2022, 4:43pm UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698/8 "2022-06-10T16:43:51Z")

</div>

So I went through and added the `fail_test = script do parties@[person1, person2, person3, person4, person5, person6] <- makePartiesFrom["harris", "tom", "lee", "martin", "lisa", "bob"] let finalContract = GovermentContract with signatories = parties`. It don’t fix the issue but gave me more errors on the unique signatories saying they were not in scope. What determines the scope?

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [June 10, 2022, 5:21pm UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698/9 "2022-06-10T17:21:40Z")

</div>

Can you share the full code you’re using now and the error message you’re receiving?

---

<div class="post-metadata">

**Author:** ![Konscious7](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/konscious7/32/3974_2.png) [@Konscious7](https://forum.canton.network/u/Konscious7)\
**Post date:** [June 14, 2022, 6:48pm UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698/10 "2022-06-14T18:48:45Z")

</div>

```haskell
module Main where
import Daml.Script

template GovermentContract
  with
    signatories: [Party]
  where
    signatory signatories
    ensure
      unique signatories

template Pending
  with
    finalContract: GovermentContract
    alreadySigned: [Party]
  where
    signatory alreadySigned
    observer finalContract.signatories
    ensure
      -- Can't have duplicate signatories
      unique alreadySigned

    -- The parties who need to sign is the finalContract.signotories with alreadySigned filtered out
    let toSign = filter (`notElem` alreadySigned) finalContract.signatories

    choice Sign : ContractId Pending with 
        signer : Party
      controller signer
        do
          -- Check the controller is in the toSign list, and if theu are, sign the Pending contract
          assert (signer `elem` toSign)
          create this with alreadySigned = signer :: alreadySigned
    
    choice Finalize : ContractId GovermentContract with
        signer : Party
      controller signer
        do
          -- Check that all the required signotories have signed Pending
          assert (sort alreadySigned == sort finalContract.signatories)
          create finalContract 
          
fail_test = script do
  parties@[person1, person2, person3, person4, person5, person6] <- makePartiesFrom ["Tom", "Lee", "Mike", "Ted", "Luke", "EJ"]
  let finalContract = GovermentContract with signatories = parties

  -- Parties cannot create a contract already signed by someone else
  initialFailTest <- person1 `submitMustFail` do 
    createCmd Pending with finalContract; alreadySigned = [person1, person2]

  -- Any party can create a contract a pending contract provided they list themeselves as the only signatory
  pending <- person1 `submit` do
    createCmd Pending with finalContract; alreadySigned = [person1]

  -- Each signatory of the finalContract can Sign the Pending contract
  pending <- person2 `submit` do
    exerciseCmd pending Sign with signer = person2

  pending <- person3 `submit` do
    exerciseCmd pending Sign with signer = person3

  pending <- person4 `submit` do
    exerciseCmd pending Sign with signer = person4

  pending <- person5 `submit` do
    exerciseCmd pending Sign with signer = person5

  pending <- person6 `submit` do
    exerciseCmd pending Sign with signer = person6

  -- A party can't sign the Pending contract twice
  pendingFailTest <- person3 `submitMustFail` do
    exerciseCmd pending Sign with signer = person3

  -- A party can't sign on behalf of someone else
  pendingFailTest <- person3 `submitMustFail` do 
    exerciseCmd pending Sign with signer = person4

  person1 `submit` do 
    exerciseCmd pending Finalize with signer = person1

```

ERROR MESSAGE:

```haskell
File: daml/Main.daml
Hidden: no
Range: 10:7-10:13
Source: typecheck
Severity: DsError
Message: daml/Main.daml:10:7: error:Variable not in scope: unique : [Party] -> Bool
File: daml/Main.daml
Hidden: no
Range: 21:7-21:13
Source: typecheck
Severity: DsError
Message: daml/Main.daml:21:7: error:Variable not in scope: unique : [Party] -> Bool
File: daml/Main.daml
Hidden: no
Range: 39:19-39:23
Source: typecheck
Severity: DsError
Message: daml/Main.daml:39:19: error:Variable not in scope: sort : [Party] -> a0
File: daml/Main.daml
Hidden: no
Range: 39:41-39:45
Source: typecheck
Severity: DsError
Message: daml/Main.daml:39:41: error:Variable not in scope: sort : [Party] -> a0
File: daml/Main.daml
Hidden: no
Range: 43:69-43:84
Source: typecheck
Severity: DsError
Message: 
  daml/Main.daml:43:69: error:
  Variable not in scope: makePartiesFrom : [Text] -> Script [Party]
damlc: Error when running Shake build system:
BadDependency "GenerateDalf"

```

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [June 14, 2022, 7:00pm UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698/11 "2022-06-14T19:00:01Z")

</div>

You have two issues here:

1. First, you are missing an import to use `unique` and `sort`. To fix that add the following after the `import Daml.Script` line:

```haskell
import DA.List (sort, unique)

```

1. Second, you are missing the definition of `makePartiesFrom`. I assume your code is copied from the Daml patterns so you probably want the definition used [there](https://github.com/digital-asset/daml/blob/9c5c72a2fdcab2a93708fc3120209d93e2593cec/docs/source/daml/patterns/daml/Utilities.daml#L9). Inlined here:

```haskell
makePartiesFrom names =
  mapA allocateParty names

```

Just add that somewhere to your file after the imports.

---

<div class="post-metadata">

**Author:** ![Konscious7](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/konscious7/32/3974_2.png) [@Konscious7](https://forum.canton.network/u/Konscious7)\
**Post date:** [June 14, 2022, 7:20pm UTC](https://forum.canton.network/t/issue-with-multiparty-contract/4698/12 "2022-06-14T19:20:46Z")

</div>

> [@cocreature](#):
>
> ```haskell
> makePartiesFrom names =
> mapA allocateParty names
> 
> ```

You are a blessing, appreciate it !!
