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

# Helius SDKを使用したプログラムによるSolanaステーキング

> Helius SDKでシームレスなSolanaステーキング体験を構築。セットアップから出金までの完全ガイド（0%手数料バリデータ統合）。

<Info>
  **ゼロコミッションバリデータ**: Heliusバリデータでステークし、手数料0%でステーキングリワードを100%手に入れましょう。
</Info>

## クイック概要

Helius SDKは、プログラムで完全なSOLステーキングライフサイクルを処理する簡単な方法を提供します。ステーキングインターフェース、DeFiプロトコル、または自動ステーキング戦略を構築するのに最適です。

<CardGroup cols={3}>
  <Card title="作成＆委任" icon="plus">
    新しいステークアカウントを作成し、一つのトランザクションでバリデータに委任
  </Card>

  <Card title="監視＆管理" icon="chart-line">
    報酬を追跡し、ステータスを確認し、既存のステークアカウントを管理
  </Card>

  <Card title="引き出し＆償還" icon="money-bill">
    クールダウン期間後にステークを非アクティブ化しSOLを引き出し
  </Card>
</CardGroup>

## インストール＆セットアップ

<CodeGroup>
  ```bash npm theme={"system"}
  npm install helius-sdk @solana/web3.js bs58
  ```

  ```bash yarn   theme={"system"}
  yarn add helius-sdk @solana/web3.js bs58
  ```

  ```bash pnpm theme={"system"}
  pnpm add helius-sdk @solana/web3.js bs58
  ```
</CodeGroup>

<CodeGroup>
  ```typescript Setup theme={"system"}
  import { Helius } from 'helius-sdk';
  import { Keypair, Transaction } from '@solana/web3.js';
  import bs58 from 'bs58';

  // Initialize Helius client
  const helius = new Helius('YOUR_API_KEY');

  // Your wallet keypair (load from your secure storage)
  const payer = Keypair.fromSecretKey(/* your secret key */);
  ```
</CodeGroup>

## ステーキングの基本

<AccordionGroup>
  <Accordion title="Solanaステーキングの仕組み">
    **ステークアカウント**: SOLをロックしバリデータに委任する特別なアカウント。各ステークアカウントは1つのバリデータを指します。

    **リワード**: バリデータはネットワークを保護するための報酬を獲得します。これらの報酬は、そのバリデータに委任されたすべてのステークアカウントに分配されます。

    **ライフサイクル**: 作成 → 委任 → リワード獲得 → 非アクティブ化 → 引き出し
  </Accordion>

  <Accordion title="Heliusバリデータを選ぶ理由">
    * **0% 手数料**: ステーキングリワードの100%を保持
    * **高性能**: 信頼できるブロック生成と最小限のダウンタイム
    * **簡単な統合**: Helius SDKに最適化され組み込みのヘルパーが付属
  </Accordion>

  <Accordion title="タイミングとエポック">
    * **アクティベーション**: ステークは次のエポック開始時にアクティブ
    * **非アクティベーション**: 現在のエポック終了時に発効
    * **クールダウン**: 非アクティブ化したステークはエポック終了後すぐに引き出し可能
  </Accordion>
</AccordionGroup>

## はじめに

