Test and emulate

Test and emulate transactions with the builtin emulator.

Initialize emulator

The emulator serves as a unique provider in Lucid, and it can be instantiated in the same way as any other provider. This provides a seamless experience, allowing for easy substitution of the emulator with a real network provider.

const emulator = new Emulator([{
  address: "addr_test...",
  assets: { lovelace: 3000000000n },
}]);

const lucid = await Lucid.new(emulator);

Working with time ranges

Unfortunately Date.now() doesn't work with the emulator because the network is not live and steps are only taken when requested. Instead you have to use emulator.now();

const tx = await lucid.newTx()
  .validTo(emulator.now())
  .complete();

Distribute staking rewards

The emulator allows you to conveniently distribute rewards to all delegated stake addresses.

emulator.distributeRewards(100000000n);

Logging state

At any point in the emulation you can call the following code to get the current state of the emulated blockchain. It gives you insights into the distribution of funds across addresses and shows you the current block height and slot.

emulator.log();

Emulator Api reference