Writing to the Network
Transfer SOL
import {
LAMPORTS_PER_SOL, SystemProgram, Transaction,
sendAndConfirmTransaction, Keypair,
} from "@solana/web3.js";
// Connect to CARV SVM Chain's RPC endpointconst rpcUrl = "https://rpc.testnet.carv.io/rpc";
const connection = new pg.Connection(rpcUrl);
// Get sender's keypair from the playground wallet
const sender = pg.wallet.keypair;
// Generate a new keypair for the receiver
const receiver = new Keypair();
// Create the transfer instruction
const transferInstruction = SystemProgram.transfer({
fromPubkey: sender.publicKey, toPubkey: receiver.publicKey, lamports: 0.01 * LAMPORTS_PER_SOL, // Transfer 0.01 SOL
});
// Add the instruction to a new transaction
const transaction = new Transaction().add(transferInstruction);
// Send and confirm the transaction
const transactionSignature = await sendAndConfirmTransaction(
connection,
transaction,
[sender]
);
// Log the transaction URL using CARV’s explorer
console.log("Transaction Signature:",`https://explorer.ops.soo.network/?cluster=custom&customUrl=https%3A%2F%2Frpc.carv.testnet.soo.network%2Frpc%2Fcarv-McPrlbfMcW0ggpkvr07Tjs2YfviwpHaI/${transactionSignature}`);Last updated