cometa: Idiomatic Haskell bindings to cardano-c

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Haskell-owned Cardano values with transaction construction, signing, script evaluation and provider interfaces backed by cardano-c. Includes a Blockfrost provider.


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.2.0.0
Change log None available
Dependencies aeson (>=2.2 && <2.3), async (>=2.2 && <2.3), base (>=4.18 && <4.22), bech32 (>=1.1.10 && <1.2), bytestring (>=0.11 && <0.13), cardano-c-clib (==0.1.0.0), cborg (>=0.2.10 && <0.3), cometa, containers (>=0.6.7 && <0.8), crypton-x509-store (>=1.8 && <1.9), crypton-x509-system (>=1.8 && <1.9), http-client (>=0.7.19 && <0.8), http-client-tls (>=0.3.6 && <0.4), http-types (>=0.12.3 && <0.13), network (>=3.2.12 && <3.3), network-uri (>=2.6.4 && <2.7), scientific (>=0.3.7 && <0.4), stm (>=2.5 && <2.6), text (>=2.0 && <2.2), tls (>=2.2 && <2.3), transformers (>=0.6 && <0.7) [details]
License Apache-2.0
Author Biglup Labs
Maintainer angel.castillob@protonmail.com
Category Blockchain
Home page https://github.com/Biglup/cometa.hs
Bug tracker https://github.com/Biglup/cometa.hs/issues
Source repo head: git clone https://github.com/Biglup/cometa.hs.git
Uploaded by angelcastillob at 2026-11-24T08:57:32Z

Modules

[Index] [Quick Jump]

Flags

Manual Flags

NameDescriptionDefault
system-cardano-c

Link an installed cardano-c instead of the bundled source package.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for cometa-0.1.0.0

[back to package description]
Cometa.hs

License Documentation Twitter Follow


Cometa.hs is a Haskell library for building, signing and inspecting Cardano transactions through cardano-c. Compose transaction requirements as immutable values, then balance them against explicit protocol parameters and wallet UTxOs. Expected failures use Either Error. Building, signing and network requests run in IO.

The examples cover features introduced across these eras:

Era features Workflows
Shelley Payments, stake delegation and reward withdrawals
Mary Native assets, minting and burning
Alonzo and Babbage Plutus spending, collateral, inline datums and reference scripts
Conway DReps, voting delegation, governance proposals and votes
Dijkstra Plutus V4 guards, direct deposits and independently signed subtransactions

Use protocol parameters and ledger rules for the network you target. Dijkstra workflows require a network that supports those features.

Installation

Cometa.hs is not yet published on Hackage. Build the checkout with GHC, Cabal and a C toolchain. Prepare its bundled native dependency from the cardano-c checkout pinned in native/cardano-c.ref, then build normally. See the installation guide for prerequisites and the optional installed-library configuration.

python3 tools/package-native.py /path/to/pinned/cardano-c
cabal build all
cabal run cometa-transaction-building

The example builds an offline payment with synthetic inputs. To use Cometa in an application, include the checkout in your cabal.project and add cometa to build-depends. The Blockfrost provider is included.

Build a payment

A plan describes what a transaction must do. (<>) combines requirements and preserves output order. The builder selects inputs, calculates fees and returns an unsigned transaction. For example, this function pays 2 ADA using supplied wallet and protocol snapshots:

import qualified Cometa.Address as Address
import Cometa.Error (Error)
import qualified Cometa.Protocol.Parameters as Parameters
import qualified Cometa.SlotConfig as Slots
import qualified Cometa.Transaction as Tx
import qualified Cometa.Transaction.Builder as Builder
import qualified Cometa.Transaction.Datum as Datum
import qualified Cometa.Transaction.Output as Output
import qualified Cometa.Transaction.Plan as Plan
import qualified Cometa.Transaction.Utxo as Utxo
import qualified Cometa.Value as Value
import Control.Monad.Trans.Except (ExceptT (..), except, runExceptT)
import Data.Word (Word64)

buildPayment :: Parameters.Parameters -> Slots.SlotConfig -> Address.Address
  -> [Utxo.Utxo] -> Address.Address -> Word64
  -> IO (Either Error Tx.Transaction)
buildPayment params slots change funds recipient expiry = runExceptT $ do
  payment <- except
    (Output.mkOutput recipient (Value.lovelace 2000000) Datum.NoDatum Nothing)
  let config = (Builder.defaultConfig params slots change)
        { Builder.availableUtxos = funds }
      plan = Plan.payTo payment <> Plan.validUntil expiry
  ExceptT (Builder.build config plan)

