API Reference

@hydra-sdk/core

Core Cardano wallet API with comprehensive utilities

Functions


AppWallet

AppWallet.brew(strength?: number) → string[]

Generate a new random mnemonic phrase for a new Cardano wallet.

Parameters:

  • strength? (number): Mnemonic strength (128 = 12 words, 160 = 15 words, 256 = 24 words). Default: 256 (24 words)

Example:

import { AppWallet } from '@hydra-sdk/core'

// Generate 24-word mnemonic (default)
const mnemonic24 = AppWallet.brew(256)

// Generate 12-word mnemonic
const mnemonic12 = AppWallet.brew(128)

// Generate 15-word mnemonic
const mnemonic15 = AppWallet.brew(160)

console.log('New mnemonic:', mnemonic24)
// => ['abandon', 'abandon', ..., 'zone']

Returns: string[]
Array of mnemonic words


AppWallet.getAccount(accountIndex?: number, keyIndex?: number) → Account

Get account information with derived keys and addresses.

Parameters:

  • accountIndex? (number): Account index (per BIP-44). Default: 0
  • keyIndex? (number): Address index. Default: 0

Example:

import { AppWallet, NETWORK_ID, ProviderUtils } from '@hydra-sdk/core'

const blockfrostProvider = new ProviderUtils.BlockfrostProvider({
  apiKey: 'your-blockfrost-api-key',
  network: 'preprod'
})

const wallet = new AppWallet({
  networkId: NETWORK_ID.PREPROD,
  key: { type: 'mnemonic', words: ['word1', 'word2', ...] },
  fetcher: blockfrostProvider.fetcher,
  submitter: blockfrostProvider.submitter
})

// Get first account (account 0, address 0)
const account = wallet.getAccount(0, 0)

console.log({
  // Address information
  baseAddressBech32: account.baseAddressBech32,
  enterpriseAddressBech32: account.enterpriseAddressBech32,
  rewardAddressBech32: account.rewardAddressBech32,
  
  // Key information
  paymentKey: account.paymentKey,
  stakeKey: account.stakeKey,
  
  // Indices
  accountIndex: account.accountIndex,
  addressIndex: account.addressIndex
})

// Default: account 0, address 0
const defaultAccount = wallet.getAccount()

Returns: Account

  • baseAddressBech32: Base address (payment + staking)
  • enterpriseAddressBech32: Enterprise address (payment only)
  • rewardAddressBech32: Reward address (staking only)
  • paymentKey: Payment key
  • stakeKey: Staking key
  • accountIndex: Account index
  • addressIndex: Address index

AppWallet.getPaymentAddress(accountIndex?: number, keyIndex?: number) → string

Get the base payment address (including staking).

Parameters:

  • accountIndex? (number): Account index. Default: 0
  • keyIndex? (number): Address index. Default: 0

Example:

const baseAddr = wallet.getPaymentAddress(0, 0)
console.log('Base address:', baseAddr)
// => "addr_test1qz2fxv2umyhttkxyxp8x0..."

Returns: string
Base address in bech32 format


AppWallet.getEnterpriseAddress(accountIndex?: number, keyIndex?: number) → string

Get the enterprise address (payment only, no staking).

Parameters:

  • accountIndex? (number): Account index. Default: 0
  • keyIndex? (number): Address index. Default: 0

Example:

const enterpriseAddr = wallet.getEnterpriseAddress(0, 0)
console.log('Enterprise address:', enterpriseAddr)
// => "addr_test1vz2fxv2umyhttkxyxp8x0..."

Returns: string
Enterprise address in bech32 format


AppWallet.getRewardAddress(accountIndex?: number, keyIndex?: number) → string

Get the reward address (staking only).

Parameters:

  • accountIndex? (number): Account index. Default: 0
  • keyIndex? (number): Address index. Default: 0

Example:

const rewardAddr = wallet.getRewardAddress(0, 0)
console.log('Reward address:', rewardAddr)
// => "stake_test1uqz2fxv2umyhttkxyxp8x0..."

Returns: string
Reward address in bech32 format


AppWallet.getNetworkId() → number

Get the current network ID of the wallet.

Example:

const networkId = wallet.getNetworkId()
console.log('Network ID:', networkId)
// => 0 (Preprod testnet) or 1 (Mainnet)

