Skip to main content
@al-ft/midgard-sdk is the official off-chain TypeScript library for interacting with the Sundial L2. It is the same library the Sundial node uses internally, so anything the node’s HTTP API can trigger, you can build directly with the SDK. The library is built on two foundational dependencies: Effect for typed, composable error handling, and Lucid Evolution for Cardano transaction construction. Every public function returns either a plain Promise or an Effect blueprint, giving you a choice of programming style.
Version 0.1.0 is distributed as a pnpm repack tarball — not a published npm package. Add it to your project by pointing your package manager at the local tarball path. See the installation steps below.

Installation

1

Bundle the tarball

Clone the sundial-monorepo repository and bundle the SDK into a local tarball:
This produces al-ft-midgard-sdk-0.1.0.tgz inside the package directory.
2

Add to your project

Reference the tarball in your package.json:
3

Initialize Lucid Evolution

The SDK requires a LucidEvolution instance. Create one against your preferred Cardano provider before calling any SDK function:

Core Modules

The SDK is organized into vertical modules. All names are globally unique, so you can either import the entire namespace or import individual functions.

user-events/deposit

Construct and fetch L2 deposit event UTxOs. A deposit places ADA into the Sundial deposit validator on L1, which the sequencer picks up and credits on L2.

user-events/withdrawal

Construct L2 withdrawal orders. A withdrawal burns the L2 UTxO and mints a withdrawal claim redeemable on L1 after the challenge window.

user-events/tx-order

Post a transaction order directly to L1 for guaranteed inclusion in the next L2 block, bypassing the node’s mempool. Use this when low-latency finality matters.

hub-oracle

Query the Hub Oracle UTxO for authoritative protocol policy IDs, validator addresses, and protocol parameters. Pass the result as a reference input in transactions.

scheduler

Query the operator scheduling state to determine which operator is currently authorized to produce blocks.

state-queue

Interact with the L2 state queue linked list — commit new blocks, merge confirmed state, and read the current queue head.

fraud-proof

Construct and submit multi-step fraud proofs against invalid blocks. Covers double-spend, invalid range, non-existent input, and computation-thread dispute programs.

active/registered/retired-operators

Manage the operator directory lifecycle: register, activate, and retire Operator nodes.

Usage Examples

Constructing a Deposit

A deposit locks ADA in the Sundial deposit validator on L1. The sequencer syncs the event and credits the amount to your L2 address at the next block boundary.
Functions ending in Program (e.g., unsignedDepositTxProgram) return an Effect blueprint for use inside Effect.gen pipelines. Functions without the suffix return a plain Promise. Use whichever fits your codebase.

Constructing a Withdrawal

A withdrawal burns your L2 UTxO and registers a withdrawal claim on L1 that you redeem after the optimistic challenge window (approximately 24 hours on testnet).

Posting a Transaction Order (Guaranteed Inclusion)

A transaction order posts your L2 transaction directly to L1. The sequencer is obligated to include it in the next block — bypassing the mempool and the node’s minimum-fee ordering.

Querying the Scheduler

Check which operator is currently scheduled to produce blocks before submitting operator tooling transactions.

Submitting a Fraud Proof

Fraud proofs challenge invalid blocks committed to the state queue. The SDK exposes multi-step incomplete*TxProgram builders for each fraud proof type — wire the Effect result into your Effect pipeline and complete the transaction with your wallet.

Error Handling with Effect

The SDK’s internal Program functions use Effect’s typed error channel. Wrap them with Effect.runPromise or handle errors with Effect.catchTag to distinguish between LucidError, HashingError, DepositError, and others.
Use Effect’s error handling for robust SDK integrations. Each tagged error type carries a message and a cause field that pinpoints exactly where the failure occurred.

SDK-to-Validator Reference

Each SDK module targets a specific pair of Plutus V3 validators in the Sundial smart contract system.
On testnet, the Sundial node runs against always-succeeds placeholder validators — every validator unconditionally returns True. This means on-chain script validation enforces nothing about protocol rules during testnet. All correctness guarantees come from the node’s and SDK’s off-chain checks. Never send real value to testnet contract addresses.
Full Plutus V3 enforcement — fee correctness, UTxO validity, double-spend prevention, and fraud-proof soundness — applies on mainnet. Behavior observed against the testnet demo is not a reliable indicator of what the production validators accept.

Midgard Types

TypeScript type definitions and binary codec for L2 blocks, transactions, and user events. Use midgard-ts to validate transactions before submission.

REST API Overview

The Sundial node also exposes an HTTP RPC API. Use the REST API as an alternative to the SDK if you prefer HTTP-based integration.