MethodsPublic Methods

X-Chain Methods

Complete reference for X-Chain (Exchange Chain) methods

Overview

The X-Chain (Exchange Chain) is Avalanche's DAG-based chain designed for creating and trading digital smart assets. It handles asset creation, transfers, UTXO management, and provides the foundation for the Avalanche ecosystem. This reference covers all read-only X-Chain operations available through the Avalanche Client SDK.

Balance Operations

getBalance

Warning

Removed in AvalancheGo v1.15.4

getBalance calls avm.getBalance, which AvalancheGo v1.15.4 removes. The call fails on nodes that run v1.15.4 or later. Use getUTXOs instead: page through all UTXOs, decode each with getUtxoFromBytes from @avalanche-sdk/client/utils, and add the amounts of the transfer outputs for the asset whose locktime has passed.

Get the balance of a specific asset controlled by a given address.

Function Signature:

function getBalance(
  params: GetBalanceParameters
): Promise<GetBalanceReturnType>;

interface GetBalanceParameters {
  address: string;
  assetID: string;
}

interface GetBalanceReturnType {
  balance: bigint;
  utxoIDs: {
    txID: string;
    outputIndex: number;
  }[];
}

Parameters:

NameTypeRequiredDescription
addressstringYesX-Chain address to query
assetIDstringYesAsset ID to query

Returns:

TypeDescription
GetBalanceReturnTypeBalance information object

Return Object:

PropertyTypeDescription
balancebigintBalance amount for the specified asset
utxoIDsarrayArray of UTXO IDs referencing the address

Example:

import { createAvalancheClient } from "@avalanche-sdk/client";
import { avalanche } from "@avalanche-sdk/client/chains";

const client = createAvalancheClient({
  chain: avalanche,
  transport: { type: "http" },
});

const balance = await client.xChain.getBalance({
  address: "X-avax18jma8ppw3nhx5r4ap8clazz0dps7rv5ukulre5",
  assetID: "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", // AVAX
});

console.log("Balance:", balance.balance);
console.log("UTXO IDs:", balance.utxoIDs);

Related:


getAllBalances

Warning

Removed in AvalancheGo v1.15.4

getAllBalances calls avm.getAllBalances, which AvalancheGo v1.15.4 removes. The call fails on nodes that run v1.15.4 or later. Use getUTXOs instead: page through all UTXOs, decode each with getUtxoFromBytes from @avalanche-sdk/client/utils, and for each asset add the amounts of the transfer outputs whose locktime has passed.

Get the balances of all assets controlled by given addresses.

Function Signature:

function getAllBalances(
  params: GetAllBalancesParameters
): Promise<GetAllBalancesReturnType>;

interface GetAllBalancesParameters {
  addresses: string[];
}

interface GetAllBalancesReturnType {
  balances: Array<{
    assetID: string;
    balance: bigint;
  }>;
}

Parameters:

NameTypeRequiredDescription
addressesstring[]YesArray of X-Chain addresses to query

Returns:

TypeDescription
GetAllBalancesReturnTypeBalances array object

Return Object:

PropertyTypeDescription
balancesarrayArray of balance objects with assetID and balance

Example:

const allBalances = await client.xChain.getAllBalances({
  addresses: ["X-avax18jma8ppw3nhx5r4ap8clazz0dps7rv5ukulre5"],
});

// Iterate over all assets
allBalances.balances.forEach(({ assetID, balance }) => {
  console.log(`Asset ${assetID}: ${balance}`);
});

Related:


Asset Operations

getAssetDescription

Get information about an asset.

Function Signature:

function getAssetDescription(
  params: GetAssetDescriptionParameters
): Promise<GetAssetDescriptionReturnType>;

interface GetAssetDescriptionParameters {
  assetID: string;
}

interface GetAssetDescriptionReturnType {
  assetID: string;
  name: string;
  symbol: string;
  denomination: number;
}

Parameters:

NameTypeRequiredDescription
assetIDstringYesAsset ID

Returns:

TypeDescription
GetAssetDescriptionReturnTypeAsset information object

Return Object:

PropertyTypeDescription
assetIDstringAsset ID
namestringAsset name
symbolstringAsset symbol
denominationnumberAsset denomination (number of decimal places)

Example:

const asset = await client.xChain.getAssetDescription({
  assetID: "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z",
});

console.log("Asset name:", asset.name);
console.log("Asset symbol:", asset.symbol);
console.log("Denomination:", asset.denomination);

Related:


Block Operations

getHeight

Get the current block height of the X-Chain.

Function Signature:

function getHeight(): Promise<GetHeightReturnType>;

interface GetHeightReturnType {
  height: number;
}

Parameters:

No parameters required.

Returns:

TypeDescription
GetHeightReturnTypeHeight object

