How exactly can I fund the emulator wallets with custom currencies? Please show an emulator example doing so.


Here's an example:

import Data.Default (def)
import qualified Data.Map as Map
import qualified Ledger.Ada as Ada
import qualified Ledger.Value as Value
import Wallet.Emulator.Wallet (Wallet(..))
import Plutus.Trace.Emulator (EmulatorTrace, EmulatorConfig(..), runEmulatorTraceIO', 

main :: IO ()
main = do
  let dist = Map.fromList [ (Wallet 1, Ada.lovelaceValueOf 100_000_000
                                    <> Value.singleton "ffff" "mytoken" 10)
                          , (Wallet 2, Ada.lovelaceValueOf 25_000_000)
      emCfg = EmulatorConfig (Left dist) def def
  runEmulatorTraceIO' def emCfg myTrace

In summary, Wallet 1 starts of with 100 ADA, and 10 tokens with currency symbol ffff and token name mytoken. Wallet 2 simply starts with 25 ADA.

The Auction use-case example demonstrates that.

  • Thanks, but I didn't find as such in the example you pointed to.
    – Kwaggy
    Aug 30 at 20:16
  • Is there a way to show the final fine-grained distribution of Value amongst all the wallets (i.e., all the various currencies)?
    – Kwaggy
    Aug 30 at 22:18
  • 1
    If you mean the distribution of Value for all the wallets at the end of emulation, then the answer is that you don't need to do anything more than the example above. The function runEmulatorTraceIO prints the distribution for all wallets in the terminal at the end of emulation.
    – kolam
    Aug 30 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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