> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getpara.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set Compute Units and Priority Fees

> Configure compute budget and priority fees for Solana transactions

export const Card = ({imgUrl, title, description, href, horizontal = false, newTab = false}) => {
  const [isHovered, setIsHovered] = useState(false);
  const handleClick = e => {
    e.preventDefault();
    if (newTab) {
      window.open(href, '_blank', 'noopener,noreferrer');
    } else {
      window.location.href = href;
    }
  };
  return <div className={`not-prose relative my-2 p-[1px] rounded-xl transition-all duration-300 ${isHovered ? 'bg-gradient-to-r from-[#FF4E00] to-[#874AE3]' : 'bg-gray-200'}`} onMouseEnter={() => setIsHovered(true)} onMouseLeave={() => setIsHovered(false)}>
      <a href={href} onClick={handleClick} className={`not-prose flex ${horizontal ? 'flex-row' : 'flex-col'} font-normal h-full bg-white overflow-hidden w-full cursor-pointer rounded-[11px] no-underline`}>
        {imgUrl && <div className={`relative overflow-hidden flex-shrink-0 ${horizontal ? 'w-[30%] rounded-l-[11px]' : 'w-full'}`} onClick={e => e.stopPropagation()}>
            <img src={imgUrl} alt={title} className="w-full h-full object-cover pointer-events-none select-none" draggable="false" />
            <div className="absolute inset-0 pointer-events-none" />
          </div>}
        <div className={`flex-grow px-6 py-5 ${horizontal ? 'w-[70%]' : 'w-full'} flex flex-col ${horizontal && imgUrl ? 'justify-center' : 'justify-start'}`}>
          {title && <h2 className="font-semibold text-base text-gray-800 m-0">{title}</h2>}
          {description && <div className={`font-normal text-gray-500 re leading-6 ${horizontal || !imgUrl ? 'mt-0' : 'mt-1'}`}>
              <p className="m-0 text-xs">{description}</p>
            </div>}
        </div>
      </a>
    </div>;
};

Optimize your Solana transactions by setting compute unit limits and priority fees. This helps ensure transactions succeed during network congestion and controls execution costs.

<Card title="Setup Solana Libraries First" description="Configure Solana libraries with Para SDK before using these operations" href="/v2/react-native/guides/web3-operations/solana/setup-libraries" horizontal />

