Evolution SDK
Addresses

Address Conversion

Convert between different address formats using Core Address module

Address Conversion

The Core Address module provides transformations between different address representations: Bech32 strings, hexadecimal, and raw bytes.

Available Formats

Bech32 (Human-Readable)

Standard format used in wallets and explorers:

  • Mainnet base: addr1...
  • Testnet base: addr_test1...
  • Mainnet reward: stake1...
  • Testnet reward: stake_test1...

Hexadecimal

Hex-encoded bytes, useful for low-level operations and debugging.

Raw Bytes

Binary format (Uint8Array), used internally and for serialization.

Conversion Examples

Bech32 ↔ Address

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

const  = "addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd";

// Parse Bech32 string to address
const  = ..();

.("Network ID:", .);
.("Payment credential:", .);
.("Staking credential:", .);

// Convert address back to Bech32
const  = ..();
.("Bech32:", );
// Same as original: addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd

Hex ↔ Address

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

const  = "019493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e32c728d3861e164cab28cb8f006448139c8f1740ffb8e7aa9e5232dc";

// Parse hex to address
const  = ..();

.("Parsed from hex:", );

// Convert address to hex
const  = ..();
.("Hex:", );

Bytes ↔ Address

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

// Create an address structure
const  = new ..({
  : 1,
  : new ..({
    : new (28)
  }),
  : new ..({
    : new (28)
  })
});

// Convert to raw bytes
const  = ..();
.("Bytes length:", .); // 57 for base address

// Parse from bytes
const  = ..();
.("Decoded:", );

Error Handling

Conversions can fail with invalid input:

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

const  = "invalid_address";

// Error handling with try-catch
try {
  const  = ..();
  .("Parsed address:", );
} catch () {
  .("Failed to parse address:", );
}

Next Steps