<Tabs>
  <Tab title="クイックスタート">
    3行のコードでSOLをステーク:

    ```typescript theme={"system"}
    // 1. Create the staking transaction
    const { serializedTx, stakeAccountPubkey } = 
      await helius.rpc.createStakeTransaction(payer.publicKey, 1.5);

    // 2. Sign and send
    const tx = Transaction.from(bs58.decode(serializedTx));
    tx.partialSign(payer);
    const signature = await helius.connection.sendRawTransaction(tx.serialize());

    console.log(`Staked! Transaction: ${signature}`);
    console.log(`Stake Account: ${stakeAccountPubkey}`);
    ```

    <Info>
      SDKは自動的にレン​​ト計算とステークアカウントの作成を処理します。`1.5`パラメータはステークするSOLの量です。
    </Info>
  </Tab>

  <Tab title="完全な例">
    エラーハンドリングを含む完全なステーキング実装:

    ```typescript theme={"system"}
    async function stakeSOL(amountInSol: number) {
      try {
        // Create staking transaction
        const { serializedTx, stakeAccountPubkey } = 
          await helius.rpc.createStakeTransaction(payer.publicKey, amountInSol);
        
        // Deserialize and sign transaction
        const transaction = Transaction.from(bs58.decode(serializedTx));
        transaction.partialSign(payer);
        
        // Send transaction
        const signature = await helius.connection.sendRawTransaction(
          transaction.serialize(),
          { 
            skipPreflight: false,
            preflightCommitment: 'confirmed'
          }
        );
        
        // Wait for confirmation
        await helius.connection.confirmTransaction(signature, 'confirmed');
        
        return {
          signature,
          stakeAccount: stakeAccountPubkey,
          amount: amountInSol
        };
        
      } catch (error) {
        console.error('Staking failed:', error);
        throw error;
      }
    }

    // Usage
    const result = await stakeSOL(2.5);
    console.log(`Successfully staked ${result.amount} SOL`);
    ```
  </Tab>
</Tabs>

## SDKメソッドリファレンス

<AccordionGroup>
  <Accordion title="createStakeTransaction(owner, amount)">
    署名および送信可能な完全なステーキングトランザクションを作成します。

    **パラメータ:**

    * `owner` (PublicKey): ステークアカウントを所有するウォレット
    * `amount` (number): ステークするSOLの量

    **戻り値:**

    ```typescript theme={"system"}
    {
      serializedTx: string,        // Base58 encoded transaction
      stakeAccountPubkey: string   // New stake account address
    }
    ```

    **例:**

    ```typescript theme={"system"}
    const result = await helius.rpc.createStakeTransaction(
      payer.publicKey, 
      1.5  // 1.5 SOL
    );
    ```
  </Accordion>

  <Accordion title="getStakeInstructions(owner, amount)">
    ステーキングの指示のみを返します（カスタムトランザクションの構築に役立ちます）。

    **戻り値:**

    ```typescript theme={"system"}
    {
      instructions: TransactionInstruction[],
      stakeAccount: Keypair
    }
    ```

    **例:**

    ```typescript theme={"system"}
    const { instructions } = await helius.rpc.getStakeInstructions(
      payer.publicKey, 
      1.5
    );

    // Use with Smart Transactions
    const signature = await helius.rpc.sendSmartTransaction(
      instructions, 
      [payer]
    );
    ```
  </Accordion>

  <Accordion title="getHeliusStakeAccounts(wallet)">
    ウォレットのHeliusバリデータに委任されたすべてのステークアカウントを取得します。

    **例:**

    ```typescript theme={"system"}
    const accounts = await helius.rpc.getHeliusStakeAccounts(
      payer.publicKey.toBase58()
    );

    accounts.forEach(account => {
      const delegation = account.account.data.parsed.info.stake.delegation;
      console.log(`Account: ${account.pubkey}`);
      console.log(`Stake: ${delegation.stake / LAMPORTS_PER_SOL} SOL`);
    });
    ```
  </Accordion>

  <Accordion title="createUnstakeTransaction(owner, stakeAccount)">
    ステークを非アクティブ化（ステーキング開始）するためのトランザクションを作成します。

    **例:**

    ```typescript theme={"system"}
    const tx = await helius.rpc.createUnstakeTransaction(
      payer.publicKey,
      stakeAccountPubkey
    );

    const transaction = Transaction.from(bs58.decode(tx));
    transaction.partialSign(payer);
    await helius.connection.sendRawTransaction(transaction.serialize());
    ```
  </Accordion>

  <Accordion title="getWithdrawableAmount(stakeAccount, includeRent?)">
    非アクティブ化されたステークアカウントから引き出せるSOLの量を確認します。

    **パラメータ:**

    * `includeRent` (boolean): レント免除額を含めるかどうか

    **例:**

    ```typescript theme={"system"}
    const available = await helius.rpc.getWithdrawableAmount(stakeAccountPubkey);
    const total = await helius.rpc.getWithdrawableAmount(stakeAccountPubkey, true);

    console.log(`Available now: ${available / LAMPORTS_PER_SOL} SOL`);
    console.log(`Total balance: ${total / LAMPORTS_PER_SOL} SOL`);
    ```
  </Accordion>

  <Accordion title="createWithdrawTransaction(owner, stakeAccount, destination, amount)">
    非アクティブ化されたステークアカウントからSOLを引き出すためのトランザクションを作成します。

    **例:**

    ```typescript theme={"system"}
    const tx = await helius.rpc.createWithdrawTransaction(
      payer.publicKey,
      stakeAccountPubkey,
      destinationPubkey,
      withdrawAmount  // in lamports
    );
    ```
  </Accordion>
</AccordionGroup>

## 完全なステーキングワークフロー

<Steps>
  <Step title="作成と委任">
    ```typescript theme={"system"}
    // Stake 2 SOL to Helius validator
    const { serializedTx, stakeAccountPubkey } = 
      await helius.rpc.createStakeTransaction(payer.publicKey, 2.0);

    const tx = Transaction.from(bs58.decode(serializedTx));
    tx.partialSign(payer);

    const signature = await helius.connection.sendRawTransaction(tx.serialize());
    console.log(`Stake created: ${stakeAccountPubkey}`);
    ```
  </Step>

  <Step title="ステークの監視">
    ```typescript theme={"system"}
    // Get all your Helius stake accounts
    const accounts = await helius.rpc.getHeliusStakeAccounts(
      payer.publicKey.toBase58()
    );

    console.log(`You have ${accounts.length} active stake accounts`);

    accounts.forEach((account, index) => {
      const info = account.account.data.parsed.info;
      const delegation = info.stake.delegation;
      
      console.log(`Stake ${index + 1}:`);
      console.log(`  Amount: ${delegation.stake / LAMPORTS_PER_SOL} SOL`);
      console.log(`  Activated: Epoch ${delegation.activationEpoch}`);
      console.log(`  Status: ${info.meta.lockup.unixTimestamp === 0 ? 'Active' : 'Locked'}`);
    });
    ```
  </Step>

  <Step title="非アクティブ化（ステーキング開始）">
    ```typescript theme={"system"}
    // Begin the unstaking process
    const unstakeTx = await helius.rpc.createUnstakeTransaction(
      payer.publicKey,
      stakeAccountPubkey
    );

    const tx = Transaction.from(bs58.decode(unstakeTx));
    tx.partialSign(payer);

    await helius.connection.sendRawTransaction(tx.serialize());
    console.log('Deactivation started. Will be withdrawable next epoch.');
    ```
  </Step>

  <Step title="SOLの引き出し">
    ```typescript theme={"system"}
    // Check withdrawable amount
    const withdrawable = await helius.rpc.getWithdrawableAmount(
      stakeAccountPubkey, 
      true  // include rent
    );

    if (withdrawable > 0) {
      // Create withdrawal instruction
      const withdrawInstruction = helius.rpc.getWithdrawInstruction(
        payer.publicKey,
        stakeAccountPubkey,
        payer.publicKey,  // withdraw to same wallet
        withdrawable
      );
      
      // Send using Smart Transactions for better reliability
      const signature = await helius.rpc.sendSmartTransaction(
        [withdrawInstruction], 
        [payer]
      );
      
      console.log(`Withdrawn ${withdrawable / LAMPORTS_PER_SOL} SOL`);
    }
    ```
  </Step>
</Steps>

## 高度なパターン