Returns: number

  • 0: Testnet (Preprod)
  • 1: Mainnet

AppWallet.signTx(txCbor: string, partialSign?: boolean, accountIndex?: number, keyIndex?: number) → Promise<string>

Sign a Cardano transaction. Supports full or partial signing (multi-sig).

Parameters:

  • txCbor (string): Transaction in CBOR hex format
  • partialSign? (boolean): If true, perform partial signing. Default: false
  • accountIndex? (number): Account index. Default: 0
  • keyIndex? (number): Address index. Default: 0

Example:

// Full signing
const signedTx = await wallet.signTx(unsignedTxCbor, false, 0, 0)

// Partial signing (multi-sig)
const partialSigned = await wallet.signTx(unsignedTxCbor, true, 0, 0)

console.log('Signed transaction:', signedTx)

Returns: Promise<string>
Signed transaction in CBOR hex format


AppWallet.signTxs(txCbors: string[], partialSign?: boolean) → Promise<string[]>

Sign multiple transactions at once.

Parameters:

  • txCbors (string): Array of transactions in CBOR hex format
  • partialSign? (boolean): If true, perform partial signing. Default: false

Example:

const signedTxs = await wallet.signTxs(
  [txCbor1, txCbor2, txCbor3],
  false
)

console.log('Signed transactions:', signedTxs)

Returns: Promise<string[]>
Array of signed transactions in CBOR hex format


AppWallet.signData(address: string, payload: string, accountIndex?: number, keyIndex?: number) → Promise<{ signature: string; key: string }>

Sign arbitrary data according to CIP-8 (Cardano Improvement Proposal).

Not implemented on AppWallet. Calling AppWallet.signData() throws [AppWallet] signData() is not implemented. Only EmbeddedWallet.signData() actually signs data — it has the same signature and returns { signature, key }.

Parameters:

  • address (string): Cardano address (bech32)
  • payload (string): Data to sign
  • accountIndex? (number): Account index. Default: 0
  • keyIndex? (number): Address index. Default: 0

Example:

import { EmbeddedWallet } from '@hydra-sdk/core'

// AppWallet.signData() throws — use EmbeddedWallet.signData() instead
const signature = await embeddedWallet.signData(
  'addr_test1qz2fxv2umyhttkxyxp8x0...',
  'Hello World',
  0,
  0
)

console.log('Data signature:', signature)
// => { signature: '...', key: '...' }

Returns: Promise<{ signature: string; key: string }>

  • signature: Signature in hex format
  • key: Public key in hex format

AppWallet.submitTx(signedTxCbor: string) → Promise<string>

Submit a signed transaction to the blockchain.

Parameters:

  • signedTxCbor (string): Signed transaction in CBOR hex format

Example:

const txHash = await wallet.submitTx(signedTxCbor)
console.log('Transaction hash:', txHash)
// => "a1b2c3d4e5f6..."

Returns: Promise<string>
Transaction hash


AppWallet.queryUTxOs(address: string) → Promise<UTxO[]>

Query UTxOs (Unspent Transaction Outputs) for an address.

Parameters:

  • address (string): Cardano address (bech32)

Example:

const address = wallet.getPaymentAddress()
const utxos = await wallet.queryUTxOs(address)

console.log('UTxOs:', utxos)
// => [{ input: { txHash: '...', index: 0 }, output: { address: '...', amount: [...] } }, ...]

Returns: Promise<UTxO[]>
Array of UTxOs for the address


EmbeddedWallet

Low-level wallet implementation used internally by AppWallet.

EmbeddedWallet.generateMnemonic(strength?: number) → string[]

Generate a mnemonic phrase.

Parameters:

  • strength? (number): Mnemonic strength (128/160/256). Default: 256

Example:

import { EmbeddedWallet } from '@hydra-sdk/core'

const mnemonic = EmbeddedWallet.generateMnemonic(256)
console.log('Mnemonic:', mnemonic)
// => ['abandon', 'abandon', ..., 'zone']

Returns: string[]
Array of mnemonic words


EmbeddedWallet.mnemonicToPrivateKeyHex(words: string[], password?: string) → string

Convert mnemonic to private key hex.

Parameters:

  • words (string): Array of mnemonic words
  • password? (string): Optional password

Example:

const privateKeyHex = EmbeddedWallet.mnemonicToPrivateKeyHex(
  ['abandon', 'abandon', ...],
  ''
)
console.log('Private key:', privateKeyHex)

Returns: string
Private key in hex format


EmbeddedWallet.privateKeyHexToBech32(privateKeyHex: string) → string

Convert private key hex to bech32.

Parameters:

  • privateKeyHex (string): Private key in hex format

Example:

const bech32Key = EmbeddedWallet.privateKeyHexToBech32(privateKeyHex)
console.log('Bech32 key:', bech32Key)

Returns: string
Private key in bech32 format (xprv)


EmbeddedWallet.privateKeyBech32ToPrivateKeyHex(bech32Key: string) → string

Convert private key bech32 to hex.

Parameters:

  • bech32Key (string): Private key in bech32 format

Example:

const hexKey = EmbeddedWallet.privateKeyBech32ToPrivateKeyHex('xprv1...')
console.log('Hex key:', hexKey)

Returns: string
Private key in hex format


CardanoCliWallet

Wallet class for working with keys created by Cardano CLI. Useful for server-side applications.

CardanoCliWallet.getAddressBech32() → string

Get wallet address in bech32 format.

Example:

import { CardanoCliWallet, NETWORK_ID, ProviderUtils } from '@hydra-sdk/core'

const blockfrostProvider = new ProviderUtils.BlockfrostProvider({
  apiKey: 'your-blockfrost-api-key',
  network: 'preprod'
})

const cliWallet = new CardanoCliWallet({
  networkId: NETWORK_ID.PREPROD,
  skey: '5820245120cdf333f8ea6910922b3f05bcbc0d5c8e8486ca94c020623d5cca822e04',
  vkey: '5820216f72947d1b97d56825c5f9f8a2e6f14234c02171853264f2f552a2685b25e0',
  fetcher: blockfrostProvider.fetcher,
  submitter: blockfrostProvider.submitter
})

const address = cliWallet.getAddressBech32()
console.log('Wallet address:', address)

Returns: string
Address in bech32 format


CardanoCliWallet.getNetworkId() → number

Get current network ID.

Example:

const networkId = cliWallet.getNetworkId()
console.log('Network ID:', networkId) // 0 or 1

Returns: number

  • 0: Testnet
  • 1: Mainnet

CardanoCliWallet.signTx(txCbor: string, partialSign?: boolean) → Promise<string>

Sign a transaction.

Parameters:

  • txCbor (string): Transaction in CBOR hex format
  • partialSign? (boolean): Perform partial signing. Default: false

Example:

const signedTx = await cliWallet.signTx(unsignedTxCbor, false)
console.log('Signed transaction:', signedTx)

Returns: Promise<string>
Signed transaction in CBOR hex format


CardanoCliWallet.submitTx(txCbor: string) → Promise<string>

Submit signed transaction to blockchain.

Parameters:

  • txCbor (string): Signed transaction in CBOR hex format

Example:

const txHash = await cliWallet.submitTx(signedTxCbor)
console.log('Transaction hash:', txHash)

Returns: Promise<string>
Transaction hash


CardanoCliWallet.queryUTxOs(address: string) → Promise<UTxO[]>

Query UTxOs for an address.

Parameters:

  • address (string): Cardano address

Example:

const address = cliWallet.getAddressBech32()
const utxos = await cliWallet.queryUTxOs(address)
console.log('UTxOs:', utxos)

Returns: Promise<UTxO[]>
Array of UTxOs


Provider Classes

BlockfrostProvider

Blockfrost provider for querying blockchain data.

Constructor:

import { ProviderUtils } from '@hydra-sdk/core'

const blockfrostProvider = new ProviderUtils.BlockfrostProvider({
  apiKey: 'your-blockfrost-api-key',
  network: 'preprod' // or 'mainnet'
})

// Access fetcher and submitter
const fetcher = blockfrostProvider.fetcher
const submitter = blockfrostProvider.submitter

// Use with wallet
const wallet = new AppWallet({
  networkId: NETWORK_ID.PREPROD,
  key: { type: 'mnemonic', words: mnemonic },
  fetcher: blockfrostProvider.fetcher,
  submitter: blockfrostProvider.submitter
})

OgmiosProvider

Ogmios provider for querying blockchain data.

Constructor:

import { ProviderUtils } from '@hydra-sdk/core'

