Skip to main content

@xyz-chain/sdk

The XYZ Chain SDK is a TypeScript library for building decentralized applications on XYZ Chain. It wraps CosmJS with XYZ-specific helpers for wallet connection, token operations, and contract interaction.

Installation

npm install @xyz-chain/sdk

Quick Start

Read-Only Client

Connect to XYZ Chain and query data without a wallet:
import { createClient, getBalance, formatXYZ } from "@xyz-chain/sdk";

const client = await createClient({
  rpcEndpoint: "http://67.205.164.156:26657",
});

// Get chain info
const chainId = await client.getChainId();  // "xyz-1"
const height = await client.getHeight();

// Query balance
const balance = await getBalance(client, "xyz1...");
console.log(formatXYZ(balance.amount), "XYZ");  // "1,000.50 XYZ"

Browser with Wallet

Connect a user’s wallet and send transactions:
import { showWalletModal, sendXYZ } from "@xyz-chain/sdk";

// Show wallet selection (Keplr, Leap, XYZ Wallet)
const wallet = await showWalletModal({
  rpcEndpoint: "http://67.205.164.156:26657",
});

if (wallet) {
  console.log("Connected:", wallet.address);
  // wallet.signer is ready for signing transactions
}

Node.js with Mnemonic

For scripts, bots, and backend services:
import { createSigningClient, sendXYZ } from "@xyz-chain/sdk";

const client = await createSigningClient(
  { rpcEndpoint: "http://67.205.164.156:26657" },
  "your mnemonic phrase here"
);

const result = await sendXYZ(client, "xyz1...recipient", "1000000");
console.log("TX:", result.transactionHash);

Key Modules

ModuleDescription
ClientcreateClient() for read-only, createSigningClient() for signing
QueriesBalance, token info, contract queries
TransactionsSend tokens, execute contracts
WalletKeplr, Leap, XYZ Wallet integration + modal
ContractsGeneric + CW20-specific contract operations
TypesCoin formatting, chain config, transaction types

Configuration

import { createClient } from "@xyz-chain/sdk";

const client = await createClient({
  rpcEndpoint: "http://67.205.164.156:26657",  // Required
  restEndpoint: "http://67.205.164.156:1317",   // Optional (REST/LCD)
  chainId: "xyz-1",                              // Default: "xyz-1"
  prefix: "xyz",                                 // Default: "xyz"
});

Token Denominations

XYZ uses 6 decimals. The SDK provides helpers for conversion:
import { formatXYZ, parseXYZ, XYZ_DECIMALS, XYZ_DENOM } from "@xyz-chain/sdk";

formatXYZ("1000000");    // "1"          (uxyz → XYZ)
parseXYZ("1");           // "1000000"    (XYZ → uxyz)

XYZ_DECIMALS;  // 6
XYZ_DENOM;     // "uxyz"

Requirements

EnvironmentRequirements
BrowserKeplr, Leap, or XYZ Wallet extension for wallet features
Node.jsNode.js 18+
BothAccess to an XYZ Chain RPC node

Next Steps