This guide demonstrates how to integrate Para with Solana in your Flutter applications. Para acts as a secure signer for your Solana transactions, while the Solana Dart package handles the blockchain interactions.Para’s approach to Solana transaction signing is designed for flexibility and security:
Para signs the raw transaction bytes without modifying the transaction data
Your application maintains full control over transaction construction
Your private keys remain secure in Para’s wallet infrastructure
The Para SDK provides a Solana signer that works with the Solana Dart package. First, let’s create the necessary components:
Copy
Ask AI
import 'package:para/para.dart';import 'package:solana/solana.dart' as web3;// Initialize Para and get wallet (assuming user is already authenticated)final para = Para( environment: Environment.beta, apiKey: 'YOUR_API_KEY',);// Set up Solana client with the desired networkfinal devnetRpcUrl = Uri.parse('https://api.devnet.solana.com');final devnetWsUrl = Uri.parse('wss://api.devnet.solana.com');final solanaClient = web3.SolanaClient( rpcUrl: devnetRpcUrl, websocketUrl: devnetWsUrl,);// Initialize Para Solana signerfinal solanaSigner = ParaSolanaWeb3Signer( para: para, solanaClient: solanaClient,);
After signing a transaction, you can send it to the Solana network:
Copy
Ask AI
Future<String> sendSolanaTransaction( Wallet wallet, String recipientAddress, double amountInSol,) async { // Convert wallet address to Solana public key final publicKey = web3.Ed25519HDPublicKey.fromBase58(wallet.address!); // Convert recipient address to Solana public key final recipient = web3.Ed25519HDPublicKey.fromBase58(recipientAddress); // Get the latest blockhash (required for Solana transactions) final blockhash = (await solanaClient.rpcClient.getLatestBlockhash()).value; // Convert SOL amount to lamports (Solana's smallest unit) final lamports = (web3.lamportsPerSol * amountInSol).toInt(); // Create a transfer instruction final instruction = web3.SystemInstruction.transfer( fundingAccount: publicKey, recipientAccount: recipient, lamports: lamports, ); // Create and compile the message final message = web3.Message(instructions: [instruction]); final compiledMessage = message.compile( recentBlockhash: blockhash.blockhash, feePayer: publicKey, ); // Sign the transaction using Para final signedTransaction = await solanaSigner.signTransaction(compiledMessage); // Send the signed transaction to the network final signature = await solanaSigner.sendTransaction(signedTransaction); return signature;}