# Launch trigger

**URL:** <https://forum.canton.network/t/launch-trigger/4439>\
**Category:** App Development\
**Created:** [April 27, 2022, 3:05pm UTC](https://forum.canton.network/t/launch-trigger/4439 "2022-04-27T15:05:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidBelinchon](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@DavidBelinchon](https://forum.canton.network/u/DavidBelinchon)\
**Post date:** [April 27, 2022, 3:05pm UTC](https://forum.canton.network/t/launch-trigger/4439/1 "2022-04-27T15:05:32Z")

</div>

I have this trigger that acts when there is an event of the Distributions contract, the first thing I do is retrieve all of them and then filter the one with the triggered=false.

My question is, within subscribeRule there is some way to have the information of the contract that has caused the trigger to be launched, the contractId or the payload or something that can identify the contract that causes the trigger ?

```haskell
subscriber : Trigger ()

subscriber = Trigger

  { initialize = pure ()

  , updateState = \_ -> pure ()

  , rule = subscriberRule

  , registeredTemplates = RegisteredTemplates [registeredTemplate @Distributions]

  , heartbeat = None

  }

 

 

subscriberRule : Party -> TriggerA () ()

subscriberRule party = do

 

  distributions <- query @Distributions

  let newsDistSub = filter (\(_, s) -> (s.triggered == false)) distributions

  forA_ newsDistSub $ \(cid, distribution) -> do

    dedupExercise cid MarkTriggered

    pure()

  pure()

```

---

<div class="post-metadata">

**Author:** ![rikotacards](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@rikotacards](https://forum.canton.network/u/rikotacards)\
**Post date:** [April 27, 2022, 4:01pm UTC](https://forum.canton.network/t/launch-trigger/4439/2 "2022-04-27T16:01:16Z")

</div>

the line  
`distributions <- query @Distributions` should return a tuple `cid (contractID), contract`  
within the `forA_` loop, you can see `(cid,distribution)`, the `distribution` is the contract, with the data, so you can access the fields there, for example `distribution.issuer`, if issuer was a field there.

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [April 28, 2022, 8:22am UTC](https://forum.canton.network/t/launch-trigger/4439/3 "2022-04-28T08:22:02Z")

</div>

> [@DavidBelinchon](#):
>
> My question is, within subscribeRule there is some way to have the information of the **contract that has caused the trigger to be launched** , the contractId or the payload or something that can identify **the contract that causes the trigger**?

Hi @DavidBelinchon,

This is not the right way to think about triggers. Despite the name, they are not triggered by a specific contract event and designing them that way will lead to issues.

You should instead think of them as rules that enforce invariants on the ledger. What triggers the rule is incidental; what matters is that after the rule has run, the invariants have been enforced and hold for all data on the ledger.

If you want a specific choice to trigger a specific consequence, that consequence should simply be part of the choice’s body.

---

<div class="post-metadata">

**Author:** ![gyorgybalazsi](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gyorgybalazsi/32/684_2.png) [@gyorgybalazsi](https://forum.canton.network/u/gyorgybalazsi)\
**Post date:** [April 29, 2022, 9:24am UTC](https://forum.canton.network/t/launch-trigger/4439/4 "2022-04-29T09:24:38Z")

</div>

> [@Gary\_Verhaegen](#):
>
> You should instead think of them as rules that enforce invariants on the ledger.

I think this is a nice example of thinking in a declarative, rather than procedural way.
