web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Retrying an EIP 1559 transaction

Open EthanNusuiev opened this issue 11 months ago • 2 comments

After sending a transaction and getting error (that expected behavior for some transactions): 'Transaction was not mined within 100 seconds. Please make sure your transaction was properly sent and there are no previous pending transaction for the same account. However, be aware that it might still be mined `

then Im trying to retrying the transaction with bigger maxPriorityFeePerGas and maxFeePerGas but still cant and getting this error: `'Returned error: replacement transaction underpriced' even if Im increase by 100%

async increaseTimeoutTransaction( payload: ValidateTimeoutTransactionDtoByAssetDto, previousTransaction: GetTransactionResponse, requestId: string ): Promise<TransactionReceiptDto> { const { increaseGasRate } = payload; const { gas, maxPriorityFeePerGas, nonce } = previousTransaction; const transferFromMethodABI = await this.getTransferFromAbiMethod(payload, requestId); let newMaxPriorityFeePerGas = new Decimal(maxPriorityFeePerGas).multiply(increaseGasRate).toString(); newMaxPriorityFeePerGas = Utils.truncate(newMaxPriorityFeePerGas, 0).toString(); const currentBaseFee = await this.infuraApiService.getBaseFee(payload.blockchain, requestId); //Get the base fee from latest block const newMaxFeePerGas = new Decimal(currentBaseFee).plus(newMaxPriorityFeePerGas).toString(); const signTransactionDto: SignTransactionApiDto = { from: payload.spenderWalletAddress, to: payload.contractAddress, blockchain: payload.blockchain, data: transferFromMethodABI, nonce, gas, maxFeePerGas: newMaxFeePerGas, maxPriorityFeePerGas: newMaxPriorityFeePerGas, type: 2, // EIP-1559 transaction type }; return this.signAndSendTransaction(signTransactionDto, requestId); }

Versions used of: npm: v10.8.1, Node: v20.16.0, web3.js: 4.16.0 , OS: macOs sequoia 15.2, device: mac

EthanNusuiev avatar Jan 20 '25 12:01 EthanNusuiev

Make sure you correctly calculate the maxFeePerGas and maxPriorityFeePerGas based on real-time network conditions. Try using https://docs.web3js.org/guides/transactions/gas-and-fees#calculating-fees for calculating fee and adjust by increasing baseFeePerGasFactor param.

jdevcs avatar Jan 21 '25 11:01 jdevcs

Also you may be aware, we are in the process of sunsetting Web3.js, Our focus during this transition will be on addressing critical issues to ensure a smooth migration for our users. For further details regarding the sunsetting of Web3.js, please refer to the official announcement here: Web3.js Sunset Announcement

jdevcs avatar Jan 21 '25 11:01 jdevcs