This module exposes the semantic functions of the Marlowe language. They can be used to simulate/test a contract.
import * as G from "@marlowe.io/language-core-v1/guards";import { datetoTimeout } from "@marlowe.io/language-core-v1";import { playTrace } from "@marlowe.io/language-core-v1/semantics";import { role, lovelace } from "@marlowe.io/language-core-v1/playground-v1";import { escrow } from "@marlowe.io/language-examples";const contract = escrow({ price: 100, depositTimeout: datetoTimeout(new Date("2050-06-01T00:00:00Z")), disputeTimeout: datetoTimeout(new Date("2050-06-02T00:00:00Z")), answerTimeout: datetoTimeout(new Date("2050-06-03T00:00:00Z")), arbitrageTimeout: datetoTimeout(new Date("2050-06-04T00:00:00Z")),});const txs = [ { tx_interval: { from: datetoTimeout(new Date("2050-05-01T00:00:00Z")), to: datetoTimeout(new Date("2050-05-02T00:00:00Z")), }, tx_inputs: [ { input_from_party: role("Buyer"), that_deposits: 100n, of_token: lovelace, into_account: role("Seller"), }, { for_choice_id: { choice_name: "Everything is alright", choice_owner: role("Buyer"), }, input_that_chooses_num: 0n, }, ], },];const txOut = playTrace( datetoTimeout(new Date("2000-06-01T00:00:00Z")), contract, txs);if (G.TransactionSuccess.is(txOut)) { const { state, contract, warnings, payments} = txOut; console.log(state, contract, warnings, payments);} Copy
import * as G from "@marlowe.io/language-core-v1/guards";import { datetoTimeout } from "@marlowe.io/language-core-v1";import { playTrace } from "@marlowe.io/language-core-v1/semantics";import { role, lovelace } from "@marlowe.io/language-core-v1/playground-v1";import { escrow } from "@marlowe.io/language-examples";const contract = escrow({ price: 100, depositTimeout: datetoTimeout(new Date("2050-06-01T00:00:00Z")), disputeTimeout: datetoTimeout(new Date("2050-06-02T00:00:00Z")), answerTimeout: datetoTimeout(new Date("2050-06-03T00:00:00Z")), arbitrageTimeout: datetoTimeout(new Date("2050-06-04T00:00:00Z")),});const txs = [ { tx_interval: { from: datetoTimeout(new Date("2050-05-01T00:00:00Z")), to: datetoTimeout(new Date("2050-05-02T00:00:00Z")), }, tx_inputs: [ { input_from_party: role("Buyer"), that_deposits: 100n, of_token: lovelace, into_account: role("Seller"), }, { for_choice_id: { choice_name: "Everything is alright", choice_owner: role("Buyer"), }, input_that_chooses_num: 0n, }, ], },];const txOut = playTrace( datetoTimeout(new Date("2000-06-01T00:00:00Z")), contract, txs);if (G.TransactionSuccess.is(txOut)) { const { state, contract, warnings, payments} = txOut; console.log(state, contract, warnings, payments);}
This module exposes the semantic functions of the Marlowe language. They can be used to simulate/test a contract.