signAndSendTransaction method

  1. @override
Future<CrossmintCheckoutTransactionResult> signAndSendTransaction(
  1. String serializedTransaction
)
override

Signs and broadcasts a raw serialized EVM transaction received from the hosted checkout via the backing CrossmintEvmWallet. Returns CrossmintCheckoutTransactionSuccess with the transaction id on success. Errors are caught and surfaced as CrossmintCheckoutTransactionFailure — this method never throws so the hosted checkout can render a user-facing message.

Implementation

@override
Future<CrossmintCheckoutTransactionResult> signAndSendTransaction(
  String serializedTransaction,
) async {
  try {
    final transaction = await _wallet.sendTransaction(
      CrossmintEvmTransactionRequest.serialized(
        serializedTransaction: serializedTransaction,
        chain: _selectedChain,
      ),
    );
    final String txId = _transactionIdFromRaw(
      transaction.raw,
      fallback: transaction.id,
    );
    if (txId.isEmpty) {
      return const CrossmintCheckoutTransactionFailure(
        errorMessage: 'Transaction completed without a transaction id.',
      );
    }
    return CrossmintCheckoutTransactionSuccess(txId: txId);
  } catch (error) {
    return CrossmintCheckoutTransactionFailure(
      errorMessage: error.toString(),
    );
  }
}