Amounts are integer lovelace: 1 ADA is 1,000,000 lovelace. expiry is an absolute slot on the selected network. Use Slots.mainnet, Slots.preprod or Slots.preview with matching protocol parameters, addresses and UTxOs. Validate external addresses with Address.fromText. Multiple payments compose with Plan.payTo first <> Plan.payTo second.

TransactionBuilding.hs is a complete offline program. BlockfrostPayment.hs fetches protocol parameters and UTxOs, builds, signs and optionally submits the payment.

Sign and connect to a network

The following snippets reuse the payment example's imports. A Signer returns additional witnesses. Attach them explicitly; submission is a separate provider operation:

import qualified Cometa.Provider as Provider
import qualified Cometa.Signer as Signer
import qualified Cometa.TransactionId as TxId

signAndSubmit :: Provider.Provider -> Signer.Signer -> Tx.Transaction
  -> IO (Either Error TxId.TransactionId)
signAndSubmit provider signer unsigned = runExceptT $ do
  witnesses <- ExceptT (Signer.signTransaction signer unsigned)
  signed <- except (Tx.addWitnesses witnesses unsigned)
  ExceptT (Provider.submitTransaction provider signed)

Signer.ed25519, Signer.software and Signer.bip32 adapt scoped keys or software handlers. Keep the scope open until signing completes. A custom Signer can call a hardware wallet or another signing service without exporting a private key. See signing, software key handlers and wallet recovery.

Provider is a record of query, evaluation and submission functions. Use Cometa.Provider.Blockfrost or supply your own backend. Submission returns an accepted transaction ID; call Provider.awaitTransaction separately to wait for confirmation. The Blockfrost guide explains network, endpoint and authentication configuration.

Connected examples print usage when run without arguments:

cabal run cometa-send-lovelace

Follow the connected examples guide to configure your encrypted wallet, recipient, amount and validity slot. Its --submit mode runs the configured on-chain workflow.

Native assets and metadata

Compose native-script minting with a token output. This function takes a validated policy script and asset name, hashes the actual script for its policy ID, and mints one token:

import qualified Cometa.AssetId as AssetId
import qualified Cometa.AssetName as AssetName
import qualified Cometa.PolicyId as PolicyId
import qualified Cometa.Script as Script
import qualified Cometa.Script.Native as NativeScript

mintToken :: Address.Address -> NativeScript.NativeScript -> AssetName.AssetName
  -> IO (Either Error Plan.Plan)
mintToken recipient policy name = runExceptT $ do
  let script = Script.Native policy
  digest <- ExceptT (Script.hash script)
  let asset = AssetId.Native (PolicyId.fromScriptHash digest) name
      value = Value.lovelace 2000000 <> Value.fromList [(asset, 1)]
  output <- except (Output.mkOutput recipient value Datum.NoDatum Nothing)
  pure (Plan.attachScript script <> Plan.mint asset 1 <> Plan.payTo output)

Pass the result to Builder.build with your configuration. Satisfy the native policy's signatures and validity interval, and fund the minimum ADA required by the output. Negative mint quantities burn tokens. Plan.metadata adds metadata under an integer label; the mint/burn recipe includes CIP-25 metadata under label 721 and both native and Plutus policies. See assets and values for validated asset names, policy IDs and multi-asset arithmetic.

Plutus contracts and deferred redeemers

Attach a native or Plutus script with Plan.attachScript, or use an existing reference-script UTxO through Plan.referenceInput. Output.mkOutput accepts a datum and optional reference script; Plan.spendWith supplies a spending redeemer and optional datum witness. Plutus minting, withdrawals, certificates, votes and governance proposals have corresponding redeemer operations.

Builders evaluate scripts locally by default. Supply current protocol parameters, cost models, resolved inputs, scripts, datums and suitable collateral through the builder configuration. An application can inject its own evaluator or coin selector. See script evaluation and transaction building.

When a redeemer depends on final input or output ordering, use the deferred operations such as Plan.spendWithDeferredRedeemer. The callback receives the balanced draft and may run repeatedly; keep its result deterministic. The deferred redeemer example and connected self-index and batch recipes show how to derive actual indexes instead of assuming them.

Staking and Conway governance

Staking certificates, reward withdrawals, DRep registration, voting delegation, proposals and votes compose with payments in the same plan. For example, delegate an existing stake credential's voting power to abstention and cast a DRep vote on a supplied governance action:

