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


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

1 Answer 1


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    
  • Oh. Really many thanks ! I'll check Feb 7, 2022 at 17:18
  • @ViktorYasterbov, does it work?
    – kindofdev
    Feb 7, 2022 at 19:16
  • 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 Feb 9, 2022 at 12:24

Your Answer

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

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