import {
Connection,
PublicKey,
Transaction,
SystemProgram,
LAMPORTS_PER_SOL,
} from "@solana/web3.js";
const connection = new Connection("https://api.devnet.solana.com");
function buildTransferTransaction(
fromPubkey: PublicKey,
toPubkey: PublicKey,
solAmount: number
): Transaction {
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey,
toPubkey,
lamports: Math.round(solAmount * LAMPORTS_PER_SOL),
})
);
return transaction;
}
Always use LAMPORTS_PER_SOL for conversion. Never hardcode 1000000000.
import { useSolana, useAccounts } from "@phantom/react-sdk";
import { PublicKey, Transaction, SystemProgram, LAMPORTS_PER_SOL } from "@solana/web3.js";
function SendSol() {
const solana = useSolana();
const { accounts } = useAccounts();
const sendTransaction = async () => {
const solanaAccount = accounts.find((a) => a.chain === "solana");
if (!solanaAccount) {
console.error("No Solana account connected");
return;
}
const fromPubkey = new PublicKey(solanaAccount.address);
const toPubkey = new PublicKey("RECIPIENT_ADDRESS_HERE");
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey,
toPubkey,
lamports: Math.round(0.01 * LAMPORTS_PER_SOL),
})
);
try {
const { signature } = await solana.signAndSendTransaction(transaction);
console.log("Transaction signature:", signature);
console.log(
`View on Explorer: https://explorer.solana.com/tx/${signature}?cluster=devnet`
);
} catch (error) {
console.error("Transaction failed:", error);
}
};
return <button onClick={sendTransaction}>Send 0.01 SOL</button>;
}
import { PublicKey, Transaction, SystemProgram, LAMPORTS_PER_SOL } from "@solana/web3.js";
async function sendSol(sdk: BrowserSDK) {
const solanaAccount = sdk.accounts.find((a) => a.chain === "solana");
if (!solanaAccount) {
throw new Error("No Solana account connected");
}
const fromPubkey = new PublicKey(solanaAccount.address);
const toPubkey = new PublicKey("RECIPIENT_ADDRESS_HERE");
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey,
toPubkey,
lamports: Math.round(0.01 * LAMPORTS_PER_SOL),
})
);
try {
const { signature } = await sdk.solana.signAndSendTransaction(transaction);
console.log("Transaction signature:", signature);
console.log(
`View on Explorer: https://explorer.solana.com/tx/${signature}?cluster=devnet`
);
} catch (error) {
console.error("Transaction failed:", error);
}
}
async function verifyTransaction(signature: string) {
const connection = new Connection("https://api.devnet.solana.com");
const status = await connection.getSignatureStatus(signature);
if (status.value?.confirmationStatus === "confirmed" ||
status.value?.confirmationStatus === "finalized") {
console.log("Transaction confirmed!");
} else {
console.log("Transaction status:", status.value);
}
}
signAndSendTransaction — NOT signTransaction. Embedded wallets do not support signTransaction.LAMPORTS_PER_SOL for SOL-to-lamport conversion.https://api.devnet.solana.com) for testing, mainnet-beta (https://api.mainnet-beta.solana.com) for production.Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.
CLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.
CLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).