user2560: So I have this code which uses a modified version of the [guess game] (https://github.com/agocorona/DAppFlow/blob/main/ContractExample/GuessGame.hs) which parameterizes the validateGuess script with a parameter depending on the user hash, so that each user can make a lock to his own scrip instance
I create two instances and the corresponding wallets make a lock of funds to his own instance:
main = Simulator.runSimulationWith handlers $ do

     cid  <- Simulator.activateContract (Wallet 1) GuessGame
     cid2 <- Simulator.activateContract (Wallet 2) GuessGame

    
     waitNSlots 3
     callEndpointOnInstance  cid  "lock" LockParams{secretWord="world", amount= Ada.adaValueOf 200}
     waitNSlots 3
     callEndpointOnInstance  cid2 "lock" LockParams{secretWord="world", amount= Ada.adaValueOf 200}
     waitNSlots 3
     Simulator.logString @(Builtin TestContracts) "Balances at the end of the simulation"
     b <- Simulator.currentBalances
     Simulator.logBalances @(Builtin TestContracts) b 

The balances reflect the operations:
[INFO] Balances at the end of the simulation
[INFO] Wallet 1: 
[INFO]     {, ""}: 99799999990
[INFO] Wallet 2: 
[INFO]     {, ""}: 99799999990
[INFO] Wallet 3: 
[INFO]     {, ""}: 100000000000
[INFO] Wallet 4: 
.....
.....
[INFO] Script 4c7d92f39ce436db8cf07bb207ca4272b255673ce988d9642403d7b8: 
[INFO]     {, ""}: 200000000
[INFO] Script 8d558e1a3cda0d447eb4d2d5ffe0837c355dc1c8f2519e205b37c439: 
[INFO]     {, ""}: 200000000


The scripts have the 200000000 funds allocated and the wallets lost 200000000 + 20 of fees
Now the question is: How I invoke the guess to one of these two instances with a third wallet ?
If I use:
callEndpointOnInstance cid "guess" GuessParams{guessWord="world",userHash=.....}

Then the funds are returned to wallet 1, since it is the wallet with which I initiated the cid contract. How I introduce a third wallet that may guess to each of these two instances?

user1231: You need to define contracts for every endpoint that you need to call. So, an endpoint for Lock and other one for Guess
Something like this:
data GuessGameContracts = Lock
                     | Guess
    deriving (Eq, Ord, Show, Generic, FromJSON, ToJSON)

instance Pretty GuessGameContracts where
    pretty = viaShow

instance HasDefinitions GuessGameContracts where
    getDefinitions = [Lock, Guess]
    getContract = getGuessGameContracts
    getSchema = getGuessGameSchema

getGuessGameSchema :: GuessGameContracts -> [FunctionSchema FormSchema]
getGuessGameSchema = \case
    Lock   -> Builtin.endpointsToSchemas @GameSchema
    Guess  -> Builtin.endpointsToSchemas @GameSchema

getGuessGameContracts :: GuessGameContracts -> SomeBuiltin
getGuessGameContracts = \case
    Lock   -> SomeBuiltin $ lock
    Guess  -> SomeBuiltin $ guess

handlers :: SimulatorEffectHandlers (Builtin GuessGameContracts)
handlers =
    Simulator.mkSimulatorHandlers def def (interpret (contractHandler Builtin.handleBuiltin))

And use it like this to activate every contract:
cid1  <- Simulator.activateContract (Wallet 1) Lock
cid2  <- Simulator.activateContract (Wallet 2) Lock
cid3  <- Simulator.activateContract (Wallet 3) Guess

You can find an example in Lesson 10 of PPP - Uniswap

2560: <p>So I have this code which uses a modified version of the [guess game] (<a href="https://github.com/agocorona/DAppFlow/blob/main/ContractExample/GuessGame.hs" rel="nofollow noreferrer">https://github.com/agocorona/DAppFlow/blob/main/ContractExample/GuessGame.hs</a>) which parameterizes the validateGuess script with a parameter depending on the user hash, so that each user can make a lock to his own scrip instance</p>
<p>I create two instances and the corresponding wallets make a lock of funds to his own instance:</p>
<pre><code>main = Simulator.runSimulationWith handlers $ do

     cid  &lt;- Simulator.activateContract (Wallet 1) GuessGame
     cid2 &lt;- Simulator.activateContract (Wallet 2) GuessGame

    
     waitNSlots 3
     callEndpointOnInstance  cid  &quot;lock&quot; LockParams{secretWord=&quot;world&quot;, amount= Ada.adaValueOf 200}
     waitNSlots 3
     callEndpointOnInstance  cid2 &quot;lock&quot; LockParams{secretWord=&quot;world&quot;, amount= Ada.adaValueOf 200}
     waitNSlots 3
     Simulator.logString @(Builtin TestContracts) &quot;Balances at the end of the simulation&quot;
     b &lt;- Simulator.currentBalances
     Simulator.logBalances @(Builtin TestContracts) b 
</code></pre>
<p>The balances reflect the operations:</p>
<pre><code>[INFO] Balances at the end of the simulation
[INFO] Wallet 1: 
[INFO]     {, &quot;&quot;}: 99799999990
[INFO] Wallet 2: 
[INFO]     {, &quot;&quot;}: 99799999990
[INFO] Wallet 3: 
[INFO]     {, &quot;&quot;}: 100000000000
[INFO] Wallet 4: 
.....
.....
[INFO] Script 4c7d92f39ce436db8cf07bb207ca4272b255673ce988d9642403d7b8: 
[INFO]     {, &quot;&quot;}: 200000000
[INFO] Script 8d558e1a3cda0d447eb4d2d5ffe0837c355dc1c8f2519e205b37c439: 
[INFO]     {, &quot;&quot;}: 200000000

</code></pre>
<p>The scripts have the 200000000 funds allocated and the wallets lost 200000000 + 20 of fees</p>
<p>Now the question is: How I invoke the guess to one of these two instances with a third wallet ?</p>
<p>If I use:</p>
<pre><code>callEndpointOnInstance cid &quot;guess&quot; GuessParams{guessWord=&quot;world&quot;,userHash=.....}
</code></pre>
<p>Then the funds are returned to wallet 1, since it is the wallet with which I initiated the cid contract. How I introduce a third wallet that may guess to each of these two instances?</p>
 1231: <p>You need to define <em>contracts</em> for every endpoint that you need to call. So, an endpoint for <code>Lock</code> and other one for <code>Guess</code></p>
<p>Something like this:</p>
<pre><code>data GuessGameContracts = Lock
                     | Guess
    deriving (Eq, Ord, Show, Generic, FromJSON, ToJSON)

instance Pretty GuessGameContracts where
    pretty = viaShow

instance HasDefinitions GuessGameContracts where
    getDefinitions = [Lock, Guess]
    getContract = getGuessGameContracts
    getSchema = getGuessGameSchema

getGuessGameSchema :: GuessGameContracts -&gt; [FunctionSchema FormSchema]
getGuessGameSchema = \case
    Lock   -&gt; Builtin.endpointsToSchemas @GameSchema
    Guess  -&gt; Builtin.endpointsToSchemas @GameSchema

getGuessGameContracts :: GuessGameContracts -&gt; SomeBuiltin
getGuessGameContracts = \case
    Lock   -&gt; SomeBuiltin $ lock
    Guess  -&gt; SomeBuiltin $ guess

handlers :: SimulatorEffectHandlers (Builtin GuessGameContracts)
handlers =
    Simulator.mkSimulatorHandlers def def (interpret (contractHandler Builtin.handleBuiltin))
</code></pre>
<p>And use it like this to activate every contract:</p>
<pre><code>cid1  &lt;- Simulator.activateContract (Wallet 1) Lock
cid2  &lt;- Simulator.activateContract (Wallet 2) Lock
cid3  &lt;- Simulator.activateContract (Wallet 3) Guess
</code></pre>
<p>You can find an example in <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/8cbc68d146c82cc95d9be44c30e049aba3774003/code/week10/app/Uniswap.hs#L29-L48" rel="nofollow noreferrer">Lesson 10 of PPP - Uniswap</a></p>
