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

# RPC İstemcisi

> Yaygın Solana yöntemleri için yeniden deneme, yedek uç nokta ve tiplenmiş yardımcılar içeren JSON-RPC istemcisi.

## Kurulum

```bash theme={null}
npm install @orbitflare/sdk
```

RPC istemcisinin ekstra peer bağımlılığı yoktur.

## İstemciyi oluşturma

Tüm seçeneklerin ayarlı olduğu bir istemci:

```ts theme={null}
import { RpcClientBuilder, type RetryPolicy } from '@orbitflare/sdk';

const client = new RpcClientBuilder()
  .url('http://ny.rpc.orbitflare.com')
  .fallbackUrl('http://fra.rpc.orbitflare.com')
  .fallbackUrl('http://ams.rpc.orbitflare.com')
  .apiKey('ORBIT-XXXXXX-NNNNNN-NNNNNN')
  .commitment('confirmed')
  .retry({
    initialDelayMs: 100,
    maxDelayMs: 30_000,
    multiplier: 2.0,
    maxAttempts: 5,
  })
  .timeoutMs(30_000)
  .build();
```

Çoğunun makul varsayılanları vardır. Minimal kurulum:

```ts theme={null}
const client = new RpcClientBuilder()
  .url('http://ny.rpc.orbitflare.com')
  .build();
```

### Builder yöntemleri

**`.url(url)`** - İsteklerin gönderileceği birincil uç nokta. Ayarlanmazsa SDK `ORBITFLARE_RPC_URL` ortam değişkenine bakar.

```ts theme={null}
.url('http://ny.rpc.orbitflare.com')
```

**`.urls([...])`** - Birincil ve tüm yedekleri tek çağrıda ayarlar. İlk eleman birincil, kalanlar yedeklerdir.

```ts theme={null}
.urls(['http://ny.rpc.orbitflare.com', 'http://fra.rpc.orbitflare.com', 'http://ams.rpc.orbitflare.com'])
```

**`.fallbackUrl(url)`** - Tek bir yedek uç nokta ekler. Birden fazla eklemek için birden çok kez çağırın. Birincil başarısız olduğunda SDK yedekleri sırayla dener.

```ts theme={null}
.fallbackUrl('http://fra.rpc.orbitflare.com')
.fallbackUrl('http://ams.rpc.orbitflare.com')
```

**`.fallbackUrls([...])`** - `fallbackUrl` ile aynı; dizi alır.

```ts theme={null}
.fallbackUrls(['http://fra.rpc.orbitflare.com', 'http://ams.rpc.orbitflare.com'])
```

**`.apiKey(key)`** - OrbitFlare lisans anahtarınız. Ayarlanmazsa SDK ortamdan `ORBITFLARE_LICENSE_KEY` okur. Anahtar istek zamanında URL'ye eklenir, uç nokta içinde saklanmaz.

```ts theme={null}
.apiKey('ORBIT-XXXXXX-NNNNNN-NNNNNN')
```

**`.commitment(level)`** - Tüm tiplenmiş yardımcılar için kullanılan varsayılan taahhüt düzeyi. Seçenekler: `'processed'`, `'confirmed'`, `'finalized'`. Varsayılan: `'confirmed'`.

```ts theme={null}
.commitment('finalized')
```

**`.retry(policy)`** - Başarısız isteklerin nasıl yeniden deneneceğini denetler. `initialDelayMs` ilk yeniden denemeden önceki beklemedir. `multiplier` her denemede gecikmeyi ölçekler. `maxDelayMs` geri çekilmeyi sınırlar. `maxAttempts` uç nokta başına toplam yeniden denemeyi sınırlar (0 sonsuz anlamına gelir). Varsayılanlar: 100 ms başlangıç, 30 sn üst sınır, 2x çarpan, sınırsız deneme.

```ts theme={null}
.retry({
  initialDelayMs: 200,
  maxDelayMs: 15_000,
  multiplier: 2.0,
  maxAttempts: 5,
})
```

**`.timeoutMs(ms)`** - Her tekil istek için HTTP zaman aşımı. Varsayılan: 30 saniye.

