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?

1 Answer 1


The cause is mustPayToOtherScript in the give endpoint where

give :: AsContractError e => Integer -> Contract w s e ()
give amount = do
  let tx = mustPayToOtherScript valHash (Datum $ Builtins.mkI 0) $ Ada.lovelaceValueOf amount 
  ledgerTx <- submitTx tx                                                                         
  void $ awaitTxConfirmed $ getCardanoTxId ledgerTx                                                
  Plutus.Contract.logInfo @String $ printf "made a gift of %d lovelace" amount 

The error is fixed by replacing mustPayToOtherScript with mustPayToOtherScriptWithDatumInTx.

Get the answer from mlabs-haskell/plutip. Thanks to their warning:

-- WARN: at the moment 'mustPayToOtherScript' causes 'DatumNotFound' error during constraints resolution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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