user2248: I am trying to create a dApp in which "accounts" are authenticated using a minting policy script. It should work by only allowing the minting of tokens if they are sent to an arbitrary script with the right Datum and value (since it should receive fees).
The problem I'm facing is that there doesn't seem to be a way of changing a "minting policy" recipient. I thought that if I specified in the transaction constraints that the script should receive N amount of tokens, the transaction would be automatically balanced and the script would receive the tokens, not the user.
let lookups = Constraints.mintingPolicy (policy fees)
    tx =
      Constraints.mustMintValue mintVal
        P.<> Constraints.mustPayToOtherScript vh (Datum $ PlutusTx.toBuiltinData initDatum) val
ledgerTx <- submitTxConstraintsWith @AccountType lookups tx

This didn't work as I intended though and, when I tried to run it, it returned an InsufficientFunds error
Slot 00001: *** CONTRACT LOG: "WalletError (InsufficientFunds \"Total: Value (Map [(,Map [(\\\"\\\",1000000000)]),(aa,Map [(\\\"DSET\\\",1000000)])]) expected: Value (Map [(97b688232555f47743c76605c03aea4ded52c6c20cc0a384f4b9a836,Map [(0x977efb35ab621d39dbeb7274ec7795a34708ff4d25a01a1df04c1f27bef45667a073d99a99a8ee15bd1abea2fc8140d5c00919060cda509e,300000)])])\")"

I suppose this is because the minted tokens were transferred directly to the user and not the script. My question is: Is there any way of making it so that a script, and not a user, receives the amount of tokens minted?

user1130: 
Is there any way of making it so that a script, and not a user, receives the amount of tokens minted?

Yep.
In your tx constraints, you need to both include mustMintValue mintVal and also mustPayToOtherScript that same mintVal. If you don't specify a recipient, it will just default to sending extra value to the transaction's originating wallet.
Not sure if you want separate datums for the minted value or what, but it might look like this:
Constraints.mustPayToOtherScript vh (Datum $ PlutusTx.toBuiltinData initDatum) (val <> mintedVal)

Here is an example from the Plutus Uniswap use cases of doing it with a separate datum. Notice that psC is minted and then included in the lpVal.
It helps to think of the minting as an input of the transaction, rather than an output.

2248: <p>I am trying to create a dApp in which &quot;accounts&quot; are authenticated using a minting policy script. It should work by only allowing the minting of tokens if they are sent to an arbitrary script with the right Datum and value (since it should receive fees).</p>
<p>The problem I'm facing is that there doesn't seem to be a way of changing a &quot;minting policy&quot; recipient. I thought that if I specified in the transaction constraints that the script should receive N amount of tokens, the transaction would be automatically balanced and the script would receive the tokens, not the user.</p>
<pre><code>let lookups = Constraints.mintingPolicy (policy fees)
    tx =
      Constraints.mustMintValue mintVal
        P.&lt;&gt; Constraints.mustPayToOtherScript vh (Datum $ PlutusTx.toBuiltinData initDatum) val
ledgerTx &lt;- submitTxConstraintsWith @AccountType lookups tx
</code></pre>
<p>This didn't work as I intended though and, when I tried to run it, it returned an InsufficientFunds error</p>
<pre><code>Slot 00001: *** CONTRACT LOG: &quot;WalletError (InsufficientFunds \&quot;Total: Value (Map [(,Map [(\\\&quot;\\\&quot;,1000000000)]),(aa,Map [(\\\&quot;DSET\\\&quot;,1000000)])]) expected: Value (Map [(97b688232555f47743c76605c03aea4ded52c6c20cc0a384f4b9a836,Map [(0x977efb35ab621d39dbeb7274ec7795a34708ff4d25a01a1df04c1f27bef45667a073d99a99a8ee15bd1abea2fc8140d5c00919060cda509e,300000)])])\&quot;)&quot;
</code></pre>
<p>I suppose this is because the minted tokens were transferred directly to the user and not the script. My question is: Is there any way of making it so that a script, and not a user, receives the amount of tokens minted?</p>
 1130: <blockquote>
<p>Is there any way of making it so that a script, and not a user, receives the amount of tokens minted?</p>
</blockquote>
<p>Yep.</p>
<p>In your <code>tx</code> constraints, you need to both include <code>mustMintValue mintVal</code> and also <code>mustPayToOtherScript</code> that same <code>mintVal</code>. If you don't specify a recipient, it will just default to sending extra value to the transaction's originating wallet.</p>
<p>Not sure if you want separate datums for the minted value or what, but it might look like this:</p>
<pre><code>Constraints.mustPayToOtherScript vh (Datum $ PlutusTx.toBuiltinData initDatum) (val &lt;&gt; mintedVal)
</code></pre>
<p><a href="https://github.com/input-output-hk/plutus/blob/49719aa5d250716a7c0ebacb30baf176364bd684/plutus-use-cases/src/Plutus/Contracts/Uniswap/OffChain.hs#L212" rel="nofollow noreferrer">Here</a> is an example from the Plutus Uniswap use cases of doing it with a separate datum. Notice that <code>psC</code> is minted and then included in the <code>lpVal</code>.</p>
<p>It helps to think of the minting as an input of the transaction, rather than an output.</p>
