Solana Integration Guide

Technical guide for integrating with BlockReel's Solana-based features including payments and governance.

Solana Integration Guide

Technical documentation for integrating with BlockReel's Solana-based features.

Overview

BlockReel uses Solana for:

Wallet Integration

Supported Wallets

Connection Flow

```typescript import { useWallet } from '@solana/wallet-adapter-react';

const { publicKey, signTransaction, connect } = useWallet();

// Connect wallet await connect();

// Check connection if (publicKey) { console.log('Connected:', publicKey.toBase58()); } ```

Payment Processing

Creating a Payment

```typescript import { Connection, Transaction, SystemProgram } from '@solana/web3.js';

// Create transaction const transaction = new Transaction().add( SystemProgram.transfer({ fromPubkey: senderPublicKey, toPubkey: recipientPublicKey, lamports: amountInLamports, }) );

// Sign and send const signature = await sendTransaction(transaction, connection);

// Confirm await connection.confirmTransaction(signature); ```

SPL Token Transfers

```typescript import { createTransferInstruction, getAssociatedTokenAddress } from '@solana/spl-token';

// Get token accounts const senderATA = await getAssociatedTokenAddress(tokenMint, senderPublicKey); const recipientATA = await getAssociatedTokenAddress(tokenMint, recipientPublicKey);

// Create transfer instruction const transferInstruction = createTransferInstruction( senderATA, recipientATA, senderPublicKey, amount * (10 ** decimals) );

// Add to transaction and send ```

Governance Integration

Voting Power Calculation

```typescript function calculateVotingPower( tokenBalance: number, isVerifiedFilmmaker: boolean, hasFounderNFT: boolean ): number { let power = Math.sqrt(tokenBalance);

if (isVerifiedFilmmaker) power *= 1.5; if (hasFounderNFT) power *= 1.2;

return power; } ```

Casting Votes

```typescript // Vote data structure interface Vote { proposalId: string; choice: 'for' | 'against' | 'abstain'; votingPower: number; walletAddress: string; signature: string; }

// Submit vote (signed message) const message = Vote ${choice} on proposal ${proposalId}; const signature = await signMessage(message); ```

RPC Configuration

Endpoints

We recommend using our proxy endpoint for stability:

```typescript const RPC_ENDPOINT = 'https://[project].supabase.co/functions/v1/solana-rpc-proxy';

// Alternative public endpoints const MAINNET = 'https://api.mainnet-beta.solana.com'; const DEVNET = 'https://api.devnet.solana.com'; ```

Rate Limiting

Error Handling

Common Errors

``typescript try { await sendTransaction(transaction, connection); } catch (error) { if (error.message.includes('insufficient funds')) { // Handle insufficient balance } else if (error.message.includes('blockhash not found')) { // Retry with fresh blockhash } else if (error.message.includes('user rejected')) { // User cancelled in wallet } } ``

Testing

Devnet Testing

1. Switch to devnet in wallet settings 2. Get test SOL from faucet 3. Test all flows before mainnet

Faucet

``bash solana airdrop 2 YOUR_WALLET_ADDRESS --url devnet ``

Security Best Practices

1. Never expose private keys 2. Verify all transactions client-side 3. Use recent blockhashes 4. Implement retry logic 5. Validate all inputs 6. Use priority fees during congestion

Useful Resources

---

Developer support: