> ## 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.

# Trasferimento di SOL

> Crea e invia una transazione di trasferimento di SOL con litesvm-go

La transazione Solana più semplice: spostare SOL da un account a un altro. È
un ottimo primo test per verificare che la configurazione di `litesvm-go` funzioni prima di testare una
logica di programma più complessa.

## Esempio completo

```go
package mytest

import (
    "testing"

    litesvm "github.com/LiteSVM/litesvm-go"
    solana "github.com/gagliardetto/solana-go"
    "github.com/gagliardetto/solana-go/programs/system"
)

func TestSolTransfer(t *testing.T) {
    svm, err := litesvm.New()
    if err != nil {
        t.Fatal(err)
    }
    defer svm.Close()

    // Generate payer + recipient.
    priv, err := solana.NewRandomPrivateKey()
    if err != nil {
        t.Fatal(err)
    }
    payer := priv.PublicKey()
    recipient := solana.NewWallet().PublicKey()

    // Airdrop SOL to the payer.
    if err := svm.Airdrop(payer, 10_000_000_000); err != nil {
        t.Fatal(err)
    }

    // Check initial balance.
    senderInitial, _, err := svm.Balance(payer)
    if err != nil {
        t.Fatal(err)
    }
    t.Logf("sender initial: %.3f SOL", float64(senderInitial)/1e9)

    // Build, sign, and encode the transfer.
    blockhash, err := svm.LatestBlockhash()
    if err != nil {
        t.Fatal(err)
    }
    ix := system.NewTransferInstruction(1_000_000_000, payer, recipient).Build()
    tx, err := solana.NewTransaction(
        []solana.Instruction{ix},
        blockhash,
        solana.TransactionPayer(payer),
    )
    if err != nil {
        t.Fatal(err)
    }
    if _, err := tx.Sign(func(k solana.PublicKey) *solana.PrivateKey {
        if k.Equals(payer) {
            return &priv
        }
        return nil
    }); err != nil {
        t.Fatal(err)
    }
    txBytes, err := tx.MarshalBinary()
    if err != nil {
        t.Fatal(err)
    }

    // Execute the transfer.
    out, err := svm.SendLegacyTransaction(txBytes)
    if err != nil {
        t.Fatal(err)
    }

    if !out.IsOk() {
        t.Fatalf("tx failed: %s\nlogs: %v", out.Error(), out.Logs())
    }

    // Check final balances.
    senderFinal, _, err := svm.Balance(payer)
    if err != nil {
        t.Fatal(err)
    }
    recipientFinal, _, err := svm.Balance(recipient)
    if err != nil {
        t.Fatal(err)
    }
    t.Logf("sender final:    %.6f SOL", float64(senderFinal)/1e9)
    t.Logf("recipient final: %.3f SOL", float64(recipientFinal)/1e9)
    t.Logf("compute units:   %d", out.ComputeUnits())
    t.Logf("fee:             %d lamports", out.Fee())
}
```

## Output previsto

```
sender initial: 10.000 SOL
sender final:    8.999995 SOL
recipient final: 1.000 SOL
compute units:   150
fee:             5000 lamports
```

<Info>
  Il saldo finale del mittente è leggermente inferiore a 9 SOL a causa delle commissioni di transazione
  (5.000 lamport per firma).
</Info>

Questo copre il tipo di transazione più semplice. Per testare programmi personalizzati, consulta
[Test dei programmi](/developers/docs/tools/litesvm/go/examples/program-testing). Per la
logica dipendente dal tempo, consulta
[Test basati sul tempo](/developers/docs/tools/litesvm/go/examples/time-based).
