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?