diff --git a/CHANGELOG.md b/CHANGELOG.md index 21a45b6d806..94a802644cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2483,6 +2483,10 @@ If there are any bugs, improvements, optimizations or any new feature proposal f ### Fixed +#### web3-eth + +- Fixed issue with simple transactions, Within `checkRevertBeforeSending` if there is no data set in transaction, set gas to be `21000` (#7043) + #### web3-utils @@ -2498,6 +2502,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f #### web3-eth - Added parameter `customTransactionReceiptSchema` into methods `emitConfirmation`, `waitForTransactionReceipt`, `watchTransactionByPolling`, `watchTransactionBySubscription`, `watchTransactionForConfirmations` (#7000) +- Changed functionality: For networks that returns `baseFeePerGas===0x0` fill `maxPriorityFeePerGas` and `maxFeePerGas` by `getGasPrice` method (#7050) #### web3-rpc-methods diff --git a/packages/web3-eth/CHANGELOG.md b/packages/web3-eth/CHANGELOG.md index 9d9b67b29ca..01294d0b449 100644 --- a/packages/web3-eth/CHANGELOG.md +++ b/packages/web3-eth/CHANGELOG.md @@ -242,7 +242,8 @@ Documentation: ### Changed - Added parameter `customTransactionReceiptSchema` into methods `emitConfirmation`, `waitForTransactionReceipt`, `watchTransactionByPolling`, `watchTransactionBySubscription`, `watchTransactionForConfirmations` (#7000) +- Changed functionality: For networks that returns `baseFeePerGas===0x0` fill `maxPriorityFeePerGas` and `maxFeePerGas` by `getGasPrice` method (#7050) ### Fixed -- Fixed issue with simple transactions, Within `checkRevertBeforeSending` if there is no data set in transaction, set gas to be `21000` (#7043) \ No newline at end of file +- Fixed issue with simple transactions, Within `checkRevertBeforeSending` if there is no data set in transaction, set gas to be `21000` (#7043) diff --git a/packages/web3-eth/src/utils/get_transaction_gas_pricing.ts b/packages/web3-eth/src/utils/get_transaction_gas_pricing.ts index e5bbcdedfd4..95e0a3c411f 100644 --- a/packages/web3-eth/src/utils/get_transaction_gas_pricing.ts +++ b/packages/web3-eth/src/utils/get_transaction_gas_pricing.ts @@ -38,14 +38,17 @@ async function getEip1559GasPricing( web3Context: Web3Context, returnFormat: ReturnFormat, ): Promise> { - const block = await getBlock(web3Context, web3Context.defaultBlock, false, returnFormat); - + const block = await getBlock(web3Context, web3Context.defaultBlock, false, ETH_DATA_FORMAT); if (isNullish(block.baseFeePerGas)) throw new Eip1559NotSupportedError(); - if (!isNullish(transaction.gasPrice)) { + let gasPrice: Numbers | undefined; + if (isNullish(transaction.gasPrice) && BigInt(block.baseFeePerGas) === BigInt(0)) { + gasPrice = await getGasPrice(web3Context, returnFormat); + } + if (!isNullish(transaction.gasPrice) || !isNullish(gasPrice)) { const convertedTransactionGasPrice = format( { format: 'uint' }, - transaction.gasPrice as Numbers, + transaction.gasPrice ?? gasPrice, returnFormat, ); diff --git a/packages/web3-eth/test/unit/utils/get_transaction_gas_pricing.test.ts b/packages/web3-eth/test/unit/utils/get_transaction_gas_pricing.test.ts new file mode 100644 index 00000000000..30d3e5beaf9 --- /dev/null +++ b/packages/web3-eth/test/unit/utils/get_transaction_gas_pricing.test.ts @@ -0,0 +1,58 @@ +/* +This file is part of web3.js. + +web3.js is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +web3.js is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with web3.js. If not, see . +*/ +import { Web3Context } from 'web3-core'; + +import { FMT_BYTES, FMT_NUMBER } from 'web3-types'; +import * as RpcMethodWrappers from '../../../src/rpc_method_wrappers'; +import { getTransactionGasPricing } from '../../../src/utils/get_transaction_gas_pricing'; + +describe('getTransactionGasPricing', () => { + const web3Context = new Web3Context(); + + it('should use the call rpc wrapper', async () => { + const gasPrice = '0x123456'; + const gasPriceSpy = jest + .spyOn(RpcMethodWrappers, 'getGasPrice') + .mockImplementation(async () => gasPrice); + const getBlockSpy = jest + .spyOn(RpcMethodWrappers, 'getBlock') + // @ts-expect-error only for testing purposes + .mockImplementation(async () => ({ + baseFeePerGas: '0x0', + })); + + const transaction = { + from: '0x4fec0a51024b13030d26e70904b066c6d41157a5', + to: '0x36361143b7e2c676f8ccd67743a89d26437f0529', + data: '0x819f48fe', + type: '0x2', + }; + + const res = await getTransactionGasPricing(transaction, web3Context, { + number: FMT_NUMBER.HEX, + bytes: FMT_BYTES.HEX, + }); + + expect(getBlockSpy).toHaveBeenCalled(); + expect(gasPriceSpy).toHaveBeenCalled(); + expect(res).toEqual({ + gasPrice: undefined, + maxPriorityFeePerGas: gasPrice, + maxFeePerGas: gasPrice, + }); + }); +});