Granite Upgrade Activates in08d:14h:58m:01s
Clients

Clients

Overview

The SDK provides different client types for interacting with Avalanche. Each client is optimized for specific use cases.

Client Architecture

Avalanche Client (Public)
├── P-Chain Client
├── X-Chain Client
├── C-Chain Client
├── Admin API Client
├── Info API Client
├── Health API Client
├── ProposerVM Client
└── Index API Clients

Avalanche Wallet Client
├── All Public Client Methods
├── P-Chain Wallet Operations
├── X-Chain Wallet Operations
├── C-Chain Wallet Operations
└── ERC20 Token Operations

Client Types

Main Clients

Chain-Specific Clients

API Clients

Configuration

All clients accept a common configuration:

interface AvalancheClientConfig {
  transport: Transport; // Required: HTTP, WebSocket, or Custom
  chain?: Chain; // Optional: Network configuration
  account?: Account | Address; // Optional: For wallet operations
  apiKey?: string; // Optional: For authenticated endpoints
  rlToken?: string; // Optional: Rate limit token
  key?: string; // Optional: Client key identifier
  name?: string; // Optional: Client name
  pollingInterval?: number; // Optional: Polling interval in ms (default: chain.blockTime / 3)
  cacheTime?: number; // Optional: Cache time in ms (default: chain.blockTime / 3)
  batch?: { multicall?: boolean | MulticallBatchOptions }; // Optional: Batch settings
  ccipRead?:
    | {
        request?: (
          params: CcipRequestParameters
        ) => Promise<CcipRequestReturnType>;
      }
    | false; // Optional: CCIP Read config
  experimental_blockTag?: BlockTag; // Optional: Default block tag (default: 'latest')
  rpcSchema?: RpcSchema; // Optional: Typed JSON-RPC schema
  type?: string; // Optional: Client type
}

Configuration Options

OptionTypeRequiredDefaultDescription
transportTransport✅ Yes-Transport configuration (HTTP, WebSocket, Custom)
chainChainNo-Network configuration (mainnet/testnet)
accountAccount | AddressNo-Account for signing operations
apiKeystringNo-API key for authenticated endpoints
rlTokenstringNo-Rate limit token
keystringNo-Client key identifier
namestringNo-Client name
pollingIntervalnumberNochain.blockTime / 3Polling interval in milliseconds
cacheTimenumberNochain.blockTime / 3Cache time in milliseconds
batchobjectNo-Batch settings (multicall configuration)
ccipReadobject | falseNo-CCIP Read configuration
rpcSchemaRpcSchemaNo-Typed JSON-RPC schema
typestringNo-Client type identifier

Usage Examples

Public Client

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

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

// Read data from all chains
const pHeight = await client.pChain.getHeight();
const balance = await client.getBalance({ address: "0x..." });

Wallet Client

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 transaction
const txHash = await walletClient.send({
  to: "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
  amount: avaxToWei(0.001),
});

Accessing Sub-Clients

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

// Chain clients
client.pChain; // P-Chain operations
client.xChain; // X-Chain operations
client.cChain; // C-Chain operations

// API clients
client.admin; // Admin API
client.info; // Info API
client.health; // Health API
client.proposerVM.pChain; // ProposerVM API for P Chain
client.proposerVM.xChain; // ProposerVM API for X Chain
client.proposerVM.cChain; // ProposerVM API for C Chain
client.indexBlock.pChain; // P-Chain block index
client.indexBlock.cChain; // C-Chain block index
client.indexBlock.xChain; // X-Chain block index
client.indexTx.xChain; // X-Chain transaction index

Next Steps

Is this guide helpful?