export const sendSol = async ({
fromAddress,
toAddress,
amount,
}: {
fromAddress: string;
toAddress: string;
amount: number; // Amount in SOL
}) => {
const svmClient = await authenticatedSvmClient();
// Create transaction
const fromPubkey = new PublicKey(fromAddress);
const toPubkey = new PublicKey(toAddress);
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey,
toPubkey,
lamports: LAMPORTS_PER_SOL * amount,
})
);
// Sign transaction
// Note: If using manual backup (backUpToClientShareService: false),
// you'll need to provide externalServerKeyShares here
const signedTransaction = await svmClient.signTransaction({
senderAddress: fromAddress,
transaction,
});
// Send transaction
const connection = new Connection('https://api.devnet.solana.com', 'confirmed');
const txHash = await sendAndConfirmTransaction(connection, signedTransaction);
return txHash;
};
// Usage
const txHash = await sendSol({
fromAddress: 'YourSolanaWalletAddress',
toAddress: 'RecipientAddress',
amount: 0.001,
});
console.log('SOL sent:', txHash);