<p>Assuming each UTxO at the script address has a datum that contains the PubKeyHash you can compare against, then you can use the above code like so:</p>
<pre><code>data UTxODatum = UTxODatum
    { pubKey :: !PaymentPubKeyHash }

{...}
    isSuitable :: PaymentPubKeyHash -&gt; ChainIndexTxOut -&gt; Bool
    isSuitable pkh o = case getUTxODatum o of
        UTxODatum{pubKey=pubKey} -&gt; pubKey == &lt;your specific pkh&gt;
        _                        -&gt; traceError &quot;Unhandled datum type&quot;
{...}

getUTxODatum :: ChainIndexTxOut -&gt; UTxODatum
getUTxODatum o = case _ciTxOutDatum o of
    Left _ -&gt; traceError &quot;unexpected datum&quot;
    Right (Datum d) -&gt; do
        let parsedDatum = PlutusTx.fromBuiltinData d :: Maybe UTxODatum
        case parsedDatum of
            Just s -&gt; s
            _ -&gt; traceError &quot;Unknown datum type&quot;

</code></pre>

CC BY-SA 4.0
2022-04-09T17:33:03.117Z
2022-04-09T17:33:03.117Z
Will
<p>In the pionner program they have this logic where they filter through utxos and get a specific set of utxos.</p>
<pre><code>{...}
utxos &lt;- Map.filter (isSuitable pkh) &lt;$&gt; utxosAt scrAddress
{...}
where
   isSuitable :: PubKeyHash -&gt; TxOutTx -&gt; Bool
</code></pre>
<p>How can i modify this to make it so that it filters utxos that came from a specific public key address. Basically get all utxos sitting in a script address that came from a specific public key.</p>

<utxo><pkh>
Filter for utxos that was send from a specific public key address
# Filter for utxos that was send from a specific public key address

(Asked by: username_0 on 2022-04-09)

In the pionner program they have this logic where they filter through utxos and get a specific set of utxos.
{...}
utxos <- Map.filter (isSuitable pkh) <$> utxosAt scrAddress
{...}
where
   isSuitable :: PubKeyHash -> TxOutTx -> Bool

How can i modify this to make it so that it filters utxos that came from a specific public key address. Basically get all utxos sitting in a script address that came from a specific public key.

**Tags:** utxo, pkh

---

## 1 answers

### Answer by username_1 on 2022-04-09. Score: 1 | Accepted answer

Assuming each UTxO at the script address has a datum that contains the PubKeyHash you can compare against, then you can use the above code like so:
data UTxODatum = UTxODatum
    { pubKey :: !PaymentPubKeyHash }

{...}
    isSuitable :: PaymentPubKeyHash -> ChainIndexTxOut -> Bool
    isSuitable pkh o = case getUTxODatum o of
        UTxODatum{pubKey=pubKey} -> pubKey == 
        _                        -> traceError "Unhandled datum type"
{...}

getUTxODatum :: ChainIndexTxOut -> UTxODatum
getUTxODatum o = case _ciTxOutDatum o of
    Left _ -> traceError "unexpected datum"
    Right (Datum d) -> do
        let parsedDatum = PlutusTx.fromBuiltinData d :: Maybe UTxODatum
        case parsedDatum of
            Just s -> s
            _ -> traceError "Unknown datum type"


---

