Skip to content

Commit 8905ee8

Browse files
authored
Merge pull request #3296 from SayanKar/sayan/add-client-sdk-docs
chore: add client sdk docs
2 parents e4bedd9 + 0441c26 commit 8905ee8

39 files changed

+11928
-120
lines changed

app/docs/[...slug]/page.tsx

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import type { Metadata } from "next";
1+
import { APIStorageManager } from "@/components/content-design/api-storage-manager";
2+
import Mermaid from "@/components/content-design/mermaid";
3+
import { AutoTypeTable } from "@/components/content-design/type-table";
4+
import YouTube from "@/components/content-design/youtube";
5+
import { BackToTop } from "@/components/ui/back-to-top";
6+
import { Feedback } from "@/components/ui/feedback";
7+
import { SidebarActions } from "@/components/ui/sidebar-actions";
8+
import { cChainApi, dataApi, metricsApi, pChainApi } from "@/lib/openapi";
9+
import { documentation } from "@/lib/source";
10+
import { createMetadata } from "@/utils/metadata";
11+
import { APIPage } from "fumadocs-openapi/ui";
12+
import { Popup, PopupContent, PopupTrigger } from "fumadocs-twoslash/ui";
13+
import { Accordion, Accordions } from "fumadocs-ui/components/accordion";
14+
import { Callout } from "fumadocs-ui/components/callout";
15+
import { File, Files, Folder } from "fumadocs-ui/components/files";
16+
import { Heading } from "fumadocs-ui/components/heading";
17+
import { Step, Steps } from "fumadocs-ui/components/steps";
18+
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
19+
import { TypeTable } from "fumadocs-ui/components/type-table";
20+
import defaultComponents from "fumadocs-ui/mdx";
221
import {
3-
DocsPage,
422
DocsBody,
5-
DocsTitle,
623
DocsDescription,
24+
DocsPage,
25+
DocsTitle,
726
} from "fumadocs-ui/page";
8-
import { notFound } from "next/navigation";
9-
import { type ComponentProps, type FC, type ReactElement } from "react";
10-
import defaultComponents from "fumadocs-ui/mdx";
11-
import { Heading } from "fumadocs-ui/components/heading";
12-
import { Popup, PopupContent, PopupTrigger } from "fumadocs-twoslash/ui";
13-
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
14-
import { Step, Steps } from "fumadocs-ui/components/steps";
15-
import { Callout } from "fumadocs-ui/components/callout";
16-
import { TypeTable } from "fumadocs-ui/components/type-table";
17-
import { Accordion, Accordions } from "fumadocs-ui/components/accordion";
18-
import { createMetadata } from "@/utils/metadata";
19-
import { documentation } from "@/lib/source";
20-
import { AutoTypeTable } from "@/components/content-design/type-table";
21-
import { BackToTop } from "@/components/ui/back-to-top";
22-
import { File, Folder, Files } from "fumadocs-ui/components/files";
23-
import Mermaid from "@/components/content-design/mermaid";
2427
import type { MDXComponents } from "mdx/types";
25-
import YouTube from "@/components/content-design/youtube";
26-
import { Feedback } from "@/components/ui/feedback";
27-
import { SidebarActions } from "@/components/ui/sidebar-actions";
28+
import type { Metadata } from "next";
29+
import { notFound } from "next/navigation";
2830
import posthog from "posthog-js";
29-
import { APIPage } from "fumadocs-openapi/ui";
30-
import { dataApi, metricsApi, pChainApi, cChainApi } from "@/lib/openapi";
31-
import { APIStorageManager } from "@/components/content-design/api-storage-manager";
31+
import { type ComponentProps, type FC, type ReactElement, type ReactNode } from "react";
3232