```ts theme={null}
.timeoutMs(10_000)
```

## Kullanılabilir RPC yöntemleri

### `getSlot()`

Geçerli slot numarasını döndürür.

```ts theme={null}
const slot: number = await client.getSlot();
```

### `getBalance(address)`

Bir hesap için lamport cinsinden bakiyeyi döndürür.

```ts theme={null}
const lamports: number = await client.getBalance('So11111111111111111111111111111111111111112');
const sol = lamports / 1_000_000_000;
```

### `getAccountInfo(address)`

Hesap yoksa tam hesap verisini veya `null` döndürür. Veri base64 kodlanmıştır.

```ts theme={null}
const account = await client.getAccountInfo('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
if (account) {
  console.log('owner:', account.owner);
  console.log('lamports:', account.lamports);
  console.log('data length:', (account.data?.[0] ?? '').length);
}
```

### `getMultipleAccounts(addresses)`

Birden çok hesabı tek çağrıda getirir. Otomatik olarak 100'lük gruplara böler (Solana'nın istek başına limiti), bu yüzden istediğiniz kadar adres geçebilirsiniz.

```ts theme={null}
const accounts = await client.getMultipleAccounts(['addr1', 'addr2', 'addr3']);

accounts.forEach((acct, i) => {
  if (acct) console.log(`account ${i}: ${acct.lamports} lamports`);
  else console.log(`account ${i}: not found`);
});
```

### `getLatestBlockhash()`

En son blockhash'i ve geçerliliğinin sona erdiği son blok yüksekliğini döndürür.

```ts theme={null}
const { blockhash, lastValidBlockHeight } = await client.getLatestBlockhash();
```

### `getTransaction(signature)`

İmzasına göre onaylanmış bir işlemi getirir. Üst veriyle birlikte tam işlemi döndürür.

```ts theme={null}
const tx = await client.getTransaction('5K8F2j...');
console.log('slot:', tx.slot);
console.log('fee:', tx.meta?.fee);
```

### `getSignaturesForAddress(address, limit)`

Bir adres için en yeniden eskiye yakın işlem imzalarını döndürür.

```ts theme={null}
const sigs = await client.getSignaturesForAddress('So111...', 10);

for (const sig of sigs) {
  console.log(`${sig.signature} at slot ${sig.slot}`);
}
```

### `getProgramAccounts(programId)`

Bir programa ait tüm hesapları döndürür. Çok fazla veri dönebilir.

```ts theme={null}
const accounts = await client.getProgramAccounts('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
```

### `getRecentPrioritizationFees(addresses)`

Hesap kümesi için son öncelik ücretlerini döndürür. İşlem birimi fiyatlandırmasını tahmin etmek için kullanışlıdır.

```ts theme={null}
const fees = await client.getRecentPrioritizationFees(['6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P']);

for (const fee of fees) {
  console.log(`slot ${fee.slot}: ${fee.prioritizationFee} micro-lamports`);
}
```

### `sendTransaction(txBase64)`

İmzalı işlemi ağa gönderir. Base64 kodlanmış seri işlemi alır. İşlem imzasını döndürür.

```ts theme={null}
const signature: string = await client.sendTransaction(txBase64);
console.log('sent:', signature);
```

### `simulateTransaction(txBase64)`

İşlemi göndermeden simüle eder. Günlükleri, tüketilen işlem birimlerini ve varsa hataları döndürür.

```ts theme={null}
const result = await client.simulateTransaction(txBase64);
if (result.err) {
  console.log('simulation failed:', result.err);
} else {
  console.log('compute units:', result.unitsConsumed);
}
```

### `getTokenAccountsByOwner(owner, mint?, programId?)`

Cüzdan için token hesaplarını döndürür. Belirli bir mint veya bir token programı kimliği verin. İkisi de atlanırsa varsayılan SPL Token programı kullanılır.

```ts theme={null}
const tokens = await client.getTokenAccountsByOwner('wallet_address');

for (const token of tokens) {
  const info = token.account?.data?.parsed?.info;
  console.log(`mint: ${info?.mint} balance: ${info?.tokenAmount?.uiAmountString}`);
}
```

