Skip to content

Commit 94c62d2

Browse files
committed
fix: refactored sendTx to solve edgecase when using smart accounts erc20 paymaster txs
1 parent b34d9d8 commit 94c62d2

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

src/libs/web3-data-provider/Web3Provider.tsx

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,51 @@ export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ chil
9696
if (provider) {
9797
const { from, ...data } = txData;
9898
const signer = provider.getSigner(from);
99-
const txResponse: TransactionResponse = await signer.sendTransaction({
100-
...data,
101-
value: data.value ? BigNumber.from(data.value) : undefined,
102-
});
103-
return txResponse;
99+
100+
try {
101+
const txResponse: TransactionResponse = await signer.sendTransaction({
102+
...data,
103+
value: data.value ? BigNumber.from(data.value) : undefined,
104+
});
105+
106+
return txResponse;
107+
} catch (error) {
108+
// Ethers.js incompatibility with Smart Account ERC-20 paymasters
109+
// Transaction may succeed on-chain but fail to return proper response
110+
if (error.transactionHash) {
111+
const hash = error.transactionHash;
112+
113+
try {
114+
const receipt = await provider.getTransactionReceipt(hash);
115+
if (receipt) {
116+
const confirmedReceipt = await provider.waitForTransaction(hash, 2);
117+
return {
118+
hash: hash,
119+
nonce: confirmedReceipt.transactionIndex,
120+
gasLimit: confirmedReceipt.gasUsed,
121+
gasPrice: confirmedReceipt.effectiveGasPrice,
122+
data: data.data || '0x',
123+
value: data.value ? BigNumber.from(data.value) : BigNumber.from(0),
124+
chainId: chainId,
125+
confirmations: confirmedReceipt.confirmations,
126+
from: confirmedReceipt.from,
127+
blockNumber: confirmedReceipt.blockNumber,
128+
blockHash: confirmedReceipt.blockHash,
129+
wait: async (confirmations?: number) => {
130+
if (!confirmations || confirmations <= 1) {
131+
return receipt;
132+
}
133+
return await provider.waitForTransaction(hash, confirmations);
134+
},
135+
} as TransactionResponse;
136+
}
137+
throw new Error(`Transaction not found: ${hash}`);
138+
} catch (receiptError) {
139+
throw new Error(`Could not verify transaction: ${hash}`);
140+
}
141+
}
142+
throw new Error(error.message || 'Transaction failed');
143+
}
104144
}
105145
throw new Error('Error sending transaction. Provider not found');
106146
};

0 commit comments

Comments
 (0)