> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xyzchain.org/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK Overview

> Build dApps on XYZ Chain with the TypeScript SDK

# @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

```bash theme={null}
npm install @xyz-chain/sdk
```

## Quick Start

### Read-Only Client

Connect to XYZ Chain and query data without a wallet:

```typescript theme={null}
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:

```typescript theme={null}
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:

```typescript theme={null}
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

| Module           | Description                                                         |
| ---------------- | ------------------------------------------------------------------- |
| **Client**       | `createClient()` for read-only, `createSigningClient()` for signing |
| **Queries**      | Balance, token info, contract queries                               |
| **Transactions** | Send tokens, execute contracts                                      |
| **Wallet**       | Keplr, Leap, XYZ Wallet integration + modal                         |
| **Contracts**    | Generic + CW20-specific contract operations                         |
| **Types**        | Coin formatting, chain config, transaction types                    |

## Configuration

```typescript theme={null}
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:

```typescript theme={null}
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

| Environment | Requirements                                             |
| ----------- | -------------------------------------------------------- |
| Browser     | Keplr, Leap, or XYZ Wallet extension for wallet features |
| Node.js     | Node.js 18+                                              |
| Both        | Access to an XYZ Chain RPC node                          |

## Next Steps

<CardGroup cols={2}>
  <Card title="Queries" icon="magnifying-glass" href="/sdk/queries">
    Read balances, token info, and contract state
  </Card>

  <Card title="Transactions" icon="paper-plane" href="/sdk/transactions">
    Send tokens and execute contracts
  </Card>

  <Card title="Wallets" icon="wallet" href="/sdk/wallets">
    Connect Keplr, Leap, or XYZ Wallet
  </Card>
</CardGroup>