const ogmiosProvider = new ProviderUtils.OgmiosProvider({
  apiEndpoint: 'https://preprod.cardano-rpc.hydrawallet.app',
  network: 'preprod' // or 'mainnet'
})

// Access fetcher and submitter
const fetcher = ogmiosProvider.fetcher
const submitter = ogmiosProvider.submitter

// Use with wallet
const wallet = new AppWallet({
  networkId: NETWORK_ID.PREPROD,
  key: { type: 'mnemonic', words: mnemonic },
  fetcher: ogmiosProvider.fetcher,
  submitter: ogmiosProvider.submitter
})

DemeterProvider

Provider for Demeter's Blockfrost-compatible hosted endpoints. Extends BlockfrostProvider, so it exposes the same fetcher/submitter surface. Authentication is embedded in the endpoint subdomain via authToken.

Constructor:

import { ProviderUtils } from '@hydra-sdk/core'

const demeterProvider = new ProviderUtils.DemeterProvider({
  authToken: 'blockfrost102lx3ckhzvkjjh7677g',
  network: 'preprod' // 'mainnet' | 'preprod' | 'preview'
})

// Same fetcher / submitter interface as BlockfrostProvider
const utxos = await demeterProvider.fetcher.fetchAddressUTxOs(address)

// Use with wallet
const wallet = new AppWallet({
  networkId: NETWORK_ID.PREPROD,
  key: { type: 'mnemonic', words: mnemonic },
  fetcher: demeterProvider.fetcher,
  submitter: demeterProvider.submitter
})

The endpoint is built as https://{authToken}.cardano-{network}.blockfrost-m1.demeter.run/api/v{apiVersion ?? 0}.


Utility Functions

AddressUtils.getPubkeyHashFromAddress(address: string) → string

Extract public key hash from a Cardano address.

Parameters:

  • address (string): Cardano address (bech32)

Example:

import { AddressUtils } from '@hydra-sdk/core'

const pubkeyHash = AddressUtils.getPubkeyHashFromAddress('addr_test1qz2fxv2umyhttkxyxp8x0...')
console.log('Public key hash:', pubkeyHash)
// => "00000000000000000000000000000000000000000000000000000000"

Returns: string
Public key hash in hex format


AddressUtils.isValidAddress(address: string | Uint8Array, type?: 'bech32' | 'hex' | 'bytes') → boolean

Check if a Cardano address is valid. type defaults to 'bech32'.

Parameters:

  • address (string | Uint8Array): Address to verify
  • type? ('bech32' | 'hex' | 'bytes'): Input encoding. Default: 'bech32'

Example:

import { AddressUtils } from '@hydra-sdk/core'

const isValid = AddressUtils.isValidAddress('addr_test1qz2fxv2umyhttkxyxp8x0...')
console.log('Valid:', isValid) // => true or false

Returns: boolean
True if address is valid, false otherwise


ValidationUtils.isValidTxOutput(output: TxOutput) → boolean

Check if a transaction output is valid.

Parameters:

  • output (TxOutput): Transaction output to verify

Example:

import { ValidationUtils } from '@hydra-sdk/core'

const isValid = ValidationUtils.isValidTxOutput(txOutput)
console.log('Output valid:', isValid)

Returns: boolean
True if output is valid


TimeUtils.slotToBeginUnixTime(slot: number, config?: SlotConfig) → number

Convert slot number to Unix timestamp (start of slot).

Parameters:

  • slot (number): Slot number
  • config? (SlotConfig): Optional slot configuration

Example:

import { TimeUtils } from '@hydra-sdk/core'

const unixTime = TimeUtils.slotToBeginUnixTime(45700800)
console.log('Unix time:', unixTime)
// => 1671292800000 (milliseconds)

Returns: number
Unix timestamp (milliseconds)


TimeUtils.unixTimeToEnclosingSlot(unixTime: number, config?: SlotConfig) → number

Convert Unix timestamp to enclosing slot number.

Parameters:

  • unixTime (number): Unix timestamp (milliseconds)
  • config? (SlotConfig): Optional slot configuration

Example:

import { TimeUtils, SLOT_CONFIG_NETWORK } from '@hydra-sdk/core'

const slot = TimeUtils.unixTimeToEnclosingSlot(Date.now(), SLOT_CONFIG_NETWORK.PREPROD)
console.log('Current slot:', slot)

