
Send SOL (Lamports)
Send Lamports
Send Sol
Send Solana
Send Solana (Lamports) to a given address. Lamports are the native currency of the Solana blockchain (1 SOL = 1,000,000,000 lamports).
import { Connection, Keypair, LAMPORTS_PER_SOL, SystemProgram, Transaction, sendAndConfirmTransaction } from "@solana/web3.js";
const connection = new Connection("https://api.mainnet-beta.solana.com", {
commitment: "processed",
});
const fromKeypair = Keypair.generate();
const toPubkey = Keypair.generate().publicKey;
const tx = new Transaction().add(
SystemProgram.transfer({
fromPubkey: fromKeypair.publicKey,
toPubkey: toPubkey,
lamports: LAMPORTS_PER_SOL * 0.1, // 0.1 SOL
})
);
await sendAndConfirmTransaction(connection, tx, [fromKeypair]);

CAVYAR AI
CAVYAR AI is in its earliest stages of development and the quality of generated descriptions will improve massively over time. At this stage, there is a risk of false information being generated.
This code snippet transfers 0.1 SOL from a randomly generated account to another randomly generated account on the Solana blockchain.
Explanation:
- The
Connection
class is imported from@solana/web3.js
to establish a connection to the Solana blockchain. In this case, it connects to the mainnet-beta network. - The
Keypair
class is imported from@solana/web3.js
to generate a random keypair. ThefromKeypair
variable holds the randomly generated keypair, which will be used as the sender's account. - Another random keypair is generated using
Keypair.generate().publicKey
, and the resulting public key is stored in thetoPubkey
variable. This will be the recipient's account. - The
Transaction
class is imported from@solana/web3.js
to create a new transaction object. - The
SystemProgram.transfer()
function is called to create a transfer instruction within the transaction. It specifies the sender's public key (fromPubkey
), the recipient's public key (toPubkey
), and the amount of lamports (the smallest unit of SOL) to transfer (lamports
). - The
LAMPORTS_PER_SOL
constant is imported from@solana/web3.js
and represents the number of lamports in one SOL. In this case, it is multiplied by 0.1 to transfer 0.1 SOL. - The transfer instruction is added to the transaction using the
add()
method. - The
sendAndConfirmTransaction()
function is called to send the transaction to the Solana blockchain for processing. It takes the connection object, the transaction object, and an array of signers (in this case, only thefromKeypair
signer) as arguments. - The
await
keyword is used to wait for the transaction to be confirmed on the blockchain before proceeding.
Ask

Soon™