<p>The line of interest is:</p>
<pre><code>pp &lt;- endpoint @&quot;pay&quot;
</code></pre>
<p>Which is essentially blocking until someone hits the <code>&quot;pay&quot;</code> endpoint and then returning whatever <code>PayParams</code> the caller included (see <code>PaySchema</code>).</p>
<p>In the case where you include the recursive <code>payContract</code> function call, you are essentially saying, &quot;after running <code>payContract</code>, wait for someone else to hit the <code>&quot;pay&quot;</code> endpoint.&quot;</p>
<p>In the case that the recursive <code>payContract</code> function call is removed, the <code>Contract</code> monad will exit, since it isn't blocked on any endpoints or anything.</p>
<p>Hope that helps :)</p>

CC BY-SA 4.0
2021-10-08T16:36:07.563Z
2021-10-08T16:36:07.563Z
Mitchell Turner
<p>I'm working through the week 4 homework for the Plutus Pioneer program. I've found an answer to the homework problem and now I'm trying to get a deeper understanding of the code. I've noticed that the <code>payContract</code> <a href="https://github.com/paymog/plutus-pioneer-program/blob/8471f77119f7815ba9103384a7dd8b9ef0188f91/code/week04/src/Week04/Solution.hs#L33" rel="nofollow noreferrer">returns itself</a> (I'm still learning Haskell so that terminology might not be correct).</p>
<p>I find that if I comment out this line of code, then the <a href="https://github.com/paymog/plutus-pioneer-program/blob/8471f77119f7815ba9103384a7dd8b9ef0188f91/code/week04/src/Week04/Solution.hs#L44" rel="nofollow noreferrer">second invocation of <code>callEndpoint</code></a> doesn't do anything. I also notice that the logs of <code>payTest1</code> say <code>Contract Stopped</code>:</p>
<pre><code>Prelude Week04.Solution&gt; payTest1
Slot 00000: TxnValidate 0636250aef275497b4f3807d661a299e34e53e5ad3bc1110e43d1f3420bc8fae
Slot 00000: SlotAdd Slot 1
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 1}:
  Contract instance started
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 1}:
  Receive endpoint call on 'pay' for Object (fromList [(&quot;contents&quot;,Array [Object (fromList [(&quot;getEndpointDescription&quot;,String &quot;pay&quot;)]),Object (fromList [(&quot;unEndpointValue&quot;,Object (fromList [(&quot;ppLovelace&quot;,Number 1000000.0),(&quot;ppRecipient&quot;,Object (fromList [(&quot;getPubKeyHash&quot;,String &quot;977efb35ab621d39dbeb7274ec7795a34708ff4d25a01a1df04c1f27&quot;)]))]))])]),(&quot;tag&quot;,String &quot;ExposeEndpointResp&quot;)])
Slot 00001: W1: TxSubmit: 66b88e2673c2d50a5de7603fb28c71ac56963d88dda4c69dc529e2d26638b294
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 1}:
  Contract instance stopped (no errors)
Slot 00001: TxnValidate 66b88e2673c2d50a5de7603fb28c71ac56963d88dda4c69dc529e2d26638b294
Slot 00001: SlotAdd Slot 2
Slot 00002: SlotAdd Slot 3
Slot 00003: SlotAdd Slot 4
</code></pre>
<p>I feel like I can intuit what <code>Contract Stopped</code> means but I'd like to understand on a more technical level what this means and under which conditions this happens.</p>

<plutus><smart-contract><plutus-pioneer-program><haskell>
What does it mean for a contract to "stop"?
# What does it mean for a contract to "stop"?

(Asked by: username_0 on 2021-10-07)

I'm working through the week 4 homework for the Plutus Pioneer program. I've found an answer to the homework problem and now I'm trying to get a deeper understanding of the code. I've noticed that the payContract returns itself (I'm still learning Haskell so that terminology might not be correct).
I find that if I comment out this line of code, then the second invocation of callEndpoint doesn't do anything. I also notice that the logs of payTest1 say Contract Stopped:
Prelude Week04.Solution> payTest1
Slot 00000: TxnValidate 0636250aef275497b4f3807d661a299e34e53e5ad3bc1110e43d1f3420bc8fae
Slot 00000: SlotAdd Slot 1
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 1}:
  Contract instance started
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 1}:
  Receive endpoint call on 'pay' for Object (fromList [("contents",Array [Object (fromList [("getEndpointDescription",String "pay")]),Object (fromList [("unEndpointValue",Object (fromList [("ppLovelace",Number 1000000.0),("ppRecipient",Object (fromList [("getPubKeyHash",String "977efb35ab621d39dbeb7274ec7795a34708ff4d25a01a1df04c1f27")]))]))])]),("tag",String "ExposeEndpointResp")])
Slot 00001: W1: TxSubmit: 66b88e2673c2d50a5de7603fb28c71ac56963d88dda4c69dc529e2d26638b294
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 1}:
  Contract instance stopped (no errors)
Slot 00001: TxnValidate 66b88e2673c2d50a5de7603fb28c71ac56963d88dda4c69dc529e2d26638b294
Slot 00001: SlotAdd Slot 2
Slot 00002: SlotAdd Slot 3
Slot 00003: SlotAdd Slot 4

I feel like I can intuit what Contract Stopped means but I'd like to understand on a more technical level what this means and under which conditions this happens.

**Tags:** plutus, smart-contract, plutus-pioneer-program, haskell

---

## 1 answers

### Answer by username_1 on 2021-10-08. Score: 2 | Accepted answer

The line of interest is:
pp <- endpoint @"pay"

Which is essentially blocking until someone hits the "pay" endpoint and then returning whatever PayParams the caller included (see PaySchema).
In the case where you include the recursive payContract function call, you are essentially saying, "after running payContract, wait for someone else to hit the "pay" endpoint."
In the case that the recursive payContract function call is removed, the Contract monad will exit, since it isn't blocked on any endpoints or anything.
Hope that helps :)


---

