[BUG] fix: refactored sendTx to solve edgecase when using smart accounts erc20 paymaster txs #2760
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
General Changes
Developer Notes
BUG DESCRIPTION
The incompatibility only arises when performing an action that requires
sendTxusing an EOA with an associated smart account in MetaMask and paying the fees using an ERC-20 Paymaster. In other words, the native token is not used to pay for the transaction.In this scenario, the transaction succeeds on-chain, but the UI fails, causing confusion for the user. The balances are correctly updated, and if the user checks the transaction hash in MetaMask’s activity tab, they will see that the transaction was indeed executed successfully.
CAUSE
The root cause is that ethers, in its
sendTransactionfunction, does not account for the different flow that occurs when executing a smart account transaction using an ERC-20 Paymaster.The flow works as follows:
The user submits the transaction using ethers’
sendTransaction. This transaction is intercepted by the smart account, which creates a UserOp with the corresponding values and sends it to the bundler. The bundler is the component that actually sends the transaction to the blockchain and produces a valid transaction hash.Ethers internally fails to recognize this alternative flow—either due to unhandled logic or internal timeouts—which leads it to throw an error even though the transaction was correctly sent to the bundler and the blockchain.
SOLUTION
We created a custom path to analyze the error emitted by ethers. If the error contains a valid transaction hash, it means that a smart account transaction with an ERC-20 Paymaster was executed. In that case, we extract the hash, fetch the corresponding receipt, and return it to the UI. This resolves the edge case.
If no valid hash exists in the error, we simply return the original error as usual.
Reviewer Checklist
Please ensure you, as the reviewer(s), have gone through this checklist to ensure that the code changes are ready to ship safely and to help mitigate any downstream issues that may occur.
.env.examplefile as well as the pertinant.github/actions/*files