Transfer SOL tokens using Solana Web3.js or Anchor with Para wallets
Transfer SOL tokens between wallets using Para’s integrated signers with different Solana libraries.
import { useParaSolana } from './hooks/useParaSolana';
import { Transaction, SystemProgram, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
function SendTokens() {
const { connection, signer } = useParaSolana();
const sendSOL = async (recipient: string, amount: number) => {
if (!signer) {
console.error("No signer available. Connect wallet first.");
return;
}
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: signer.sender,
toPubkey: new PublicKey(recipient),
lamports: LAMPORTS_PER_SOL * amount,
})
);
const signature = await signer.sendTransaction(transaction);
console.log("Transaction signature:", signature);
await connection.confirmTransaction(signature, "confirmed");
console.log("Transaction confirmed");
return signature;
};
return (
<button onClick={() => sendSOL("RECIPIENT_ADDRESS", 0.1)}>
Send 0.1 SOL
</button>
);
}