I'm trying to create a contract where a TxOutRef is supplied to it which tells it a specific UTxO to use in the contract. This seemed fine until I started working with ContractModel. I can't find any way to pass on information about UTxOs that I create. nextState allows me to update the state, but I can't get any contract related info there. perform lets me get info from the contracts, but doesn't let me update the state.

1 Answer 1


Hopefully I'm understanding your question correctly. I'm hearing two things here:

How do I include a specific UTxO in a transaction required by a script?

Here is an example of off-chain code including an arbitrary UTxO to create "one shot", single issued currency.

In this case it doesn't matter which UTxO it is, as long as the TxOutRef (txOutRef) referenced in the OneShotCurrency (thisCurrency) is spent with the minting transaction:

    let theCurrency = mkCurrency txOutRef amounts
        mintTx      = Constraints.mustSpendPubKeyOutput txOutRef
                        <> Constraints.mustMintValue (mintedValue theCurrency)

How do I to choose a specific UTxO "that I created?"

One way is how the oracle is grabbed from the ContractHandle in the Oracle example. The Oracle value is stored in the ContractHandle monad as a Last and can be grabbed inside the runtime context with the getOracle function.

The logic for actually finding the UTxO is the the findOracle function here.

An alternative approach is in the Uniswap example. An NFT is created with Currency.mintContract and then immediately used as the NFT (c) for the Factory Datum here:

tx   = mustPayToTheScript (Factory []) $ unitValue c

This approach avoids managing the UTxO directly.

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.