@@ -117,10 +117,21 @@ export class TransactionService {
117117
118118 console . log ( `Estimated transaction fee: ${ feeEstimate . estimatedFeeInPOL } POL` ) ;
119119
120- // Ensure wallet has sufficient balance for fees
120+ // Determine the actual gas limit that will be used
121+ const actualGasLimit = request . gasLimit || feeEstimate . gasLimit ;
122+
123+ // If a custom gas limit is provided, recalculate the fee using the actual gas limit
124+ let actualTotalFee = feeEstimate . totalFee ;
125+ if ( request . gasLimit && request . gasLimit !== feeEstimate . gasLimit ) {
126+ // Recalculate fee with the actual gas limit that will be used
127+ actualTotalFee = actualGasLimit * feeEstimate . gasPrice ;
128+ console . log ( `Custom gas limit provided. Recalculated fee: ${ ethers . formatEther ( actualTotalFee ) } POL (Gas: ${ actualGasLimit . toString ( ) } , Price: ${ ethers . formatUnits ( feeEstimate . gasPrice , 'gwei' ) } gwei)` ) ;
129+ }
130+
131+ // Ensure wallet has sufficient balance for fees using the actual fee
121132 const refillResult = await this . feeRefillerService . ensureSufficientBalance (
122133 request . from ,
123- feeEstimate . totalFee
134+ actualTotalFee
124135 ) ;
125136
126137 if ( ! refillResult . success ) {
@@ -132,7 +143,7 @@ export class TransactionService {
132143 to : request . to as `0x${string } `,
133144 data : request . data as `0x${string } `,
134145 value : request . value ? ethers . parseEther ( request . value ) : 0n ,
135- gasLimit : request . gasLimit || feeEstimate . gasLimit , // Use custom gas limit if provided
146+ gasLimit : actualGasLimit ,
136147 gasPrice : feeEstimate . gasPrice ,
137148 nonce : nonce // Explicit nonce to prevent conflicts
138149 } ;
0 commit comments