Skip to content

cardano-wasm demo: fee estimation, balance checks, signing, tx export - #1283

Open
palas wants to merge 2 commits into
masterfrom
wasm-demo-fee-sign-export
Open

cardano-wasm demo: fee estimation, balance checks, signing, tx export#1283
palas wants to merge 2 commits into
masterfrom
wasm-demo-fee-sign-export

Conversation

@palas

@palas palas commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

This PR adds the following functionality to the cardano-wasm demo:

  • Conway/Dijkstra era toggle; estimateMinFee over the described tx
  • balance arithmetic in Elm: change = inputs - outputs - fee; explicit outputs and the change must meet the ADA-only min-UTxO, gating the sign button (insufficient/dust/too-small states)
  • the two numbers Elm needs come as init flags from web/pparams.js — the same pinned ledger-format object estimateMinFee consumes (single source)
  • signing returns the CBOR and the tx id (body hash, shown pre-submission)
  • export: cardano-cli TextEnvelope download (tx.signed) + copy CBOR, with an era-matched broadcast hint and the witness counts it was signed with
  • stale protection: shape edits reset the fee (invalidateShape), and the fee/sign replies are accepted only while their request is still live
  • live tx inspector mirrors the exact spec, including the implicit change

Context

This is a follow up of: #1278

How to trust this PR

  • Diff is entirely in cardano-wasm/demo/ + a changelog fragment; CI already compiles it and checks elm-format.
  • This is the first slice that produces a real signed transaction — but nothing is broadcast: signing happens in cardano-wasm in the browser, keys stay in memory, and the only outputs are a downloaded tx.signed and copied CBOR.
  • You can test it by serving the contents of the demo artifact generated by the CI.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff
  • Changelog fragment added in .changes/

@palas palas self-assigned this Aug 8, 2026
@palas
palas requested review from Jimbo4350 and erikd as code owners August 8, 2026 00:01
Copilot AI lite review requested due to automatic review settings August 8, 2026 00:01
- Conway/Dijkstra era toggle; estimateMinFee over the described tx
- balance arithmetic in Elm: change = inputs - outputs - fee; explicit
  outputs and the change must meet the ADA-only min-UTxO, gating the
  sign button (insufficient/dust/too-small states)
- the two numbers Elm needs come as init flags from web/pparams.js — the
  same pinned ledger-format object estimateMinFee consumes (single
source)
- signing returns the CBOR and the tx id (body hash, shown
pre-submission)
- export: cardano-cli TextEnvelope download (tx.signed) + copy CBOR,
with
  an era-matched broadcast hint and the witness counts it was signed
with
- stale protection: shape edits reset the fee (invalidateShape), and the
  fee/sign replies are accepted only while their request is still live
- live tx inspector mirrors the exact spec, including the implicit
change
@palas
palas force-pushed the wasm-demo-fee-sign-export branch from 0b56e1e to cd8bdd5 Compare August 8, 2026 00:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the cardano-wasm/demo transaction builder from “draft spec” into a workflow that can estimate fees, perform basic balance/min-UTxO checks, sign a transaction in-browser, and export the signed transaction (CBOR + cardano-cli TextEnvelope), with additional UX support such as era toggling and a live tx inspector.

Changes:

  • Add pinned protocol parameters (pparams.js) and pass fee-related values into Elm via init flags (single source of truth for fee estimation + Elm balance arithmetic).
  • Implement fee estimation + signing ports (JS) and corresponding Elm commands/decoders/state gates (fee state, tx state, staleness protection).
  • Add UI for era selection, summary/balance display, signing/export actions, and a “live tx inspector”.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
cardano-wasm/demo/web/pparams.js Introduces pinned ledger-format protocol parameters consumed by fee estimation and Elm flags.
cardano-wasm/demo/web/ports.js Adds unsigned-tx builder plus fee estimation/signing port handlers; passes protocol flags into Elm.
cardano-wasm/demo/src/Wasm.elm Adds ports-side commands for fee estimation/signing and encodes the tx “spec” JSON sent to JS.
cardano-wasm/demo/src/View.elm Adds era toggle, builder summary, signing/export UI, and a live tx inspector panel.
cardano-wasm/demo/src/Update.elm Adds fee/sign/export state machine, staleness handling, and cardano-cli TextEnvelope download.
cardano-wasm/demo/src/Types.elm Adds era/fee/tx state types, signed payload types, and Protocol flags record.
cardano-wasm/demo/src/State.elm Adds balance/min-UTxO logic, readiness gates, staleness helpers, witness counting, and Protocol-flag init.
cardano-wasm/demo/src/Ports.elm Declares new fee-estimation and signing ports.
cardano-wasm/demo/src/Net.elm Adds era tags and cardano-cli TextEnvelope type mapping per era.
cardano-wasm/demo/src/Main.elm Switches Elm program flags from () to Protocol and wires new incoming ports.
.changes/20260718_cardano_wasm_demo_signing.yml Changelog fragment documenting the demo feature addition.
Files not reviewed (1)
  • cardano-wasm/demo/web/pparams.js: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cardano-wasm/demo/web/ports.js
Comment thread cardano-wasm/demo/src/Wasm.elm
Comment thread cardano-wasm/demo/src/State.elm
Comment thread cardano-wasm/demo/src/View.elm
- finalOutputs doc states the estimate-size relation precisely: the real
  transaction is never larger than the estimated one (over-pay only)
- the live tx inspector prints the fee exactly as the spec sends it
  (lovelace integer or null) instead of the display string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants