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

# Solana Program Interaction

Interact with Solana programs using the embedded wallet and the Solana web3.js library.

## Implementation

```tsx theme={null}
import { useSendTransaction, useWallet } from '@moon-key/react-auth/solana';
import { 
  Connection, 
  Transaction, 
  PublicKey,
  SystemProgram,
  LAMPORTS_PER_SOL 
} from '@solana/web3.js';

export default function SolanaProgram() {
  const { sendTransaction } = useSendTransaction();
  const { wallet } = useWallet();
  const connection = new Connection('https://api.mainnet-beta.solana.com');

  const handleProgramInteraction = async () => {
    if (!wallet) return;

    try {
      // Example: Create an account
      const newAccount = PublicKey.unique();
      
      const transaction = new Transaction().add(
        SystemProgram.createAccount({
          fromPubkey: wallet.publicKey,
          newAccountPubkey: newAccount,
          lamports: 0.001 * LAMPORTS_PER_SOL,
          space: 0,
          programId: SystemProgram.programId
        })
      );

      const signature = await sendTransaction({
        transaction,
        connection
      });

      console.log('Program interaction successful:', signature);
    } catch (error) {
      console.error('Program interaction failed:', error);
    }
  };

  return (
    <div>
      <h2>Solana Program Interaction</h2>
      <button onClick={handleProgramInteraction}>
        Interact with Program
      </button>
    </div>
  );
}
```

## Key concepts

* **Connection** - Connects to Solana RPC endpoint
* **Transaction** - Builds transaction with instructions
* **Program interaction** - Calls Solana program instructions
* **Wallet integration** - Uses embedded wallet's public key

## Common patterns

### SPL Token Transfer

```tsx theme={null}
import { getAssociatedTokenAddress, createTransferInstruction } from '@solana/spl-token';

const handleTokenTransfer = async () => {
  const tokenMint = new PublicKey('YOUR_TOKEN_MINT');
  const recipient = new PublicKey('RECIPIENT_ADDRESS');
  
  const senderAta = await getAssociatedTokenAddress(tokenMint, wallet.publicKey);
  const recipientAta = await getAssociatedTokenAddress(tokenMint, recipient);
  
  const transaction = new Transaction().add(
    createTransferInstruction(
      senderAta,
      recipientAta,
      wallet.publicKey,
      100 * Math.pow(10, 6) // Amount with decimals
    )
  );
  
  await sendTransaction({ transaction, connection });
};
```

### Custom Program Instruction

```tsx theme={null}
import { TransactionInstruction } from '@solana/web3.js';

const handleCustomInstruction = async () => {
  const programId = new PublicKey('YOUR_PROGRAM_ID');
  
  const instruction = new TransactionInstruction({
    keys: [
      { pubkey: wallet.publicKey, isSigner: true, isWritable: true },
      // Add other account keys as needed
    ],
    programId,
    data: Buffer.from([/* instruction data */])
  });
  
  const transaction = new Transaction().add(instruction);
  await sendTransaction({ transaction, connection });
};
```

## Important notes

<Info>
  Make sure you're using the correct RPC endpoint for your environment (mainnet, devnet, or testnet).
</Info>

<Warning>
  Always verify that the wallet has sufficient SOL to pay for transaction fees and any required lamports for the operation.
</Warning>

## Next steps

<CardGroup cols={2}>
  <Card title="Send Transaction" icon="paper-plane" href="/wallet-as-a-service/using-wallets/solana/send-transaction">
    Learn more about Solana transactions
  </Card>

  <Card title="Web3.js Integration" icon="code" href="/wallet-as-a-service/using-wallets/solana/solana-web3-js">
    Deep dive into Solana web3.js
  </Card>
</CardGroup>
