Skip to main content
For interacting the SVM blockchain, you must have our dynamic_sdk_solana package installed. so in your pubspec.yaml file add that package as a dependency. Here is an example on how you can interact with the SVM by signing the message or sending the transaction:
Future<void> _signSolanaMessage(String message) async {
    if (_wallet == null) {
      print('Please connect a wallet first.');
      return;
    }
    
    try {
      final signer = _sdk.solana.createSigner(wallet: _wallet!);
      final signature = await signer.signMessage(message: message);
      print('Message signed with signature: $signature');
    } catch (e) {
      print('An error occurred while signing the message: $e');
    }
  }

  Future<void> _sendSolanaTransaction(String recipientAddress, double amount) async {
    if (_wallet == null) {
      print('Please connect a wallet first.');
      return;
    }

    try {
      final signer = _sdk.solana.createSigner(wallet: _wallet!);
      final connection = _sdk.solana.createConnection();

      final fromPubKey = Pubkey.fromString(_wallet!.address);
      final toPubKey = Pubkey.fromString(recipientAddress);

      final BlockhashWithExpiryBlockHeight recentBlockhash =
          await connection.getLatestBlockhash();

      final transaction = Transaction.v0(
        payer: fromPubKey,
        recentBlockhash: recentBlockhash.blockhash,
        instructions: [
          SystemProgram.transfer(
            fromPubkey: fromPubKey,
            toPubkey: toPubKey,
            lamports: solToLamports(amount),
          ),
        ],
      );

      final signature = await signer.signAndSendTransaction(transaction: transaction);
      print('Transaction sent with signature: $signature');
    } catch (e) {
      print('An error occurred while sending the transaction: $e');
    }
  }```