Skip to main content
Send native SOL tokens to another wallet.
import { useSolana } from "@phantom/react-sdk";
import {
  Connection,
  PublicKey,
  VersionedTransaction,
  TransactionMessage,
  SystemProgram,
  LAMPORTS_PER_SOL,
} from "@solana/web3.js";

function SendSOL() {
  const { solana } = useSolana();

  const send = async (to: string, amount: number) => {
    const connection = new Connection("https://api.mainnet-beta.solana.com");
    const { blockhash } = await connection.getLatestBlockhash();
    const from = new PublicKey(await solana.getPublicKey());

    const transaction = new VersionedTransaction(
      new TransactionMessage({
        payerKey: from,
        recentBlockhash: blockhash,
        instructions: [
          SystemProgram.transfer({
            fromPubkey: from,
            toPubkey: new PublicKey(to),
            lamports: amount * LAMPORTS_PER_SOL,
          }),
        ],
      }).compileToV0Message()
    );

    const { signature } = await solana.signAndSendTransaction(transaction);
    console.log("Transaction:", signature);
    return signature;
  };

  return (
    <button onClick={() => send("RECIPIENT_ADDRESS", 0.1)}>
      Send 0.1 SOL
    </button>
  );
}