<p>This helper function can help you. It returns the list of <strong>TxOutRef</strong> and <strong>TxOut</strong> owned by an address.</p>
<pre><code>import Control.Lens
import qualified Data.Map as Map
import Ledger 
import Ledger.Index
import Plutus.Trace.Emulator qualified as Trace

getUtxos :: Address -&gt; Trace.EmulatorTrace [(TxOutRef, TxOut)]
getUtxos addr = do
    state &lt;- Trace.chainState
    let utxoIndex = getIndex $ state ^. Trace.index 
        utxos     =  [(oref, o) | (oref, o) &lt;- Map.toList utxoIndex, txOutAddress o == addr]
    pure utxos    
</code></pre>

CC BY-SA 4.0
2022-02-07T17:18:17.980Z
Oh. Really many thanks ! I'll check
ViktorYasterbov
CC BY-SA 4.0
2022-02-07T19:16:01.903Z
@ViktorYasterbov, does it work?
kindofdev
CC BY-SA 4.0
2022-02-09T12:24:02.193Z
Yeah. Great. Everything is fine. Thank you for help. you gave me good hint eventually how to process things under Emulator. I did the same for getting values etc
ViktorYasterbov
CC BY-SA 4.0
2022-02-07T16:42:05.560Z
2022-02-07T16:42:05.560Z
kindofdev
<p>I'm doing integration tests with Emulation
As far as I understand under emulation wallets have initial funds.</p>
<p>Example:</p>
<pre><code>test :: IO ()
test = runEmulatorTraceIO $ do
    let 
        w1 = knownWallet 1
        walletAddress = mockWalletAddress w1
        # how to get utxos for walletAddress under emulator ????
</code></pre>

<plutus>
How to get Utxos from emulation wallet
# How to get Utxos from emulation wallet

(Asked by: username_0 on 2022-02-07)

I'm doing integration tests with Emulation
As far as I understand under emulation wallets have initial funds.

Example:

```
test :: IO ()
test = runEmulatorTraceIO $ do
    let 
        w1 = knownWallet 1
        walletAddress = mockWalletAddress w1
        # how to get utxos for walletAddress under emulator ????

```

**Tags:** plutus


---

## 1 answers

### Answer by username_1 on 2022-02-07. Score: 1 | Accepted answer

This helper function can help you. It returns the list of **TxOutRef** and **TxOut** owned by an address.

```
import Control.Lens
import qualified Data.Map as Map
import Ledger 
import Ledger.Index
import Plutus.Trace.Emulator qualified as Trace

getUtxos :: Address -> Trace.EmulatorTrace [(TxOutRef, TxOut)]
getUtxos addr = do
    state <- Trace.chainState
    let utxoIndex = getIndex $ state ^. Trace.index 
        utxos     =  [(oref, o) | (oref, o) <- Map.toList utxoIndex, txOutAddress o == addr]
    pure utxos    

```

> **Comments:**
> **username_0**: Oh. Really many thanks ! I'll check  
> **username_1**: @username_0, does it work?  
> **username_0**: Yeah. Great. Everything is fine. Thank you for help. you gave me good hint eventually how to process things under Emulator. I did the same for getting values etc  

---