Returns: number
Slot number enclosing the Unix time


TimeUtils.resolveSlotNo(network: Network, milliseconds?: number) → string

Resolve slot number for a network at a given time.

Parameters:

  • network (Network): Target network ('MAINNET' | 'PREPROD' | 'PREVIEW')
  • milliseconds? (number): Timestamp in milliseconds. Default: Date.now()

Example:

import { TimeUtils } from '@hydra-sdk/core'

const slotNo = TimeUtils.resolveSlotNo('PREPROD')
console.log('Slot number:', slotNo)

Returns: string
Slot number as string


TimeUtils.resolveEpochNo(network: Network, milliseconds?: number) → number

Resolve epoch number for a network at a given time.

Parameters:

  • network (Network): Target network ('MAINNET' | 'PREPROD' | 'PREVIEW')
  • milliseconds? (number): Timestamp in milliseconds. Default: Date.now()

Example:

import { TimeUtils } from '@hydra-sdk/core'

const epochNo = TimeUtils.resolveEpochNo('PREPROD')
console.log('Epoch number:', epochNo)

Returns: number
Epoch number


TimeUtils.buildHydraSlotConfig(startTimestamp: number, options?: object) → SlotConfig

Build Hydra slot configuration anchored at a Head start timestamp.

Parameters:

  • startTimestamp (number): Head start timestamp in milliseconds (required)
  • options? (object): Optional overrides for the slot configuration

Example:

import { TimeUtils } from '@hydra-sdk/core'

const config = TimeUtils.buildHydraSlotConfig(Date.now())
console.log('Slot config:', config)

Returns: SlotConfig
Slot configuration for Hydra


PolicyUtils.buildPolicyScriptFromPubkey(pubkey: string) → string

Build minting policy script from a public key script.

Parameters:

  • pubkey (string): Public key hex

Example:

import { PolicyUtils } from '@hydra-sdk/core'

const policyScript = PolicyUtils.buildPolicyScriptFromPubkey('a1b2c3...')
console.log('Policy script:', policyScript)

Returns: string
Policy script in hex format


PolicyUtils.buildMintingPolicyScriptFromAddress(address: string) → string

Build minting policy script from an address.

Parameters:

  • address (string): Cardano address (bech32)

Example:

import { PolicyUtils } from '@hydra-sdk/core'

const policyScript = PolicyUtils.buildMintingPolicyScriptFromAddress('addr_test1...')
console.log('Policy script:', policyScript)

Returns: string
Policy script in hex format


PolicyUtils.buildMintingPolicyScriptFromKeyHash(keyHash: string) → string

Build minting policy script from a key hash.

Parameters:

  • keyHash (string): Key hash in hex

Example:

import { PolicyUtils } from '@hydra-sdk/core'

const policyScript = PolicyUtils.buildMintingPolicyScriptFromKeyHash('a1b2c3...')
console.log('Policy script:', policyScript)

Returns: string
Policy script in hex format


PolicyUtils.policyIdFromNativeScript(nativeScript: string) → string

Extract policy ID from a native script.

Parameters:

  • nativeScript (string): Native script in hex format

Example:

import { PolicyUtils } from '@hydra-sdk/core'

const policyId = PolicyUtils.policyIdFromNativeScript(nativeScriptHex)
console.log('Policy ID:', policyId)

Returns: string
Policy ID in hex format


bytesToHex(bytes: Uint8Array) → string

Convert bytes to hex string.

Parameters:

  • bytes (Uint8Array): Byte data

Example:

import { bytesToHex } from '@hydra-sdk/core'

const hexString = bytesToHex(new Uint8Array([1, 2, 3]))
console.log('Hex:', hexString) // => "010203"

Returns: string
Hex string


hexToBytes(hex: string) → Uint8Array

Convert hex string to bytes.

Parameters:

  • hex (string): Hex string

Example:

import { hexToBytes } from '@hydra-sdk/core'

const bytes = hexToBytes('010203')
console.log('Bytes:', bytes) // => Uint8Array [ 1, 2, 3 ]

Returns: Uint8Array
Byte data


stringToHex(str: string) → string

Convert UTF-8 string to hex string.

Parameters:

  • str (string): UTF-8 string

Example:

import { stringToHex } from '@hydra-sdk/core'

