How to Send SOL

To send SOL, you will need to interact with the SystemProgram.

import {
address,
lamports,
createTransaction,
createSolanaClient,
signTransactionMessageWithSigners,
} from "gill";
import { loadKeypairSignerFromFile } from "gill/node";
import { getTransferSolInstruction } from "gill/programs";
const { rpc, sendAndConfirmTransaction } = createSolanaClient({
urlOrMoniker: "devnet",
});
// loads Signer from the default Solana CLI keypair path: `~/.config/solana/id.json`
const signer = await loadKeypairSignerFromFile();
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?