3333
export const dynamicParams = false;
3434
export const revalidate = false;
@@ -99,6 +99,17 @@ export default async function Page(props: {
9999
PopupTrigger,
100100
Tabs,
101101
Tab,
102+
InstallTabs: ({
103+
items,
104+
children,
105+
}: {
106+
items: string[];
107+
children: ReactNode;
108+
}) => (
109+
<Tabs items={items} style={{ padding: '15px'}} id="package-manager">
110+
{children}
111+
</Tabs>
112+
),
102113
Step,
103114
Steps,
104115
YouTube,

content/docs/tooling/avalanche-sdk/chainkit/getting-started.mdx

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: Getting Started
33
description: Get started with the ChainKit SDK
44
icon: Rocket
55
---
6+
67
### ChainKit SDK
78

89
The ChainKit SDK provides web3 application developers with multi-chain data related to Avalanche's primary network, Avalanche L1s, and Ethereum. With the Data API, you can easily build products that leverage real-time and historical transaction and transfer history, native and token balances, and various types of token metadata.
@@ -14,9 +15,19 @@ The ChainKit SDK provides web3 application developers with multi-chain data rela
1415
refer to the individual method documentation.
1516
</Callout>
1617

17-
<img src="https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=5ef81daf70200912ac6c1b505021c921" data-og-width="3968" width="3968" data-og-height="2452" height="2452" data-path="images/chainkit-SDK.jpg" data-optimize="true" data-opv="3" srcSet="https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?w=280&fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=17f99881ded8ce13a0df4784eb730562 280w, https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?w=560&fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=b64c64345a3586c1d73a1acdad757bb0 560w, https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?w=840&fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=606d74291aa14a9c98a169450b00ec9e 840w, https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?w=1100&fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=8cb8cb94c1851512eae03c1deaa71985 1100w, https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?w=1650&fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=855ca27fa8e66c64006f3d4623a7d8f6 1650w, https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?w=2500&fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=97d501a7bedbfc7c909e4b6b706bafe8 2500w" />
18+
<img
19+
src="https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=5ef81daf70200912ac6c1b505021c921"
20+
data-og-width="3968"
21+
width="3968"
22+
data-og-height="2452"
23+
height="2452"
24+
data-path="images/chainkit-SDK.jpg"
25+
data-optimize="true"
26+
data-opv="3"
27+
srcSet="https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?w=280&fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=17f99881ded8ce13a0df4784eb730562 280w, https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?w=560&fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=b64c64345a3586c1d73a1acdad757bb0 560w, https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?w=840&fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=606d74291aa14a9c98a169450b00ec9e 840w, https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?w=1100&fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=8cb8cb94c1851512eae03c1deaa71985 1100w, https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?w=1650&fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=855ca27fa8e66c64006f3d4623a7d8f6 1650w, https://mintcdn.com/avalabs-47ea3976/5tYvr4aERqS4CNLz/images/chainkit-SDK.jpg?w=2500&fit=max&auto=format&n=5tYvr4aERqS4CNLz&q=85&s=97d501a7bedbfc7c909e4b6b706bafe8 2500w"
28+
/>
1829

19-
The SDK is currently available in TypeScript, with more languages coming soon. If you are interested in a language that is not listed, please reach out to us in the [#dev-tools](https://discord.com/channels/578992315641626624/1280920394236297257) channel in the [Avalanche Discord](https://discord.gg/avax).
30+
The SDK is currently available in TypeScript, with more languages coming soon. If you are interested in a language that is not listed, please reach out to us in the [#avalanche-sdk](https://discord.com/channels/578992315641626624/1416238478915665961) channel in the [Avalanche Discord](https://discord.gg/avax).
2031

2132
<Cards>
2233
<Card title="NPM Package">
@@ -29,50 +40,50 @@ The SDK is currently available in TypeScript, with more languages coming soon. I
2940

3041
### SDK Installation
3142

32-
<Tabs items={['npm', 'pnpm', 'bun', 'yarn']}>
33-
<Tab value="npm">
34-
```bash
35-
npm add @avalanche-sdk/chainkit
36-
```
43+
<InstallTabs items={['npm', 'yarn', 'bun']}>
44+
<Tab value="npm">
45+
46+
```bash
47+
npm install @avalanche-sdk/client
48+
```
49+
3750
</Tab>
38-
<Tab value="pnpm">
39-
```bash
40-
pnpm add @avalanche-sdk/chainkit
41-
```
51+
<Tab value="yarn">
52+
53+
```bash
54+
yarn add @avalanche-sdk/client
55+
```
56+
4257
</Tab>
4358
<Tab value="bun">
44-
```bash
45-
bun add @avalanche-sdk/chainkit
46-
```
47-
</Tab>
48-
<Tab value="yarn">
49-
```bash
50-
yarn add @avalanche-sdk/chainkit zod
51-
```
59+
60+
```bash
61+
bun add @avalanche-sdk/client
62+
```
63+
5264
</Tab>
53-
</Tabs>
65+
</InstallTabs>
5466

5567
### SDK Example Usage
5668

5769
```javascript
5870
import { Avalanche } from "@avalanche-sdk/chainkit";
5971

6072
const avalancheSDK = new Avalanche({
61-
apiKey: "<YOUR_API_KEY_HERE>",
62-
chainId: "43114",
63-
network: "mainnet",
73+
apiKey: "<YOUR_API_KEY_HERE>",
74+
chainId: "43114",
75+
network: "mainnet",
6476
});
6577

6678
async function run() {
67-
const result = await avalancheSDK.metrics.healthCheck();
79+
const result = await avalancheSDK.metrics.healthCheck();
6880

69-
// Handle the result
70-
console.log(result);
81+
// Handle the result
82+
console.log(result);
7183
}
7284

7385
run();
74-
7586
```
7687

7788
Refer to the code samples provided for each route to see examples of how to use them in the SDK. Explore routes here [Data API](/docs/api-reference/data-api/getting-started),
78-
[Metrics API](/docs/api-reference/metrics-api/getting-started) & [Webhooks API](/docs/api-reference/webhook-api/getting-started).
89+
[Metrics API](/docs/api-reference/metrics-api/getting-started) & [Webhooks API](/docs/api-reference/webhook-api/getting-started).
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
---
2+
title: Account Management
3+
icon: users
4+
description: Learn how to create and manage accounts in the Avalanche Client SDK with support for EVM, X-Chain, and P-Chain operations.
5+
---
6+
7+
## Overview
8+
9+
Avalanche accounts work across all three chains—P-Chain, X-Chain, and C-Chain—with a single account. Each account provides both EVM addresses (for C-Chain) and XP addresses (for X/P-Chain), so you can interact with the entire Avalanche network without managing separate accounts.
10+
11+
## Account Structure
12+
13+
Every Avalanche account has an EVM account for C-Chain and an optional XP account for X/P-Chain:
14+
15+
```typescript
16+
type AvalancheAccount = {
17+
evmAccount: Account; // C-Chain
18+
xpAccount?: XPAccount; // X/P-Chain
19+
getEVMAddress: () => Address;
20+
getXPAddress: (chain?: "X" | "P" | "C", hrp?: string) => XPAddress;
21+
};
22+
```
23+
24+
### Quick Start
25+
26+
```typescript
27+
import { privateKeyToAvalancheAccount } from "@avalanche-sdk/client/accounts";
28+
import { createAvalancheWalletClient } from "@avalanche-sdk/client";
29+
import { avalanche } from "@avalanche-sdk/client/chains";
30+
31+
const account = privateKeyToAvalancheAccount("0x...");
32+
33+
const walletClient = createAvalancheWalletClient({
34+
account,
35+
chain: avalanche,
36+
transport: { type: "http" },
37+
});
38+
39+
// Get addresses for all chains
40+
const evmAddress = account.getEVMAddress(); // 0x742d35Cc...
41+
const xChainAddress = account.getXPAddress("X"); // X-avax1...
42+
const pChainAddress = account.getXPAddress("P"); // P-avax1...
43+
```
44+
45+
## Account Types
46+
47+
### Local Accounts
48+
49+
Local accounts store keys on your machine and sign transactions before broadcasting. Use these for server-side apps, bots, or when you need full control.
50+
51+
- [Private Key Accounts](accounts/local/private-key) - Simple and direct
52+
- [Mnemonic Accounts](accounts/local/mnemonic) - Easy recovery with seed phrases
53+
- [HD Key Accounts](accounts/local/hd-key) - Advanced key derivation
54+
55+
### JSON-RPC Accounts
56+
57+
JSON-RPC accounts use external wallets (MetaMask, Core, etc.) for signing. Perfect for browser-based dApps where users control their own keys.
58+
59+
[Learn more about JSON-RPC accounts →](accounts/json-rpc)
60+
61+
## Working with Accounts
62+
63+
### EVM Account
64+
65+
The `evmAccount` handles all C-Chain operations—smart contracts, ERC-20 transfers, and standard EVM interactions.
66+
67+
```typescript
68+
const evmAccount = account.evmAccount;
69+
console.log(evmAccount.address); // 0x742d35Cc...
70+
```
71+
72+
### XP Account
73+
74+
The `xpAccount` handles X-Chain and P-Chain operations—UTXO transactions, asset transfers, and staking.
75+
76+
```typescript
77+
if (account.xpAccount) {
78+
const xpAccount = account.xpAccount;
79+
console.log(xpAccount.publicKey);
80+
}
81+
```
82+
83+
### Getting Addresses
84+
85+
```typescript
86+
// C-Chain address
87+
const evmAddress = account.getEVMAddress(); // 0x742d35Cc...
88+
89+
// X/P-Chain addresses
90+
const xChainAddress = account.getXPAddress("X"); // X-avax1...
91+
const pChainAddress = account.getXPAddress("P"); // P-avax1...
92+
93+
// Network-specific (mainnet vs testnet)
94+
const mainnet = account.getXPAddress("X", "avax");
95+
const testnet = account.getXPAddress("X", "fuji");
96+
```
97+
98+
## Creating Accounts
99+
100+
### Private Key
101+
102+
```typescript
103+
import { privateKeyToAvalancheAccount } from "@avalanche-sdk/client/accounts";
104+
105+
const account = privateKeyToAvalancheAccount("0x...");
106+
```
107+
108+
[Private Key Accounts →](accounts/local/private-key)
109+
110+
### Mnemonic
111+
112+
```typescript
113+
import { mnemonicsToAvalancheAccount } from "@avalanche-sdk/client/accounts";
114+
115+
const account = mnemonicsToAvalancheAccount("abandon abandon abandon...");
116+
```
117+
118+
[Mnemonic Accounts →](accounts/local/mnemonic)
119+
120+
### HD Key
121+
122+
```typescript
123+
import { hdKeyToAvalancheAccount, HDKey } from "@avalanche-sdk/client/accounts";
124+
125+
const hdKey = HDKey.fromMasterSeed(seed);
126+
const account = hdKeyToAvalancheAccount(hdKey, { accountIndex: 0 });
127+
```
128+
129+
[HD Key Accounts →](accounts/local/hd-key)
130+
131+
## Address Formats
132+
133+
- **C-Chain:** `0x...` (Ethereum-compatible)
134+
- **X/P-Chain:** `avax1...` or `X-avax1...` / `P-avax1...` (Bech32-encoded)
135+
136+
[Network-Specific Addresses →](accounts/local/addresses)
137+
138+
## Security
139+
140+
<Callout>
141+
**Never expose private keys or mnemonics in client-side code or commit them to
142+
version control. Use environment variables.**
143+
</Callout>
144+
145+
```typescript
146+
// ✅ Good
147+
const account = privateKeyToAvalancheAccount(process.env.PRIVATE_KEY!);
148+
149+
// ❌ Bad
150+
const account = privateKeyToAvalancheAccount("0x1234...");
151+
```
152+
153+
## Comparison Table
154+
155+
| Feature | Private Key | Mnemonic | HD Key | JSON-RPC |
156+
| ----------------- | ----------- | --------- | -------- | ------------ |
157+
| **Ease of Use** | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
158+
| **Recovery** |||||
159+
| **Multi-Account** |||||
160+
| **Security** | ⚠️ High | ✅ High | ✅ High | ✅ Very High |
161+
| **Use Case** | Server/Bots | User Apps | Advanced | User Apps |
162+
163+
## Next Steps
164+
165+
- [Private Key Accounts](accounts/local/private-key) - Simple and direct
166+
- [Mnemonic Accounts](accounts/local/mnemonic) - Easy recovery
167+
- [HD Key Accounts](accounts/local/hd-key) - Advanced key derivation
168+
- [JSON-RPC Accounts](accounts/json-rpc) - Browser wallet integration
169+
- [Account Utilities](accounts/local/utilities) - Helper functions
170+
- [Wallet Operations](methods/wallet-methods/wallet) - Send transactions

0 commit comments

Comments
 (0)