Return Object:

PropertyTypeDescription
heightnumberCurrent X-Chain block height

Example:

const height = await client.xChain.getHeight();
console.log("Current X-Chain height:", height.height);

Related:


getBlockByHeight

Get a block by its height.

Function Signature:

function getBlockByHeight(
  params: GetBlockByHeightParameters
): Promise<GetBlockByHeightReturnType>;

interface GetBlockByHeightParameters {
  height: number;
  encoding?: "hex" | "json";
}

interface GetBlockByHeightReturnType {
  encoding: "hex" | "json";
  block: string | object;
}

Parameters:

NameTypeRequiredDescription
heightnumberYesBlock height
encoding"hex" | "json"NoEncoding format (defaults to "json")

Returns:

TypeDescription
GetBlockByHeightReturnTypeBlock data object

Return Object:

PropertyTypeDescription
encoding"hex" | "json"Encoding format used
blockstring | objectBlock data in the specified encoding format

Example:

const block = await client.xChain.getBlockByHeight({
  height: 12345,
  encoding: "hex",
});

console.log("Block data:", block.block);

Related:


getBlock

Get a block by its ID.

Function Signature:

function getBlock(params: GetBlockParameters): Promise<GetBlockReturnType>;

interface GetBlockParameters {
  blockId: string;
  encoding?: "hex" | "json";
}

interface GetBlockReturnType {
  encoding: "hex" | "json";
  block: string | object;
}

Parameters:

NameTypeRequiredDescription
blockIdstringYesBlock ID in CB58 format
encoding"hex" | "json"NoEncoding format (defaults to "json")

Returns:

TypeDescription
GetBlockReturnTypeBlock data object

Return Object:

PropertyTypeDescription
encoding"hex" | "json"Encoding format used
blockstring | objectBlock data in the specified encoding format

Example:

const block = await client.xChain.getBlock({
  blockId: "block-id-in-cb58-format",
  encoding: "hex",
});

console.log("Block:", block.block);

Related:


Transaction Operations

getTx

Get a transaction by its ID.

Function Signature:

function getTx(params: GetTxParameters): Promise<GetTxReturnType>;

interface GetTxParameters {
  txID: string;
  encoding?: "hex" | "json";
}

interface GetTxReturnType {
  encoding: "hex" | "json";
  tx: string | object;
}

Parameters:

NameTypeRequiredDescription
txIDstringYesTransaction ID in CB58 format
encoding"hex" | "json"NoEncoding format (defaults to "json")

Returns:

TypeDescription
GetTxReturnTypeTransaction data object

Return Object:

PropertyTypeDescription
encoding"hex" | "json"Encoding format used
txstring | objectTransaction data in the specified encoding format

Example:

const tx = await client.xChain.getTx({
  txID: "transaction-id",
  encoding: "hex",
});

console.log("Transaction:", tx.tx);

Related:


getTxStatus

Warning

Removed in AvalancheGo v1.15.4

getTxStatus calls avm.getTxStatus, which AvalancheGo v1.15.4 removes. The call fails on nodes that run v1.15.4 or later. Use getTx instead: the transaction is accepted when getTx returns it.

Get the status of a transaction.

Function Signature:

function getTxStatus(
  params: GetTxStatusParameters
): Promise<GetTxStatusReturnType>;

interface GetTxStatusParameters {
  txID: string;
  includeReason?: boolean | true;
}

interface GetTxStatusReturnType {
  status: "Accepted" | "Processing" | "Rejected" | "Unknown";
  reason?: string;
}

Parameters:

NameTypeRequiredDescription
txIDstringYesTransaction ID in CB58 format
includeReasonboolean | trueNoWhether to include the reason for the status

Returns:

TypeDescription
GetTxStatusReturnTypeTransaction status object

Return Object:

PropertyTypeDescription
statusstringTransaction status: "Accepted", "Processing", "Rejected", or "Unknown"
reasonstringOptional reason for the status (if rejected)

Status Values:

  • Accepted: Transaction has been accepted and included in a block
  • Processing: Transaction is being processed
  • Rejected: Transaction was rejected
  • Unknown: Transaction status cannot be determined

Example:

const status = await client.xChain.getTxStatus({
  txID: "transaction-id",
});

if (status.status === "Accepted") {
  console.log("Transaction accepted!");
} else if (status.status === "Rejected") {
  console.log("Transaction rejected");
  if (status.reason) {
    console.log("Reason:", status.reason);
  }
} else {
  console.log("Transaction status:", status.status);
}

Related:


getTxFee

Get the transaction fee for the X-Chain.

Function Signature:

function getTxFee(): Promise<GetTxFeeReturnType>;

interface GetTxFeeReturnType {
  txFee: number;
  createAssetTxFee: number;
}