const hex = stringToHex('Hello')
console.log('Hex:', hex) // => "48656c6c6f"

Returns: string
Hex string


hexToString(hex: string) → string

Convert hex string to UTF-8 string.

Parameters:

  • hex (string): Hex string

Example:

import { hexToString } from '@hydra-sdk/core'

const str = hexToString('48656c6c6f')
console.log('String:', str) // => "Hello"

Returns: string
UTF-8 string


toBytes(data: string | Uint8Array) → Uint8Array

Convert hex string or UTF-8 string to bytes.

Parameters:

  • data (string | Uint8Array): Hex string or UTF-8 string

Example:

import { toBytes } from '@hydra-sdk/core'

const bytes1 = toBytes('48656c6c6f')
const bytes2 = toBytes('Hello')

Returns: Uint8Array
Byte data


fromUTF8(str: string) → string

Convert UTF-8 string to hex string.

Parameters:

  • str (string): UTF-8 string

Example:

import { fromUTF8 } from '@hydra-sdk/core'

const hex = fromUTF8('Hello')
console.log('Hex:', hex)

Returns: string
Hex string


toUTF8(hex: string) → string

Convert hex string to UTF-8 string.

Parameters:

  • hex (string): Hex string

Example:

import { toUTF8 } from '@hydra-sdk/core'

const str = toUTF8('48656c6c6f')
console.log('String:', str)

Returns: string
UTF-8 string


MetadataUtils.metadataObjToMetadatum(obj: any) → TransactionMetadatum

Convert metadata object to CardanoWASM.TransactionMetadatum.

Note:

  • Maximum metadata bytes size: 64 bytes
  • Maximum metadata text size: 64 characters

Parameters:

  • obj (any): Metadata object

Example:

import { MetadataUtils } from '@hydra-sdk/core'

const metadata = MetadataUtils.metadataObjToMetadatum({
  '1': 'Hello',
  '2': 12345
})
console.log('Metadata:', metadata)

Returns: TransactionMetadatum
Metadata in CardanoWASM format


KeysUtils.cardanoCliKeygen() → { sk: CardanoCLiSkey; vk: CardanoCLiVkey }

Generate ed25519 key pair compatible with Cardano CLI.

Example:

import { KeysUtils } from '@hydra-sdk/core'

const { sk, vk } = KeysUtils.cardanoCliKeygen()
console.log('Secret Key (cborHex):', sk.cborHex)
console.log('Verification Key (cborHex):', vk.cborHex)

Returns: { sk: CardanoCLiSkey; vk: CardanoCLiVkey }

  • sk.cborHex: Signing key in CBOR hex format
  • vk.cborHex: Verification key in CBOR hex format

KeysUtils.hydraCliKeygen() → { sk: HydraCliSkey; vk: HydraCliVkey }

Generate ed25519 key pair compatible with Hydra CLI.

Example:

import { KeysUtils } from '@hydra-sdk/core'

const { sk, vk } = KeysUtils.hydraCliKeygen()
console.log('Secret Key:', sk)
console.log('Verification Key:', vk)

Returns: { sk: object; vk: object }
Hydra key pair


KeysUtils.genVkey(sk: CardanoCLiSkey) → CardanoCLiVkey

Generate verification key from signing key.

Parameters:

  • sk (CardanoCLiSkey): Signing key

Example:

import { KeysUtils } from '@hydra-sdk/core'

const { sk } = KeysUtils.cardanoCliKeygen()
const vk = KeysUtils.genVkey(sk)
console.log('Verification Key:', vk.cborHex)

Returns: CardanoCLiVkey
Verification key


DatumUtils.mkInt(value: number | bigint) → PlutusData

Create PlutusData from an integer.

Parameters:

  • value (number | bigint): Integer value

Example:

import { DatumUtils } from '@hydra-sdk/core'

const plutusInt = DatumUtils.mkInt(42)
console.log('PlutusData:', plutusInt)

Returns: PlutusData
PlutusData representing an integer


DatumUtils.mkBytes(hex: string) → PlutusData

Create PlutusData from hex string representing bytes.

Parameters:

  • hex (string): Hex string

Example:

import { DatumUtils } from '@hydra-sdk/core'

const plutusBytes = DatumUtils.mkBytes('a1b2c3')
console.log('PlutusData:', plutusBytes)

