<p>Hopefully I'm understanding your question correctly. I'm hearing two things here:</p>
<p><strong>How do I include a specific UTxO in a transaction required by a script?</strong></p>
<p><a href="https://github.com/input-output-hk/plutus-apps/blob/7f7aca8500105d3a0830b40627f1821c9ac7b58e/plutus-use-cases/src/Plutus/Contracts/Currency.hs#L156" rel="nofollow noreferrer">Here</a> is an example of off-chain code including an arbitrary UTxO to create &quot;one shot&quot;, single issued currency.</p>
<p>In this case it doesn't matter which UTxO it is, as long as the <code>TxOutRef</code> (<code>txOutRef</code>) referenced in the <code>OneShotCurrency</code> (<code>thisCurrency</code>) is spent with the minting transaction:</p>
<pre><code>    let theCurrency = mkCurrency txOutRef amounts
        ...
        mintTx      = Constraints.mustSpendPubKeyOutput txOutRef
                        &lt;&gt; Constraints.mustMintValue (mintedValue theCurrency)
</code></pre>
<p><strong>How do I to choose a specific UTxO &quot;that I created?&quot;</strong></p>
<p>One way is how the oracle is grabbed from the <code>ContractHandle</code> in the <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/8cbc68d146c82cc95d9be44c30e049aba3774003/code/week06/src/Week06/Oracle/Test.hs#L70" rel="nofollow noreferrer">Oracle example</a>. The <code>Oracle</code> value is stored in the <code>ContractHandle</code> monad as a <code>Last</code> and can be grabbed inside the runtime context with the <code>getOracle</code> function.</p>
<p>The logic for actually finding the UTxO is the the <code>findOracle</code> function <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/8cbc68d146c82cc95d9be44c30e049aba3774003/code/week06/src/Week06/Oracle/Core.hs#L176" rel="nofollow noreferrer">here</a>.</p>
<p>An alternative approach is in the <a href="https://github.com/input-output-hk/plutus-apps/blob/7f7aca8500105d3a0830b40627f1821c9ac7b58e/plutus-use-cases/src/Plutus/Contracts/Uniswap/OffChain.hs#L173" rel="nofollow noreferrer">Uniswap example</a>. An NFT is created with <code>Currency.mintContract</code> and then immediately used as the NFT (<code>c</code>) for the Factory Datum here:</p>
<pre><code>tx   = mustPayToTheScript (Factory []) $ unitValue c
</code></pre>
<p>This approach avoids managing the UTxO directly.</p>

CC BY-SA 4.0
2021-11-15T23:37:21.260Z
2021-11-15T23:37:21.260Z
Mitchell Turner
<p>I'm trying to create a contract where a <code>TxOutRef</code> is supplied to it which tells it a specific UTxO to use in the contract. This seemed fine until I started working with <code>ContractModel</code>. I can't find any way to pass on information about UTxOs that I create. <code>nextState</code> allows me to update the state, but I can't get any contract related info there. <code>perform</code> lets me get info from the contracts, but doesn't let me update the state.</p>

<plutus>
How can I pinpoint a specific UTxO using ContractModel
# How can I pinpoint a specific UTxO using ContractModel

(Asked by: username_0 on 2021-11-15)

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.

**Tags:** plutus

---

## 1 answers

### Answer by username_1 on 2021-11-15. Score: 0

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.


---

