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

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Token Testi

> @solana-program/token ve LiteSVM ile SPL token'ları test edin

Solana'da token mantığını test etmek, asıl önemsediğiniz transfer mantığını test edebilmeden önce mint'leri, token account'ları ve yetkilileri kurmayı gerektirir. `@solana-program/token` paketindeki `tokenProgram()` eklentisi bu kurulumu birkaç metot çağrısına indirger ve ATA oluşturmayı otomatik olarak yönetir.

[`@solana-program/token` paketini npm'de görüntüleyin](https://www.npmjs.com/package/@solana-program/token)

## Kurulum

```bash
npm install @solana/kit @solana/kit-plugin-litesvm @solana/kit-plugin-signer @solana-program/token
```

## Mint Oluşturma

```typescript
import { createClient, generateKeyPairSigner, lamports } from "@solana/kit";
import { litesvm } from "@solana/kit-plugin-litesvm";
import { signer } from "@solana/kit-plugin-signer";
import { tokenProgram } from "@solana-program/token";

const mySigner = await generateKeyPairSigner();
const client = createClient()
  .use(signer(mySigner))
  .use(litesvm())
  .use(tokenProgram());

client.svm.airdrop(client.payer.address, lamports(10_000_000_000n));

const mintAuthority = await generateKeyPairSigner();
const newMint = await generateKeyPairSigner();

await client.token.instructions
  .createMint({
    newMint,
    decimals: 9,
    mintAuthority: mintAuthority.address
  })
  .sendTransaction();

// Verify
const mintAccount = await client.token.accounts.mint.fetch(newMint.address);
console.log(mintAccount.data.supply); // 0n
console.log(mintAccount.data.decimals); // 9
```

## Token Basma

`mintToATA`, token'ları bir sahibin Associated Token Account'una basar. ATA mevcut değilse aynı işlemde oluşturulur.

```typescript
await client.token.instructions
  .mintToATA({
    mint: newMint.address,
    owner: client.payer.address,
    mintAuthority,
    amount: 1_000_000_000_000n, // 1000 tokens (9 decimals)
    decimals: 9
  })
  .sendTransaction();
```

`decimals` parametresi bir güvenlik kontrolüdür — mint'in decimals değeriyle tam olarak eşleşmelidir; aksi halde Token program, işlemi `Custom program error: #18` (`0x12`, `MintDecimalsMismatch`) hatasıyla reddeder. Bu, yanlışlıkla 1000 kat fazla token basılmasını önler.

## Token Transferi

`transferToATA`, token'ları kullanıcılar arasında taşır. Alıcının ATA'sı gerekirse otomatik olarak oluşturulur.

```typescript
const alice = await generateKeyPairSigner();
const bob = await generateKeyPairSigner();

// Mint to Alice
await client.token.instructions
  .mintToATA({
    mint: newMint.address,
    owner: alice.address,
    mintAuthority,
    amount: 1_000_000_000_000n,
    decimals: 9
  })
  .sendTransaction();

// Transfer 400 tokens from Alice to Bob
await client.token.instructions
  .transferToATA({
    mint: newMint.address,
    authority: alice,
    recipient: bob.address,
    amount: 400_000_000_000n,
    decimals: 9
  })
  .sendTransaction();
```

`authority`, kaynak token'ların sahibi olan imzalayandır. Eklenti, hem kaynak hem de hedef ATA'ları adreslerinden + mint'ten türetir.

## Bakiyeleri Doğrulama

Token bakiyelerini geri okumak için ATA adresini `findAssociatedTokenPda` ile türetin ve çözümlenmiş hesabı getirin:

```typescript
import {
  findAssociatedTokenPda,
  TOKEN_PROGRAM_ADDRESS
} from "@solana-program/token";

const [aliceAta] = await findAssociatedTokenPda({
  owner: alice.address,
  mint: newMint.address,
  tokenProgram: TOKEN_PROGRAM_ADDRESS
});

const aliceAccount = await client.token.accounts.token.fetch(aliceAta);
console.log(aliceAccount.data.amount); // 600_000_000_000n
console.log(aliceAccount.data.mint); // newMint.address
console.log(aliceAccount.data.owner); // alice.address
```

## Ondalık Basamaklar

Token miktarları her zaman ham birimlerle ifade edilir. 9 ondalık basamaklı 1000 token, `1000n` değil, `1_000_000_000_000n` değeridir.

```typescript
// USDC has 6 decimals
const oneUSDC = 10n ** 6n; // 1_000_000n

// SOL has 9 decimals
const oneSOL = 10n ** 9n; // 1_000_000_000n
```

<Warning>
  Token miktarları için her zaman `BigInt` kullanın. JavaScript'in `Number` türü 2^53 üzerinde hassasiyet kaybeder.
</Warning>

## Eklenti Referansı

| Metot                                      | Açıklama                                                  |
| ------------------------------------------- | ------------------------------------------------------------ |
| `client.token.instructions.createMint()`    | Yeni bir SPL token mint'i oluşturur                                  |
| `client.token.instructions.mintToATA()`     | Token'ları bir sahibin ATA'sına basar (gerekirse ATA oluşturur)        |
| `client.token.instructions.transferToATA()` | Token'ları bir alıcının ATA'sına aktarır (gerekirse ATA oluşturur) |
| `client.token.accounts.mint.fetch()`        | Bir mint account'u getirir ve çözümler                              |
| `client.token.accounts.token.fetch()`       | Bir token account'u getirir ve çözümler                             |

## Sık Karşılaşılan Hatalar

| Hata                                                               | Neden                             | Çözüm                                                    |
| ------------------------------------------------------------------- | --------------------------------- | ------------------------------------------------------ |
| `Custom program error: #18` (`0x12`, `MintDecimalsMismatch`)        | `decimals` değeri mint ile eşleşmiyor | `createMint` işlevine verdiğiniz decimals değerinin aynısını kullanın |
| `Account not found at address: ...`                                 | Hesap henüz mevcut değil         | Getirme veya basma işleminden önce mint'in oluşturulduğundan emin olun  |
| `Attempt to debit an account but found no record of a prior credit` | Ücretleri ödeyecek hesapta SOL yok  | Önce ödeme yapacak hesaba SOL airdrop edin                         |
| `Custom program error: #4` (`OwnerMismatch`)                       | İmzalayan `authority`, kaynak token account'un sahibi değil | `authority` olarak gerçek sahibi verin     |
