Examples
Send a Transaction

Send a Transaction

Send SOL from the connected wallet to another address.

Code

SendSOL.tsx
import { useWallet, useConnection, useSendTransaction } from '@wankmi/wankmi'
import {
  Transaction,
  SystemProgram,
  PublicKey,
  LAMPORTS_PER_SOL,
} from '@solana/web3.js'
 
export function SendSOL() {
  const { publicKey } = useWallet()
  const { connection } = useConnection()
  const { sendTransaction, isPending, isSuccess, isError, data: signature } =
    useSendTransaction()
 
  async function handleSend() {
    if (!publicKey) return
 
    const recipient = new PublicKey('RecipientAddressHere...')
    const { blockhash } = await connection.getLatestBlockhash()
 
    const tx = new Transaction().add(
      SystemProgram.transfer({
        fromPubkey: publicKey,
        toPubkey: recipient,
        lamports: 0.01 * LAMPORTS_PER_SOL,
      })
    )
    tx.recentBlockhash = blockhash
    tx.feePayer = publicKey
 
    sendTransaction(tx)
  }
 
  return (
    <div>
      <button onClick={handleSend} disabled={isPending || !publicKey}>
        {isPending ? 'Sending...' : 'Send 0.01 SOL'}
      </button>
 
      {isSuccess && (
        <p>
          ✅ Sent!{' '}
          <a
            href={`https://explorer.solana.com/tx/${signature}?cluster=devnet`}
            target="_blank"
            rel="noreferrer"
          >
            View on Explorer
          </a>
        </p>
      )}
 
      {isError && <p>❌ Transaction failed. Please try again.</p>}
    </div>
  )
}
⚠️

Always fetch a fresh blockhash immediately before building the transaction. Blockhashes expire after ~60 seconds (~150 slots).

How it works

  1. Fetch the latest blockhash from the RPC.
  2. Build a Transaction with a SystemProgram.transfer instruction.
  3. Set recentBlockhash and feePayer on the transaction.
  4. Pass the transaction to sendTransaction — wankmi handles signing via the wallet adapter and submitting to the network.
  5. On success, the data field contains the transaction signature, which you can link to Solana Explorer.