<Tabs>
  <Tab title="@solana/kit">
    ```typescript theme={null}
    import { useParaSolanaSigner, useParaSolanaSignAndSend } from "@getpara/react-native-wallet/solana";
    import { Address } from '@solana/addresses';
    import {
      createSolanaRpc,
      pipe,
      createTransactionMessage,
      setTransactionMessageFeePayer,
      setTransactionMessageLifetimeUsingBlockhash,
      appendTransactionMessageInstruction,
      lamports,
    } from '@solana/kit';
    import { getTransferSolInstruction } from '@solana-program/system';
    import {
      getSetComputeUnitLimitInstruction,
      getSetComputeUnitPriceInstruction,
    } from '@solana-program/compute-budget';

    const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");

    function ComputeUnitsExample() {
      const { solanaSigner, isLoading } = useParaSolanaSigner({ rpc });
      const { signAndSendAsync, isPending } = useParaSolanaSignAndSend(solanaSigner);

      const sendWithPriorityFee = async () => {
        if (!solanaSigner) return;

        const recipient = "RECIPIENT_ADDRESS" as Address;
        const response = await rpc.getLatestBlockhash().send();
        const { blockhash, lastValidBlockHeight } = response.value;

        const { value: recentFees } = await rpc.getRecentPrioritizationFees().send();
        const avgFee = recentFees.reduce((sum, fee) => sum + fee.prioritizationFee, 0n) / BigInt(recentFees.length);
        const priorityFee = (avgFee * 120n) / 100n;

        const transactionMessage = pipe(
          createTransactionMessage({ version: "legacy" }),
          tx => setTransactionMessageFeePayer(solanaSigner.address, tx),
          tx => setTransactionMessageLifetimeUsingBlockhash({ blockhash, lastValidBlockHeight }, tx),
          tx => appendTransactionMessageInstruction(getSetComputeUnitLimitInstruction({ units: 200000 }), tx),
          tx => appendTransactionMessageInstruction(getSetComputeUnitPriceInstruction({ microLamports: priorityFee }), tx),
          tx => appendTransactionMessageInstruction(
            getTransferSolInstruction({
              source: solanaSigner,
              destination: recipient,
              amount: lamports(100_000_000n),
            }),
            tx
          )
        );

        const txSignature = await signAndSendAsync({ transactionMessage });
        console.log("Transaction sent with priority fee:", txSignature);

        return txSignature;
      };

      return <button onClick={sendWithPriorityFee}>Send with Priority Fee</button>;
    }
    ```
  </Tab>

  <Tab title="@solana/web3.js">
    ```typescript theme={null}
    import { useParaSolana } from './hooks/useParaSolana';
    import {
      Transaction,
      SystemProgram,
      LAMPORTS_PER_SOL,
      PublicKey,
      ComputeBudgetProgram
    } from '@solana/web3.js';

    function ComputeUnitsExample() {
      const { connection, signer } = useParaSolana();

      const sendWithPriorityFee = async () => {
        const recipient = new PublicKey("RECIPIENT_ADDRESS");

        // Get recent prioritization fees
        const recentFees = await connection.getRecentPrioritizationFees();
        const avgFee = recentFees.reduce((sum, fee) => sum + fee.prioritizationFee, 0) / recentFees.length;
        const priorityFee = Math.ceil(avgFee * 1.2); // 20% above average

        const transaction = new Transaction()
          .add(
            // Set compute unit limit
            ComputeBudgetProgram.setComputeUnitLimit({
              units: 200000, // Adjust based on your transaction needs
            })
          )
          .add(
            // Set priority fee
            ComputeBudgetProgram.setComputeUnitPrice({
              microLamports: priorityFee,
            })
          )
          .add(
            // Your actual transaction instruction
            SystemProgram.transfer({
              fromPubkey: signer.sender,
              toPubkey: recipient,
              lamports: LAMPORTS_PER_SOL * 0.1,
            })
          );

        try {
          const signature = await signer.sendTransaction(transaction, {
            skipPreflight: false,
            maxRetries: 3,
          });

          console.log("Transaction sent with priority fee:", signature);
          console.log("Priority fee used:", priorityFee, "microLamports");

          const confirmation = await connection.confirmTransaction(signature, "confirmed");
          console.log("Transaction confirmed:", confirmation);
        } catch (error) {
          console.error("Transaction failed:", error);
        }
      };

      return <button onClick={sendWithPriorityFee}>Send with Priority Fee</button>;
    }
    ```
  </Tab>

  <Tab title="Anchor">
    ```typescript theme={null}
    import { useParaAnchor } from './hooks/useParaAnchor';
    import {
      Transaction,
      SystemProgram,
      LAMPORTS_PER_SOL,
      PublicKey,
      ComputeBudgetProgram
    } from '@solana/web3.js';
    import * as anchor from '@coral-xyz/anchor';

    function ComputeUnitsExample() {
      const provider = useParaAnchor();

      const sendWithPriorityFee = async () => {
        anchor.setProvider(provider);
        const program = new anchor.Program(idl, provider);

        // Get recent prioritization fees
        const recentFees = await provider.connection.getRecentPrioritizationFees();
        const avgFee = recentFees.reduce((sum, fee) => sum + fee.prioritizationFee, 0) / recentFees.length;
        const priorityFee = Math.ceil(avgFee * 1.2);

        // Create the main instruction
        const ix = await program.methods
          .someMethod()
          .accounts({
            user: provider.publicKey,
            // ... other accounts
          })
          .instruction();

        // Build transaction with compute budget instructions
        const transaction = new Transaction()
          .add(
            ComputeBudgetProgram.setComputeUnitLimit({
              units: 300000, // Higher for complex program calls
            })
          )
          .add(
            ComputeBudgetProgram.setComputeUnitPrice({
              microLamports: priorityFee,
            })
          )
          .add(ix);

        try {
          const signature = await provider.sendAndConfirm(transaction);
          console.log("Transaction sent with priority fee:", signature);
          console.log("Priority fee used:", priorityFee, "microLamports");
        } catch (error) {
          console.error("Transaction failed:", error);
        }
      };

      return <button onClick={sendWithPriorityFee}>Execute with Priority</button>;
    }
    ```
  </Tab>
</Tabs>

## Next Steps

<CardGroup cols={3}>
  <Card title="Execute Transactions" description="Build and send transactions" href="/v2/react-native/guides/web3-operations/solana/execute-transactions" icon="bolt" />

  <Card title="Get Transaction Status" description="Monitor transaction confirmations" href="/v2/react-native/guides/web3-operations/solana/get-transaction-status" icon="clock" />

  <Card title="Configure RPC" description="Set up custom RPC endpoints" href="/v2/react-native/guides/web3-operations/solana/configure-rpc" icon="server" />
</CardGroup>