### `getTransactionsForAddress(address, options)`

`getSignaturesForAddress` ve `getTransaction` çağrılarını tek istekte birleştiren OrbitFlare'a özgü yöntem. `data` dizisi ve isteğe bağlı bir sonraki sayfa için `paginationToken` içeren `GetTransactionsResult` döndürür.

Dört ayrıntı düzeyini (`signatures`, `none`, `accounts`, `full`), çift yönlü sıralamayı, zaman/slot filtrelerini, durum filtrelerini ve token hesabı dahilini destekler.

```ts theme={null}
const result = await client.getTransactionsForAddress('address', {
  transactionDetails: 'full',
  limit: 100,
  sortOrder: 'asc',
  filters: {
    tokenAccounts: 'all',
    status: 'succeeded',
    blockTime: { gte: 1704067200, lte: 1706745600 },
  },
});

for (const tx of result.data) {
  console.log(`slot ${tx.slot}`);
}

if (result.paginationToken) {
  // fetch next page using { paginationToken: result.paginationToken }
}
```

### `request(method, params)`

Herhangi bir RPC yöntemini ada göre çağırır. SDK JSON-RPC zarfını oluşturur, yeniden deneme ve yedek uç noktayı yönetir ve `result` alanını döndürür.

```ts theme={null}
const epoch = await client.request('getEpochInfo', []);
const inflation = await client.request('getInflationRate', []);
const supply = await client.request('getSupply', []);
```

### `requestRaw(body)`

Ham JSON-RPC gövde dizgesi gönderir. Diğer her şeyle aynı yeniden deneme ve yedek uç nokta davranışı.

```ts theme={null}
const result = await client.requestRaw(
  '{"jsonrpc":"2.0","id":1,"method":"getHealth","params":[]}',
);
```

## Tam örnek

Ağ durumunu kontrol eden, bir cüzdanın SOL bakiyesini ve token varlıklarını çeken ve son işlemlere bakan bir betik.

```ts theme={null}
import { RpcClientBuilder } from '@orbitflare/sdk';

async function main() {
  const client = new RpcClientBuilder()
    .url('http://ny.rpc.orbitflare.com')
    .fallbackUrl('http://fra.rpc.orbitflare.com')
    .commitment('confirmed')
    .build();

  const wallet = 'CKs1E69a2e9TmH4mKKLrXFF8kD3ZnwKjoEuXa6sz9WqX';

  const slot = await client.getSlot();
  const { blockhash } = await client.getLatestBlockhash();
  console.log(`network slot: ${slot}`);
  console.log(`blockhash: ${blockhash}`);

  const balance = await client.getBalance(wallet);
  console.log(`\n${wallet}`);
  console.log(`  SOL: ${(balance / 1_000_000_000).toFixed(4)}`);

  const tokens = await client.getTokenAccountsByOwner(wallet);
  for (const token of tokens) {
    const info = token?.account?.data?.parsed?.info;
    const mint = info?.mint ?? 'unknown';
    const amount = info?.tokenAmount?.uiAmountString ?? '0';
    if (amount !== '0') console.log(`  ${mint}: ${amount}`);
  }

  const sigs = await client.getSignaturesForAddress(wallet, 5);
  console.log('\nrecent transactions:');
  for (const sig of sigs) {
    const signature = sig?.signature ?? '?';
    const status = sig?.err == null ? 'ok' : 'failed';
    console.log(`  ${sig?.slot ?? 0} ${status} ${signature.slice(0, 20)}`);
  }

  const fees = await client.getRecentPrioritizationFees([wallet]);
  const total = fees.reduce(
    (acc: number, f: any) =>
      acc + (typeof f?.prioritizationFee === 'number' ? f.prioritizationFee : 0),
    0,
  );
  const avg = total / Math.max(fees.length, 1);
  console.log(`\navg priority fee: ${avg.toFixed(0)} micro-lamports`);
}

void main();
```
