How exactly can I fund the emulator wallets with custom currencies? Please show an emulator example doing so.
3 Answers
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',
activateContractWallet)
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.– KwaggyCommented Aug 30, 2021 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)?– KwaggyCommented Aug 30, 2021 at 22:18 -
1If 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 functionrunEmulatorTraceIO
prints the distribution for all wallets in the terminal at the end of emulation.– kolamCommented Aug 30, 2021 at 22:34
12/2022, plutus-apps v1.0.0 update on the accepted answer.
Wallet 1
is not working anymore. You can use knownWallet 1
.
Or you can import Plutus.Contract.Test (w1, w2)
and then use w1
, w2
as your simulated wallets.
Also EmulatorConfig
has 2 components, not 3. So it is:
emCfg = EmulatorConfig (Left dist) def
BTW I get error when setting initial state with custom currencies.
the easier way I found:
dist = Map.fromList [ (wallet 1, Ada.lovelaceValueOf 1_000_000_000 ) -- treasury
, (wallet 2, Ada.lovelaceValueOf 1_000_000_000
<> Value.singleton yacadaNFTSymbol (U.giveReferralNFTName ) 15) -- referral