5

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?

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.