Solana CookbookTransactions
How to Send SOL
To send SOL, you will need to interact with the SystemProgram.
import {address,lamports,createTransaction,createSolanaClient,signTransactionMessageWithSigners,generateKeyPairSigner,airdropFactory} from "gill";// @ts-ignoreimport { getTransferSolInstruction } from "gill/programs";const { rpc, rpcSubscriptions, sendAndConfirmTransaction } = createSolanaClient({urlOrMoniker: "http://127.0.0.1:8899"});const signer = await generateKeyPairSigner();await airdropFactory({ rpc, rpcSubscriptions })({commitment: "confirmed",lamports: lamports(5_000_000n),recipientAddress: signer.address});const destination = address("nick6zJc6HpW3kfBm4xS2dmbuVRyb5F3AnUvj5ymzR5");const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();const tx = createTransaction({version: "legacy",feePayer: signer,instructions: [getTransferSolInstruction({source: signer,destination,amount: lamports(1_000_000n)})],latestBlockhash});const signedTransaction = await signTransactionMessageWithSigners(tx);await sendAndConfirmTransaction(signedTransaction);
Is this page helpful?