import qualified Cometa.Certificate as Certificate
import qualified Cometa.Credential as Credential
import qualified Cometa.Governance.ActionId as ActionId
import qualified Cometa.Governance.DRep as DRep
import qualified Cometa.Governance.Voting as Voting

abstainDelegation :: Credential.Credential Credential.Stake -> Plan.Plan
abstainDelegation stake =
  Plan.certificate (Certificate.VoteDelegation stake DRep.AlwaysAbstain)

voteYes :: Credential.Credential Credential.DRep -> ActionId.ActionId -> Plan.Plan
voteYes drep action =
  Plan.vote (Voting.DRepVoter drep) action
    (Voting.VotingProcedure Voting.Yes Nothing)

Registration deposits and deregistration refunds are explicit certificate values. Plan.withdraw withdraws staking rewards, Plan.donate donates to the treasury, and Plan.propose adds a governance action with a return account and metadata anchor. Use Plan.proposeWithRedeemer or Plan.proposeWithDeferredRedeemer for a custom guardrails argument. Plan.currentTreasuryValue declares a treasury balance without transferring funds. Proposal deposits come from the protocol snapshot. Ledger registration, reward balances, action eligibility and required signing authorities must match the target network's state.

The staking and governance guide links complete key- and script-authorized registration, delegation, reward withdrawal, DRep, proposal and vote workflows, including cleanup stages.

Dijkstra guards, account deposits and batches

Dijkstra features require a network that has activated the corresponding ledger rules. An offline build does not establish network acceptance. The connected Plutus V4 example checks for protocol 12 or later before funding its workflow.

Guards authorize a transaction with a key or script. Direct deposits transfer lovelace to reward accounts without creating a UTxO; balance constraints express requirements on those accounts:

import qualified Cometa.Address.Reward as Reward
import qualified Cometa.Transaction.Fields as Fields

guardedDeposit :: Credential.Credential Credential.Guard
  -> Reward.RewardAddress -> Plan.Plan
guardedDeposit guard account =
  Plan.requireGuard guard
    <> Plan.directDeposit account 1000000
    <> Plan.startingAccountBalance account (Fields.ExactBalance 2000000)
    <> Plan.accountBalance account (Fields.BalanceRange (Just 3000000) Nothing)

For a Plutus guard, use Plan.guardWithRedeemer and attach its script. Plutus V4 guards can inspect the enclosing batch. See the full account and governance example.

Fee-free subtransactions can be built and signed independently, then attached to an enclosing transaction with their resolved inputs. The enclosing builder funds net deficits, balances change and supplies fees and collateral:

import qualified Cometa.Crypto.Ed25519.SigningKey as Key
import qualified Cometa.SubTransaction.Builder as SubBuilder
import qualified Cometa.SubTransaction.Plan as SubPlan
import qualified Cometa.Transaction.Signing as Signing

buildSignedBatch :: Key.SigningKey -> SubBuilder.Config -> Builder.Config
  -> Utxo.Utxo -> Output.Output -> IO (Either Error Tx.Transaction)
buildSignedBatch key localConfig outerConfig funding payment = runExceptT $ do
  let intent = SubPlan.spend funding <> SubPlan.payTo payment
  local <- ExceptT (SubBuilder.build localConfig intent)
  signedIntent <- ExceptT (Signing.signSubTransaction key local)
  let plan = Plan.attachSubTransaction signedIntent (SubPlan.resolvedInputs intent)
  batch <- ExceptT (Builder.build outerConfig plan)
  ExceptT (Signing.sign key batch)

Use matching Dijkstra protocol parameters and slot schedules in both configurations. outerConfig supplies an independent fee-payer UTxO through Builder.availableUtxos; inputs spent at different levels must be disjoint. This example signs both levels with one open key. Independent parties can sign their own intents before a batcher attaches them. Attaching an intent preserves its exact bytes and signatures. Complete workflows:

More examples

Task Example
Addresses and credentials Addresses.hs
CBOR and exact transaction encodings Cbor.hs, Transactions.hs
Plutus data and script parameters PlutusData.hs, Scripts.hs
CIP-8 message signing MessageSigning.hs
Transaction JSON inspection TransactionInspection.hs
Custom providers, evaluators and selection Providers.hs, Evaluation.hs, CoinSelection.hs

Offline examples use synthetic inputs or public fixtures and do not submit transactions. Connected runners document their required network state and take an explicit --submit argument. Build and test the checkout with:

cabal build all
cabal test all --test-show-details=direct
cabal haddock all

License

Cometa.hs is licensed under the Apache License 2.0. See LICENSE.