Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
* @SayanKar
# CODEOWNERS file for Avalanche SDK TypeScript
# This file defines code owners who will be automatically requested for review
# when changes are made to the corresponding paths.
#
# Default owners for the entire repository
* @SayanKar @rajranjan0608 @ava-labs/data-platform
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"Permissioned",
"Permissionless",
"POSTHOG",
"proposervm",
"Sayan",
"scure",
"Sepk",
Expand All @@ -37,6 +38,7 @@
"UTXOID",
"UTXOs",
"viem",
"VMAPI",
"xChain"
]
}
31 changes: 29 additions & 2 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const cChainClient = client.cChain
const adminClient = client.admin
const infoClient = client.info
const healthClient = client.health
const indexPChainBlockClient = client.indexPChainBlock
const indexPChainBlockClient = client.indexBlock.pChain
const proposervmCChainClient = client.proposervm

// Example: Get the latest block number
const blockNumber = await pChainClient.getBlockNumber()
Expand Down Expand Up @@ -176,6 +177,7 @@ const exportTx = await cChainWallet.prepareExportTxn({
- Index C-Chain Block
- Index X-Chain Block
- Index X-Chain Transaction
- **proposervm Client**: Proposer VM Information

### Wallet Clients

Expand Down Expand Up @@ -208,6 +210,7 @@ const client = createAvalancheClient({
The SDK supports multiple transport types for connecting to Avalanche nodes. Each transport type has specific configuration options:

#### HTTP Transport (Recommended)

```typescript
const client = createAvalancheClient({
chain: avalanche,
Expand All @@ -230,12 +233,14 @@ const client = createAvalancheClient({
```

**HTTP Transport Features:**

- **Automatic URL Resolution**: If no URL is provided, uses the chain's default RPC endpoint
- **Custom Headers**: Support for custom HTTP headers via `fetchOptions.headers`
- **API Key Support**: Automatically adds `x-glacier-api-key` header when `apiKey` is provided
- **Rate Limit Support**: Automatically adds `rlToken` header when `rlToken` is provided

#### WebSocket Transport

```typescript
const client = createAvalancheClient({
chain: avalanche,
Expand All @@ -252,11 +257,13 @@ const client = createAvalancheClient({
```

**WebSocket Transport Features:**

- **Real-time Updates**: Supports WebSocket connections for live data
- **Automatic Reconnection**: Built-in retry logic with configurable retry count and delay
- **Event-driven**: Ideal for subscribing to blockchain events and real-time updates

#### Custom Transport

```typescript
const client = createAvalancheClient({
chain: avalanche,
Expand All @@ -271,11 +278,13 @@ const client = createAvalancheClient({
```

**Custom Transport Features:**

- **Provider Integration**: Integrate with custom RPC providers or middleware
- **Flexible Configuration**: Full control over transport behavior
- **Wallet Support**: Special handling for wallet clients

#### Fallback Transport

```typescript
const client = createAvalancheClient({
chain: avalanche,
Expand All @@ -295,11 +304,13 @@ const client = createAvalancheClient({
```

**Fallback Transport Features:**

- **High Availability**: Automatic failover between multiple RPC endpoints

### Advanced Configuration Examples

#### Custom HTTP Headers and Timeouts

```typescript
const client = createAvalancheClient({
chain: avalanche,
Expand All @@ -317,6 +328,7 @@ const client = createAvalancheClient({
```

#### Multiple Fallback Endpoints

```typescript
const client = createAvalancheClient({
chain: avalanche,
Expand All @@ -336,6 +348,7 @@ const client = createAvalancheClient({
```

#### WebSocket with Custom Configuration

```typescript
const client = createAvalancheClient({
chain: avalanche,
Expand Down Expand Up @@ -436,6 +449,9 @@ import { /* Health methods */ } from '@avalanche-sdk/client/methods/health'

// Index methods
import { /* Index methods */ } from '@avalanche-sdk/client/methods/index'

// proposervm methods
import { /* proposervm methods */ } from '@avalanche-sdk/client/methods/proposervm'
```

### Utilities
Expand Down Expand Up @@ -507,6 +523,7 @@ import { /* Window utilities */ } from '@avalanche-sdk/client/window'
- [`sampleValidators`](./src/methods/pChain/sampleValidators.ts) - Samples validators from the specified Subnet. [Docs](https://build.avax.network/docs/api-reference/p-chain/api#platformsamplevalidators)
- [`validatedBy`](./src/methods/pChain/validatedBy.ts) - Gets the Subnet that validates a given blockchain. [Docs](https://build.avax.network/docs/api-reference/p-chain/api#platformvalidatedby)
- [`validates`](./src/methods/pChain/validates.ts) - Gets the IDs of the blockchains a Subnet validates. [Docs](https://build.avax.network/docs/api-reference/p-chain/api#platformvalidates)
- [`getAllValidatorsAt`](./src/methods/pChain/getAllValidatorsAt.ts) - Get the validators and their weights of all L1s and the Primary Network at a given P-Chain height. [Docs](https://build.avax.network/docs/api-reference/p-chain/api#platformgetallvalidatorsat)

### X-Chain Methods

Expand Down Expand Up @@ -619,19 +636,26 @@ import { /* Window utilities */ } from '@avalanche-sdk/client/window'
- [`getLastAccepted`](./src/methods/index/getLastAccepted.ts) - Get the last accepted container. [Docs](https://build.avax.network/docs/api-reference/index-api#indexgetlastaccepted)
- [`isAccepted`](./src/methods/index/isAccepted.ts) - Returns true if the container is in this index. [Docs](https://build.avax.network/docs/api-reference/index-api#indexisaccepted)

### proposervm Methods
- [`getCurrentEpoch`](./src/methods/proposervm/getCurrentEpoch.ts) - Returns the current epoch information. [Docs](https://build.avax.network/docs/api-reference/proposervm-api#proposervmgetcurrentepoch)
- [`getProposedHeight`](./src/methods/proposervm/getProposedHeight.ts) - Returns this node's current proposer VM height. [Docs](https://build.avax.network/docs/api-reference/proposervm-api#proposervmgetproposedheight)

## Examples

> **Note:** Make sure to create your own `.env` file by copying the `.env.example` file and updating the values. You'll also need to modify the `config.ts` file to point to your `.env` file path. By default, the examples use the values from `.env.example`, and the test addresses mentioned in the examples as comments (like `0x76Dd3d7b2f635c2547B861e55aE8A374E587742D` and `X-fuji19fc97zn3mzmwr827j4d3n45refkksgms4y2yzz`) are derived from the private key values in that file.

Check out the [examples](./examples) folder for comprehensive usage examples:

### Basic Examples

- [`sendAvax.ts`](./examples/sendAvax.ts) - Basic example of sending AVAX using the SDK

### Primary Network Transaction Examples

The [`prepare-primary-network-txns`](./examples/prepare-primary-network-txns) folder contains examples for preparing various types of transactions:

#### Cross-Chain Transfer Examples

- [`transfer-avax-from-x-chain-to-p-chain.ts`](./examples/prepare-primary-network-txns/transfer-avax-from-x-chain-to-p-chain.ts) - Transfer AVAX from X-Chain to P-Chain
- [`transfer-avax-from-p-chain-to-x-chain.ts`](./examples/prepare-primary-network-txns/transfer-avax-from-p-chain-to-x-chain.ts) - Transfer AVAX from P-Chain to X-Chain
- [`transfer-avax-from-x-chain-to-c-chain.ts`](./examples/prepare-primary-network-txns/transfer-avax-from-x-chain-to-c-chain.ts) - Transfer AVAX from X-Chain to C-Chain
Expand All @@ -640,10 +664,12 @@ The [`prepare-primary-network-txns`](./examples/prepare-primary-network-txns) fo
- [`transfer-avax-from-c-chain-to-p-chain.ts`](./examples/prepare-primary-network-txns/transfer-avax-from-c-chain-to-p-chain.ts) - Transfer AVAX from C-Chain to P-Chain

#### X-Chain Transaction Examples

- [`exportTx.ts`](./examples/prepare-primary-network-txns/x-chain/exportTx.ts) - Prepare X-Chain export transaction
- [`importTx.ts`](./examples/prepare-primary-network-txns/x-chain/importTx.ts) - Prepare X-Chain import transaction

#### P-Chain Transaction Examples

- [`addSubnetValidatorTx.ts`](./examples/prepare-primary-network-txns/p-chain/addSubnetValidatorTx.ts) - Add subnet validator transaction
- [`baseTx.ts`](./examples/prepare-primary-network-txns/p-chain/baseTx.ts) - Base transaction example
- [`convertSubnetToL1Tx.ts`](./examples/prepare-primary-network-txns/p-chain/convertSubnetToL1Tx.ts) - Convert subnet to L1 transaction
Expand All @@ -654,6 +680,7 @@ The [`prepare-primary-network-txns`](./examples/prepare-primary-network-txns) fo
- [`removeSubnetValidatorTx.ts`](./examples/prepare-primary-network-txns/p-chain/removeSubnetValidatorTx.ts) - Remove subnet validator transaction

#### C-Chain Transaction Examples

- [`exportTx.ts`](./examples/prepare-primary-network-txns/c-chain/exportTx.ts) - Prepare C-Chain export transaction
- [`importTx.ts`](./examples/prepare-primary-network-txns/c-chain/importTx.ts) - Prepare C-Chain import transaction

Expand All @@ -679,4 +706,4 @@ If you encounter any issues or have questions, please:

- [GitHub Repository](https://github.com/ava-labs/avalanche-sdk-typescript)
- [Documentation](https://github.com/ava-labs/avalanche-sdk-typescript/tree/main/client#readme)
- [Issue Tracker](https://github.com/ava-labs/avalanche-sdk-typescript/issues)
- [Issue Tracker](https://github.com/ava-labs/avalanche-sdk-typescript/issues)
Loading