Skip to main content

Address Eras

The AddressEras module is a full-spectrum address parser that handles every Cardano address type -- including legacy Byron addresses and deprecated Pointer addresses that the simplified Address module does not cover.

When to Use AddressEras vs Address

FeatureAddressAddressEras
Base addressesYesYes
Enterprise addressesYesYes
Byron addressesNoYes
Pointer addressesNoYes
Reward accountsNoYes
Simplified APIYesNo

Use Address for most application code. Use AddressEras when parsing UTxOs or transactions that may contain legacy formats.

Parsing Any Address

AddressEras.fromBech32 accepts any valid Bech32-encoded Cardano address and returns a discriminated union tagged by _tag:

import { AddressEras } from "@evolution-sdk/evolution"

const addr1 = AddressEras.fromBech32(
"addr_test1vrm9x2dgvdau8vckj4duc89m638t8djmluqw5pdrFollw8qd9k63"
)
const addr2 = AddressEras.fromBech32(
"stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw"
)

// Type narrowing by _tag
if (addr1._tag === "BaseAddress") {
console.log("Payment:", addr1.paymentCredential)
console.log("Stake:", addr1.stakeCredential)
} else if (addr1._tag === "EnterpriseAddress") {
console.log("Payment only:", addr1.paymentCredential)
} else if (addr1._tag === "RewardAccount") {
console.log("Stake credential:", addr1.stakeCredential)
}

The Five Address Types

AddressEras is a union of all five Cardano address types:

_tagFieldsBech32 prefixUse case
BaseAddressnetworkId, paymentCredential, stakeCredentialaddr / addr_testStandard address with payment and staking
EnterpriseAddressnetworkId, paymentCredentialaddr / addr_testPayment only, no staking rewards
PointerAddressnetworkId, paymentCredential, pointeraddr / addr_testDeprecated pointer to on-chain stake registration
RewardAccountnetworkId, stakeCredentialstake / stake_testStaking reward withdrawal address
ByronAddressnetworkId, bytesN/A (Base58)Legacy Byron-era address

Each type is a Schema.TaggedClass, so you can use _tag for exhaustive pattern matching.

Format Conversion

AddressEras provides symmetric parsing and encoding functions for all three formats:

Bech32

import { AddressEras } from "@evolution-sdk/evolution"

const address = AddressEras.fromBech32(
"addr_test1vrm9x2dgvdau8vckj4duc89m638t8djmluqw5pdrFollw8qd9k63"
)

const bech32 = AddressEras.toBech32(address)

Hex

import { AddressEras } from "@evolution-sdk/evolution"

const address = AddressEras.fromHex(
"019493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e32c728d3861e164cab28cb8f006448139c8f1740ffb8e7aa9e5232dc"
)

const hex = AddressEras.toHex(address)

Bytes

import { AddressEras } from "@evolution-sdk/evolution"

const address = AddressEras.fromHex(
"019493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e32c728d3861e164cab28cb8f006448139c8f1740ffb8e7aa9e5232dc"
)

const bytes = AddressEras.toBytes(address)
const decoded = AddressEras.fromBytes(bytes)

Handling Legacy Addresses

When iterating UTxOs from the chain, you may encounter Byron addresses that Address cannot parse. Use AddressEras to handle them:

import { AddressEras } from "@evolution-sdk/evolution"

type Utxo = { address: string; value: bigint }

function getPaymentCredential(utxo: Utxo) {
const address = AddressEras.fromHex(utxo.address)

switch (address._tag) {
case "BaseAddress":
case "EnterpriseAddress":
case "PointerAddress":
return address.paymentCredential
case "RewardAccount":
return null // Reward accounts have no payment credential
case "ByronAddress":
return null // Byron addresses store opaque bytes
}
}

Summary

FunctionPurpose
fromBech32()Parse Bech32 address string (any type)
fromHex()Parse hex-encoded address bytes
fromBytes()Parse raw Uint8Array address
toBech32()Encode to Bech32 string
toHex()Encode to hex string
toBytes()Encode to raw Uint8Array
isAddress()Type guard for the AddressEras union

Next Steps