Skip to main content
Version: Next

emulator.emulator

Home > @blaze-cardano/emulator > Emulator

Emulator class

The Emulator class is used to simulate the behavior of a ledger. It maintains a ledger of unspent transaction outputs, reward accounts, protocol parameters, and a clock. It also provides methods to start and stop an event loop for the ledger.

Signature:

export declare class Emulator 

Constructors

Constructor

Modifiers

Description

(constructor)(genesisOutputs, params, { evaluator, slotConfig })

Constructs a new instance of the Emulator class. Initializes the ledger with the provided genesis outputs and parameters.

Properties

Property

Modifiers

Type

Description

accounts

Map<RewardAccount, bigint>

The map of reward accounts and their balances.

clock

LedgerTimer

The clock of the ledger.

datumHashes

Record<DatumHash, PlutusData>

A lookup table of hashes to datums.

evaluator

Evaluator

The script evaluator for the emulator

eventLoop?

NodeJS.Timeout

(Optional) The event loop for the ledger.

mockedWallets

Map<string, Wallet>

A map from label to blaze instance for that wallet

params

ProtocolParameters

The protocol parameters of the ledger.

Methods

Method

Modifiers

Description

addressOf(label)

addUtxo(utxo)

Adds a given UTxO to the Emulator's ledger. Overwrites any existing UTxO with the same input.

as(label, callback)

awaitTransactionConfirmation(txId)

expectScriptFailure(tx, pattern)

expectValidMultisignedTransaction(signers, tx)

expectValidTransaction(blaze, tx)

fund(label, value, datum)

getOutput(inp)

Retrieves an output from the ledger by input.

lookupScript(script)

publishScript(script)

register(label, value, datum)

removeUtxo(inp)

Removes a given UTxO from the Emulator's ledger by input.

slotToUnix(slot)

startEventLoop()

Starts the event loop for the ledger. If the event loop is already running, it is cleared and restarted. The event loop calls the stepForwardBlock method every 20 slots.

stepForwardBlock()

stepForwardToSlot(slot)

stepForwardToUnix(unix)

stopEventLoop()

Stops the event loop for the ledger. If the event loop is running, it is cleared.

submitTransaction(tx)

Submits a transaction to the ledger.

unixToSlot(unix_millis)

utxos()

Retrieves the Emulator's ledger as an array of UTxOs.