Returns: PlutusData
PlutusData representing bytes


DatumUtils.mkConstr(index: number, fields: PlutusData[]) → PlutusData

Create PlutusData constructor.

Parameters:

  • index (number): Constructor index
  • fields (PlutusData): Array of PlutusData fields

Example:

import { DatumUtils } from '@hydra-sdk/core'

const constr = DatumUtils.mkConstr(0, [DatumUtils.mkInt(1), DatumUtils.mkInt(2)])
console.log('Constructor:', constr)

Returns: PlutusData
PlutusData constructor


DatumUtils.mkMap(pairs: [PlutusData, PlutusData][]) → PlutusData

Create PlutusData map.

Parameters:

  • pairs ([PlutusData, PlutusData]): Array of key-value pairs

Example:

import { DatumUtils } from '@hydra-sdk/core'

const map = DatumUtils.mkMap([
  [DatumUtils.mkInt(1), DatumUtils.mkBytes('a1b2')],
  [DatumUtils.mkInt(2), DatumUtils.mkBytes('c3d4')]
])
console.log('Map:', map)

Returns: PlutusData
PlutusData map


CostModels.buildCostModels(models: { plutusV1?: number[]; plutusV2?: number[]; plutusV3?: number[] }) → Costmdls

Build cost models for Cardano. At least one of plutusV1 / plutusV2 / plutusV3 must be provided, otherwise it throws At least one cost model must be provided. For zero-config defaults use CostModels.defaultCostModels.

Parameters:

  • models (object): Cost model lists keyed by Plutus language version

Example:

import { CostModels } from '@hydra-sdk/core'

// Ready-made defaults (all three Plutus versions)
const defaults = CostModels.defaultCostModels

// Or build from explicit cost model lists
const costModels = CostModels.buildCostModels({
  plutusV3: [/* ...cost model integers... */]
})
console.log('Cost Models:', costModels)

Returns: Costmdls
Cost models


UTxO Conversion Utilities

convertUTxOObjectToUTxO(utxoObject: UTxOObject) → UTxO[]

Convert a UTxO object (snapshot format) to an array of UTxO items.

Example:

import { Converter } from '@hydra-sdk/core'

const utxos = Converter.convertUTxOObjectToUTxO(snapshotUtxo)
console.log('UTxO count:', utxos.length)

Returns: UTxO[]


convertUTxOObjectToUTxOWithOptions(utxoObject: UTxOObject, options?: ConvertOptions) → UTxO[]

Same as convertUTxOObjectToUTxO but accepts an options object for fine-tuning the internal datum deserialization cache.

Parameters:

  • utxoObject (UTxOObject): Snapshot UTxO object
  • options?:
    • maxDatumCacheSize? (number): Max number of deserialized PlutusData entries to cache. 0 disables caching. Default: 1024

Why it matters: When processing large snapshots (thousands of UTxOs) containing repeated inline datums, the cache avoids redundant WASM deserialization calls. The LRU eviction policy keeps memory usage bounded.

Example:

import { Converter } from '@hydra-sdk/core'

// Default — cache up to 1024 datum entries
const utxos = Converter.convertUTxOObjectToUTxOWithOptions(snapshotUtxo)

// Larger cache for snapshots with many unique inline datums
const utxos = Converter.convertUTxOObjectToUTxOWithOptions(snapshotUtxo, {
    maxDatumCacheSize: 4096
})

// Disable cache entirely
const utxos = Converter.convertUTxOObjectToUTxOWithOptions(snapshotUtxo, {
    maxDatumCacheSize: 0
})

Returns: UTxO[]


convertUTxOToUTxOObject(utxos: UTxO[]) → UTxOObject

Convert a UTxO[] array back to the snapshot object format.

Example:

import { Converter } from '@hydra-sdk/core'

const utxoObj = Converter.convertUTxOToUTxOObject(utxos)

Returns: UTxOObject


Constants

NETWORK_ID

Network ID constants for different Cardano networks. NETWORK_ID is a Record<Network, number> keyed by MAINNET, PREPROD, and PREVIEW (there is no TESTNET key).

Example:

import { NETWORK_ID } from '@hydra-sdk/core'

// Available network IDs
NETWORK_ID.MAINNET  // 1
NETWORK_ID.PREPROD  // 0
NETWORK_ID.PREVIEW  // 0