You should use particle-auth/particle-connect to send transaction, both of them have a function called signAndSendTransaction , a parameter called feeMode is used with AA service.
feeMode support native, gasless and token, just as its name implies, it tells how to pay gas fee.
SignAndSendTransaction with Connect Service
Show how to send transaction with particle-connect, use native token to pay gas fee.
staticvoidsignAndSendTransactionWithNative() async {if (account ==null) {print("not connect");return; }if (smartAccountAddress ==null) {print("not get smartAccountAddress");return; }try {final transaction =awaitTransactionMock.mockEvmSendNative(smartAccountAddress!);// check if enough native for gas feevar result =awaitParticleAA.rpcGetFeeQuotes( account!.publicAddress, [transaction]);var verifyingPaymasterNative = result["verifyingPaymasterNative"];var feeQuote = verifyingPaymasterNative["feeQuote"];var fee =BigInt.parse(feeQuote["fee"], radix:10);var balance =BigInt.parse(feeQuote["balance"], radix:10);if (balance < fee) {print("native balance if not enough for gas fee");return; }// pass result from rpcGetFeeQuotes to send pay with nativefinal signature =awaitParticleConnect.signAndSendTransaction(WalletType.metaMask, account!.publicAddress, transaction, feeMode:AAFeeMode.native(result));print("signature $signature"); } catch (error) {print("signAndSendTransactionWithNative: $error"); }}
Show how to send transaction with particle-connect, gasless.
staticvoidsignAndSendTransactionWithGasless() async {if (account ==null) {print("not connect");return; }if (smartAccountAddress ==null) {print("not get smartAccountAddress");return; }try {final transaction =awaitTransactionMock.mockEvmSendNative(smartAccountAddress!);// check if gasless availablevar result =awaitParticleAA.rpcGetFeeQuotes( account!.publicAddress, [transaction]);var verifyingPaymasterGasless = result["verifyingPaymasterGasless"];if (verifyingPaymasterGasless ==null) {print("gasless is not available");return; }// pass result from rpcGetFeeQuotes to send gaslessfinal signature =awaitParticleConnect.signAndSendTransaction(WalletType.metaMask, account!.publicAddress, transaction, feeMode:AAFeeMode.gasless(result));print("signature $signature");showToast("signature $signature"); } catch (error) {print("signAndSendTransactionWithGasless: $error");showToast("signAndSendTransactionWithGasless: $error"); }}
Show how to send transaction with particle-connect, use token to pay gas fee.