> ## 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.

# Interact with Solana Programs

> Call program instructions and work with Anchor IDLs using Para

Interact with Solana programs by calling instructions and working with Anchor IDLs. This guide covers manual instruction creation and Anchor's type-safe program interaction.

<Card title="Setup Solana Libraries First" description="Configure Solana libraries with Para SDK before using these operations" href="/v3/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,
      createTransactionMessage,
      setTransactionMessageFeePayer,
      setTransactionMessageLifetimeUsingBlockhash,
      appendTransactionMessageInstruction,
      pipe,
    } from '@solana/kit';
    import { getTransferSolInstruction } from '@solana-program/system';

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

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

      const callProgram = async () => {
        if (!solanaSigner) {
          console.error("No signer available. Connect wallet first.");
          return;
        }

        const programId = "YOUR_PROGRAM_ID" as Address;

        // Create instruction data (program-specific)
        const instructionData = new Uint8Array(9);
        instructionData[0] = 0; // Instruction index
        const view = new DataView(instructionData.buffer);
        view.setBigUint64(1, BigInt(1000), true); // Example parameter

        const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();

        const transactionMessage = pipe(
          createTransactionMessage({ version: 0 }),
          (tx) => setTransactionMessageFeePayer(solanaSigner.address, tx),
          (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
          (tx) => appendTransactionMessageInstruction(
            {
              programAddress: programId,
              accounts: [
                { address: solanaSigner.address, role: 3 /* WritableSigner */ },
              ],
              data: instructionData,
            },
            tx
          )
        );

        const signature = await signAndSendAsync({ transactionMessage });
        console.log("Program call signature:", signature);
      };

      return <button onClick={callProgram}>Call Program</button>;
    }
    ```
  </Tab>

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

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

      const callProgram = async () => {
        const programId = new PublicKey("YOUR_PROGRAM_ID");

        // Example: Initialize account with custom data
        const [pda] = PublicKey.findProgramAddressSync(
          [Buffer.from("seed"), signer.sender.toBuffer()],
          programId
        );

        // Create instruction data (program-specific)
        const instructionData = Buffer.alloc(9);
        instructionData.writeUInt8(0, 0); // Instruction index
        instructionData.writeBigUInt64LE(BigInt(1000), 1); // Example parameter

        const instruction = new TransactionInstruction({
          keys: [
            { pubkey: signer.sender, isSigner: true, isWritable: true },
            { pubkey: pda, isSigner: false, isWritable: true },
            { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
          ],
          programId,
          data: instructionData,
        });

        const transaction = new Transaction().add(instruction);

        try {
          const signature = await signer.sendTransaction(transaction);
          console.log("Program call signature:", signature);

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

      return <button onClick={callProgram}>Call Program</button>;
    }
    ```
  </Tab>

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

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

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

        // Generate keypair for new account
        const newAccount = anchor.web3.Keypair.generate();

        try {
          // Example: Initialize an account
          const tx = await program.methods
            .initialize(new anchor.BN(1000))
            .accountsPartial({
              user: provider.wallet.publicKey,
              dataAccount: newAccount.publicKey,
              systemProgram: SystemProgram.programId,
            })
            .signers([newAccount])
            .rpc();

          console.log("Transaction signature:", tx);

          // Fetch account data
          const account = await program.account.dataAccount.fetch(newAccount.publicKey);
          console.log("Account data:", account);

          // Example: Update the account
          const updateTx = await program.methods
            .update(new anchor.BN(2000))
            .accountsPartial({
              user: provider.wallet.publicKey,
              dataAccount: newAccount.publicKey,
            })
            .rpc();

          console.log("Update transaction:", updateTx);
        } catch (error) {
          console.error("Anchor program call failed:", error);
        }
      };

      return <button onClick={callAnchorProgram}>Call Anchor Program</button>;
    }
    ```
  </Tab>
</Tabs>

## Next Steps

<CardGroup cols={3}>
  <Card title="Compute Units" description="Optimize transaction compute units" href="/v3/react-native/guides/web3-operations/solana/compute-units" icon="calculator" />

  <Card title="Execute Transactions" description="Build complex transactions" href="/v3/react-native/guides/web3-operations/solana/execute-transactions" icon="bolt" />

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