Granite Upgrade Activates in08d:14h:58m:21s

Getting Started

Get started with the Avalanche Client SDK - your gateway to building on Avalanche with TypeScript.

Overview

The Avalanche Client SDK provides a TypeScript interface for interacting with Avalanche. Built on viem, it offers full Ethereum compatibility plus native support for P-Chain, X-Chain, and C-Chain operations.

Installation

Install the Avalanche Client SDK using your preferred package manager:

npm install @avalanche-sdk/client
yarn add @avalanche-sdk/client
bun add @avalanche-sdk/client

Requirements

  • Node.js >= 20.0.0
  • TypeScript >= 5.0.0 (recommended)
  • Modern browsers: Chrome 88+, Firefox 85+, Safari 14+, Edge 88+

Quick Start

Public Client

Create a read-only client:

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

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

// Read operations
const pChainHeight = await client.pChain.getHeight();
const balance = await client.getBalance({
  address: "0xA0Cf798816D4b9b9866b5330EEa46a18382f251e",
});

Wallet Client

Create a wallet client for transactions:

import { createAvalancheWalletClient } from "@avalanche-sdk/client";
import { privateKeyToAvalancheAccount } from "@avalanche-sdk/client/accounts";
import { avalanche } from "@avalanche-sdk/client/chains";
import { avaxToWei } from "@avalanche-sdk/client/utils";

const account = privateKeyToAvalancheAccount("0x...");

const walletClient = createAvalancheWalletClient({
  account,
  chain: avalanche,
  transport: { type: "http" },
});

// Send AVAX
const hash = await walletClient.send({
  to: "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
  amount: avaxToWei(0.001),
});

Account Creation

Private Key

import { privateKeyToAvalancheAccount } from "@avalanche-sdk/client/accounts";

const account = privateKeyToAvalancheAccount("0x...");

Mnemonic

import { mnemonicsToAvalancheAccount } from "@avalanche-sdk/client/accounts";

const account = mnemonicsToAvalancheAccount("test test test...");

HD Key

import { hdKeyToAvalancheAccount, HDKey } from "@avalanche-sdk/client/accounts";

const hdKey = HDKey.fromMasterSeed(seed);
const account = hdKeyToAvalancheAccount(hdKey);

Learn more about accounts →

Transport Configuration

HTTP

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

WebSocket

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

Custom Endpoint

const client = createAvalancheClient({
  chain: avalanche,
  transport: {
    type: "http",
    url: "https://your-custom-rpc-endpoint.com/ext/bc/C/rpc",
  },
});

Learn more about transports →

Avalanche Chains

Avalanche has three primary chains:

  • P-Chain (Platform Chain): Validators, staking, subnets
  • X-Chain (Exchange Chain): Asset transfers (UTXO model)
  • C-Chain (Contract Chain): Smart contracts (Ethereum-compatible)
// P-Chain
const validators = await client.pChain.getCurrentValidators({});

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

// C-Chain
const balance = await client.getBalance({ address: "0x..." });

Using viem Features

The SDK is built on viem, so you have access to all viem functionality:

import { formatEther, parseEther } from "@avalanche-sdk/client/utils";

const valueInWei = parseEther("1.0");
const valueInAvax = formatEther(1000000000000000000n);
const receipt = await walletClient.waitForTransactionReceipt({ hash });

See the viem documentation for more utilities.

Next Steps

Need Help?

Is this guide helpful?