Parameters:

No parameters required.

Returns:

TypeDescription
GetTxFeeReturnTypeTransaction fee object

Return Object:

PropertyTypeDescription
txFeenumberStandard transaction fee
createAssetTxFeenumberFee for creating a new asset

Example:

const fees = await client.xChain.getTxFee();

console.log("Standard transaction fee:", fees.txFee);
console.log("Create asset fee:", fees.createAssetTxFee);

Related:


UTXO Operations

getUTXOs

Get the UTXOs controlled by a set of addresses.

Function Signature:

function getUTXOs(params: GetUTXOsParameters): Promise<GetUTXOsReturnType>;

interface GetUTXOsParameters {
  addresses: string[];
  sourceChain?: string;
  limit?: number;
  startIndex?: {
    address: string;
    utxo: string;
  };
  encoding?: "hex";
}

interface GetUTXOsReturnType {
  numFetched: number;
  utxos: string[];
  endIndex: {
    address: string;
    utxo: string;
  };
  sourceChain?: string;
  encoding: "hex";
}

Parameters:

NameTypeRequiredDescription
addressesstring[]YesArray of X-Chain addresses
sourceChainstringNoSource chain ID (e.g., "P" for P-Chain)
limitnumberNoMaximum number of UTXOs to return
startIndex{ address: string; utxo: string }NoPagination cursor for next page
encoding"hex"NoEncoding format (can only be "hex" if provided)

Returns:

TypeDescription
GetUTXOsReturnTypeUTXO data with pagination

Return Object:

PropertyTypeDescription
numFetchednumberNumber of UTXOs fetched in this response
utxosstring[]Array of UTXO bytes (hex encoded)
endIndex{ address: string; utxo: string }Pagination cursor for fetching next page
sourceChainstringSource chain ID (if specified)
encoding"hex"Encoding format used

Example:

// Get first page
const utxos = await client.xChain.getUTXOs({
  addresses: ["X-avax18jma8ppw3nhx5r4ap8clazz0dps7rv5ukulre5"],
  limit: 100,
});

console.log("Number of UTXOs:", utxos.numFetched);

// Get next page if needed
if (utxos.endIndex) {
  const moreUTXOs = await client.xChain.getUTXOs({
    addresses: ["X-avax18jma8ppw3nhx5r4ap8clazz0dps7rv5ukulre5"],
    startIndex: utxos.endIndex,
    limit: 100,
  });
}

Related:


Transaction Submission

issueTx

Issue a transaction to the X-Chain.

Function Signature:

function issueTx(params: IssueTxParameters): Promise<IssueTxReturnType>;

interface IssueTxParameters {
  tx: string;
  encoding: "hex";
}

interface IssueTxReturnType {
  txID: string;
}

Parameters:

NameTypeRequiredDescription
txstringYesTransaction bytes in hex format
encoding"hex"YesEncoding format (must be "hex")

Returns:

TypeDescription
IssueTxReturnTypeTransaction ID object

Return Object:

PropertyTypeDescription
txIDstringTransaction ID in CB58 format

Example:

const txID = await client.xChain.issueTx({
  tx: "0x00000009de31b4d8b22991d51aa6aa1fc733f23a851a8c9400000000000186a0...",
  encoding: "hex",
});

console.log("Transaction ID:", txID.txID);

Related:


Genesis Operations

buildGenesis

Build a genesis block for a custom blockchain.

Function Signature:

function buildGenesis(
  params: BuildGenesisParameters
): Promise<BuildGenesisReturnType>;

interface BuildGenesisParameters {
  networkID: number;
  genesisData: {
    name: string;
    symbol: string;
    denomination: number;
    initialState: {
      fixedCap: {
        amount: number;
        addresses: string[];
      };
    };
  };
  encoding: "hex";
}

interface BuildGenesisReturnType {
  bytes: string;
  encoding: "hex";
}

Parameters:

NameTypeRequiredDescription
networkIDnumberYesNetwork ID
genesisDataobjectYesGenesis block data with asset configuration
encoding"hex"YesEncoding format (must be "hex")

Returns:

TypeDescription
BuildGenesisReturnTypeGenesis block bytes object

Return Object:

PropertyTypeDescription
bytesstringGenesis block bytes in hex format
encoding"hex"Encoding format used

Example:

const genesis = await client.xChain.buildGenesis({
  networkID: 16,
  genesisData: {
    name: "myFixedCapAsset",
    symbol: "MFCA",
    denomination: 0,
    initialState: {
      fixedCap: {
        amount: 100000,
        addresses: ["X-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p"],
      },
    },
  },
  encoding: "hex",
});

console.log("Genesis bytes:", genesis.bytes);

Related:


Next Steps

Is this guide helpful?