<Tabs>
  <Tab title="ブラウザ統合">
    ウォレットアダプターを使用したブラウザアプリケーション向け:

    ```typescript theme={"system"}
    // Get instructions instead of full transaction
    const { instructions, stakeAccount } = await helius.rpc.getStakeInstructions(
      wallet.publicKey,
      stakeAmount
    );

    // Let the wallet handle transaction building and signing
    const transaction = new Transaction().add(...instructions);

    // Sign with wallet adapter
    const signature = await wallet.sendTransaction(transaction, connection);

    console.log(`Stake account: ${stakeAccount.publicKey.toBase58()}`);
    ```
  </Tab>

  <Tab title="バッチ操作">
    複数のウォレットを効率的にステーク:

    ```typescript theme={"system"}
    async function batchStake(wallets: Keypair[], amount: number) {
      const promises = wallets.map(async (wallet) => {
        try {
          const { serializedTx, stakeAccountPubkey } = 
            await helius.rpc.createStakeTransaction(wallet.publicKey, amount);
          
          const tx = Transaction.from(bs58.decode(serializedTx));
          tx.partialSign(wallet);
          
          return helius.connection.sendRawTransaction(tx.serialize());
        } catch (error) {
          console.error(`Failed to stake for ${wallet.publicKey.toBase58()}:`, error);
          return null;
        }
      });
      
      const results = await Promise.allSettled(promises);
      const successful = results.filter(r => r.status === 'fulfilled').length;
      
      console.log(`Successfully staked for ${successful}/${wallets.length} wallets`);
    }
    ```
  </Tab>

  <Tab title="スマートトランザクション">
    信頼性と最適化を向上させるためにスマートトランザクションを使用:

    ```typescript theme={"system"}
    // Get individual instructions
    const { instructions } = await helius.rpc.getStakeInstructions(
      payer.publicKey,
      2.5
    );

    // Send with Smart Transaction features:
    // - Automatic priority fee optimization
    // - Retry logic with backoff
    // - Better error handling
    const signature = await helius.rpc.sendSmartTransaction(
      instructions,
      [payer],
      {
        skipPreflight: false,
        maxRetries: 3
      }
    );

    console.log(`Smart transaction sent: ${signature}`);
    ```
  </Tab>
</Tabs>

## 重要な注意事項

<Warning>
  **エポックのタイミング**: Solanaエポックは約2日間持続します。ステークは次のエポック開始時にアクティブになり、非アクティブ化は現在のエポック終了時に発効します。
</Warning>

<Note>
  **レン​​トの考慮事項**: ステークアカウントはレン​​ト免除のリザーブ（約0.00228 SOL）が必要です。残高全額を引き出すとアカウントが閉鎖されます。
</Note>

<Tip>
  **ハードウェアウォレット**: ユーザーは2つの署名プロンプトを見ることになります - ステークアカウント用（事前に署名済み）と手数料支払者用。UXをそれに応じて設計してください。
</Tip>

## クイックリファレンス

クイックリマインダーが必要ですか？ ここに重要なメソッドがあります:

```typescript theme={"system"}
// Stake SOL
await helius.rpc.createStakeTransaction(owner, amountInSol);

// Check your stakes  
await helius.rpc.getHeliusStakeAccounts(ownerAddress);

// Start unstaking
await helius.rpc.createUnstakeTransaction(owner, stakeAccount);

// Check withdrawable amount
await helius.rpc.getWithdrawableAmount(stakeAccount, includeRent);

// Withdraw SOL
helius.rpc.getWithdrawInstruction(owner, stakeAccount, destination, amount);
```

## 次のステップ

<CardGroup cols={2}>
  <Card title="Helius SDKドキュメント" icon="code" href="https://github.com/helius-labs/helius-sdk">
    利用可能なすべてのメソッドを持つ完全なSDKリファレンス
  </Card>

  <Card title="スマートトランザクション" icon="bolt" href="/ja/sending-transactions/optimizing-transactions">
    優先手数料と再試行ロジックでトランザクションを最適化
  </Card>

  <Card title="Discordに参加" icon="discord" href="https://discord.com/invite/6GXdee3gBj">
    開発者コミュニティからヘルプを得る
  </Card>

  <Card title="バリデータダッシュボード" icon="chart-bar" href="https://www.validators.app/validators/EKgWgpJY5BtX7TeJfhKbqcJT7gzLKFFtj7cjX1XY6CxA">
    Heliusバリデータのパフォーマンスとリワードを監視
  </Card>
</CardGroup>
