This is how I spend script's utxos with the Emulator. This one from this example.
grab :: forall w s e. AsContractError e => Contract w s e ()
grab = do
utxos <- utxosAt scrAddress
let orefs = fst <$> Map.toList utxos
lookups = Constraints.unspentOutputs utxos <>
Constraints.plutusV1OtherScript validator
tx :: TxConstraints Void Void
tx = mconcat [mustSpendScriptOutput oref $ Redeemer $ Builtins.mkI 17 | oref <- orefs]
ledgerTx <- submitTxConstraintsWith @Void lookups tx
void $ awaitTxConfirmed $ getCardanoTxId ledgerTx
Plutus.Contract.logInfo @String $ "collected gifts"
This is PlutusV1. This works as expected. But with PlutusV2, the lookups
now is like:
lookups = Constraints.unspentOutputs utxos <>
Constraints.plutusV2OtherScript validator
Note the version difference in Constraints.plutusV2OtherScript validator
.
The rest of the code is the same except that this time the package is plutus-apps v1.0.0.
The V2 script compiles but when grab
is called I get this error:
*** CONTRACT STOPPED WITH ERROR: ""ConstraintResolutionContractError (DatumNotFound 03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314)""
I try Constraints.otherScript (Versioned validator PlutusV2)
. Same error.
I try Plutus.Trace
instead of Plutus.Trace.Emulator
. Same error.
This is just one example. I see this "DatumNotFound" error in other projects when trying to work with plutus-apps v1.0.0.
How do I fix this. Or is it just a bug?