@hydra-sdk/core
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
Random mnemonic phrase separated by spaces
AppWallet.getAccount(accountIndex?: number, keyIndex?: number) → Account
Get account information with derived keys and addresses.
Parameters:
accountIndex?(number): Account index (per BIP-44). Default: 0keyIndex?(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 keystakeKey: Staking keyaccountIndex: Account indexaddressIndex: Address index
AppWallet.getPaymentAddress(accountIndex?: number, keyIndex?: number) → string
Get the base payment address (including staking).
Parameters:
accountIndex?(number): Account index. Default: 0keyIndex?(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: 0keyIndex?(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: 0keyIndex?(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 formatpartialSign?(boolean): If true, perform partial signing. Default: falseaccountIndex?(number): Account index. Default: 0keyIndex?(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 formatpartialSign?(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).
Parameters:
address(string): Cardano address (bech32)payload(string): Data to signaccountIndex?(number): Account index. Default: 0keyIndex?(number): Address index. Default: 0
Example:
const signature = await wallet.signData(
'addr_test1qz2fxv2umyhttkxyxp8x0...',
'Hello World',
0,
0
)
console.log('Data signature:', signature)
// => { signature: '...', key: '...' }
Returns: Promise<{ signature: string; key: string }>
signature: Signature in hex formatkey: 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)
Returns: string
Mnemonic phrase
EmbeddedWallet.mnemonicToPrivateKeyHex(words: string[], password?: string) → string
Convert mnemonic to private key hex.
Parameters:
words(string): Array of mnemonic wordspassword?(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: Testnet1: Mainnet
CardanoCliWallet.signTx(txCbor: string, partialSign?: boolean) → Promise<string>
Sign a transaction.
Parameters:
txCbor(string): Transaction in CBOR hex formatpartialSign?(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
})
Utility Functions
getPubkeyHashFromAddress(address: string) → string
Extract public key hash from a Cardano address.
Parameters:
address(string): Cardano address (bech32)
Example:
import { getPubkeyHashFromAddress } from '@hydra-sdk/core'
const pubkeyHash = getPubkeyHashFromAddress('addr_test1qz2fxv2umyhttkxyxp8x0...')
console.log('Public key hash:', pubkeyHash)
// => "00000000000000000000000000000000000000000000000000000000"
Returns: string
Public key hash in hex format
isValidAddress(address: string) → boolean
Check if a Cardano address is valid.
Parameters:
address(string): Address to verify
Example:
import { isValidAddress } from '@hydra-sdk/core'
const isValid = isValidAddress('addr_test1qz2fxv2umyhttkxyxp8x0...')
console.log('Valid:', isValid) // => true or false
Returns: boolean
True if address is valid, false otherwise
isValidTxOutput(output: any) → boolean
Check if a transaction output is valid.
Parameters:
output(any): Transaction output to verify
Example:
import { isValidTxOutput } from '@hydra-sdk/core'
const isValid = isValidTxOutput(txOutput)
console.log('Output valid:', isValid)
Returns: boolean
True if output is valid
slotToBeginUnixTime(slot: number, config?: SlotConfig) → number
Convert slot number to Unix timestamp (start of slot).
Parameters:
slot(number): Slot numberconfig?(SlotConfig): Optional slot configuration
Example:
import { slotToBeginUnixTime } from '@hydra-sdk/core'
const unixTime = slotToBeginUnixTime(45700800)
console.log('Unix time:', unixTime)
// => 1671292800000 (milliseconds)
Returns: number
Unix timestamp (milliseconds)
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 { unixTimeToEnclosingSlot } from '@hydra-sdk/core'
const slot = unixTimeToEnclosingSlot(Date.now())
console.log('Current slot:', slot)
Returns: number
Slot number enclosing the Unix time
resolveSlotNo(timestamp: number) → string
Resolve slot number based on timestamp (milliseconds).
Parameters:
timestamp(number): Timestamp (milliseconds)
Example:
import { resolveSlotNo } from '@hydra-sdk/core'
const slotNo = resolveSlotNo(Date.now())
console.log('Slot number:', slotNo)
Returns: string
Slot number as string
resolveEpochNo(timestamp: number) → number
Resolve epoch number based on timestamp (milliseconds).
Parameters:
timestamp(number): Timestamp (milliseconds)
Example:
import { resolveEpochNo } from '@hydra-sdk/core'
const epochNo = resolveEpochNo(Date.now())
console.log('Epoch number:', epochNo)
Returns: number
Epoch number
buildHydraSlotConfig(timestamp?: number) → SlotConfig
Build Hydra slot configuration for a specific timestamp.
Parameters:
timestamp?(number): Timestamp (milliseconds). Default: current time
Example:
import { buildHydraSlotConfig } from '@hydra-sdk/core'
const config = buildHydraSlotConfig()
console.log('Slot config:', config)
Returns: SlotConfig
Slot configuration for Hydra
buildPolicyScriptFromPubkey(pubkey: string) → string
Build minting policy script from a public key script.
Parameters:
pubkey(string): Public key hex
Example:
import { buildPolicyScriptFromPubkey } from '@hydra-sdk/core'
const policyScript = buildPolicyScriptFromPubkey('a1b2c3...')
console.log('Policy script:', policyScript)
Returns: string
Policy script in hex format
buildMintingPolicyScriptFromAddress(address: string) → string
Build minting policy script from an address.
Parameters:
address(string): Cardano address (bech32)
Example:
import { buildMintingPolicyScriptFromAddress } from '@hydra-sdk/core'
const policyScript = buildMintingPolicyScriptFromAddress('addr_test1...')
console.log('Policy script:', policyScript)
Returns: string
Policy script in hex format
buildMintingPolicyScriptFromKeyHash(keyHash: string) → string
Build minting policy script from a key hash.
Parameters:
keyHash(string): Key hash in hex
Example:
import { buildMintingPolicyScriptFromKeyHash } from '@hydra-sdk/core'
const policyScript = buildMintingPolicyScriptFromKeyHash('a1b2c3...')
console.log('Policy script:', policyScript)
Returns: string
Policy script in hex format
policyIdFromNativeScript(nativeScript: string) → string
Extract policy ID from a native script.
Parameters:
nativeScript(string): Native script in hex format
Example:
import { policyIdFromNativeScript } from '@hydra-sdk/core'
const policyId = 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
metadataObjToMetadatum(obj: any) → TransactionMetadatum
Convert metadata object to CardanoWASM.TransactionMetadatum.
Note:
- Maximum metadata
bytessize: 64 bytes - Maximum metadata
textsize: 64 characters
Parameters:
obj(any): Metadata object
Example:
import { metadataObjToMetadatum } from '@hydra-sdk/core'
const metadata = metadataObjToMetadatum({
'1': 'Hello',
'2': 12345
})
console.log('Metadata:', metadata)
Returns: TransactionMetadatum
Metadata in CardanoWASM format
cardanoCliKeygen() → { sk: CardanoCLiSkey; vk: CardanoCLiVkey }
Generate ed25519 key pair compatible with Cardano CLI.
Example:
import { cardanoCliKeygen } from '@hydra-sdk/core'
const { sk, vk } = 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 formatvk.cborHex: Verification key in CBOR hex format
hydraCliKeygen() → { sk: object; vk: object }
Generate ed25519 key pair compatible with Hydra CLI.
Example:
import { hydraCliKeygen } from '@hydra-sdk/core'
const { sk, vk } = hydraCliKeygen()
console.log('Secret Key:', sk)
console.log('Verification Key:', vk)
Returns: { sk: object; vk: object }
Hydra key pair
genVkey(sk: CardanoCLiSkey) → CardanoCLiVkey
Generate verification key from signing key.
Parameters:
sk(CardanoCLiSkey): Signing key
Example:
import { genVkey, cardanoCliKeygen } from '@hydra-sdk/core'
const { sk } = cardanoCliKeygen()
const vk = genVkey(sk)
console.log('Verification Key:', vk.cborHex)
Returns: CardanoCLiVkey
Verification key
mkInt(value: number | bigint) → PlutusData
Create PlutusData from an integer.
Parameters:
value(number | bigint): Integer value
Example:
import { mkInt } from '@hydra-sdk/core'
const plutusInt = mkInt(42)
console.log('PlutusData:', plutusInt)
Returns: PlutusData
PlutusData representing an integer
mkBytes(hex: string) → PlutusData
Create PlutusData from hex string representing bytes.
Parameters:
hex(string): Hex string
Example:
import { mkBytes } from '@hydra-sdk/core'
const plutusBytes = mkBytes('a1b2c3')
console.log('PlutusData:', plutusBytes)
Returns: PlutusData
PlutusData representing bytes
mkConstr(index: number, fields: PlutusData[]) → PlutusData
Create PlutusData constructor.
Parameters:
index(number): Constructor indexfields(PlutusData): Array of PlutusData fields
Example:
import { mkConstr, mkInt } from '@hydra-sdk/core'
const constr = mkConstr(0, [mkInt(1), mkInt(2)])
console.log('Constructor:', constr)
Returns: PlutusData
PlutusData constructor
mkMap(pairs: [PlutusData, PlutusData][]) → PlutusData
Create PlutusData map.
Parameters:
pairs([PlutusData, PlutusData]): Array of key-value pairs
Example:
import { mkMap, mkInt, mkBytes } from '@hydra-sdk/core'
const map = mkMap([
[mkInt(1), mkBytes('a1b2')],
[mkInt(2), mkBytes('c3d4')]
])
console.log('Map:', map)
Returns: PlutusData
PlutusData map
buildCostModels() → Costmdls
Build cost models for Cardano.
Example:
import { buildCostModels } from '@hydra-sdk/core'
const costModels = buildCostModels()
console.log('Cost Models:', costModels)
Returns: Costmdls
Cost models
Constants
NETWORK_ID
Network ID constants for different Cardano networks.
Example:
import { NETWORK_ID } from '@hydra-sdk/core'
// Available network IDs
NETWORK_ID.TESTNET // 0
NETWORK_ID.PREPROD // 0
NETWORK_ID.MAINNET // 1
Related Documentation
- Transaction Builder API - Build transactions
- Hydra Bridge API - Hydra Layer 2 integration
