Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes maxPriorityFeePerGas in _handleTxPricing #5018

Closed
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,12 @@ Released with 1.0.0-beta.37 code base.
- Fix static tuple encoding (#4673) (#4884)
- Fix bug in handleRevert logic for eth_sendRawTransaction (#4902)
- Fix resolve type of getBlock function (#4911)
- Fix resolve issue with to low priority fee on polygon (#4857)

### Changed
- Replace deprecated String.prototype.substr() (#4855)
- Exporting AbiCoder as coder (#4937)
- `web3-core-method._handleTxPricing` uses now `eth_feeHistory` for priority fee calculation on EIP-1559 compatible chains (#5018)

### Added
- Exposing `web3.eth.Contract.setProvider()` as per public documentation (#4822) (#5001)
Expand Down
22 changes: 20 additions & 2 deletions packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,23 @@ function _handleTxPricing(method, tx) {
call: 'eth_gasPrice',
params: 0
})).createFunction(method.requestManager);
var getFeeHistory = new Method({
name: "getFeeHistory",
call: "eth_feeHistory",
params: 3,
inputFormatter: [
utils.numberToHex,
function (blockNumber) {
return blockNumber ? utils.toHex(blockNumber) : "latest";
},
null,
],
}).createFunction(method.requestManager);

Promise.all([
getBlockByNumber(),
getGasPrice()
]).then(responses => {
]).then(async responses => {
const [block, gasPrice] = responses;
if (
(tx.type === '0x2' || tx.type === undefined) &&
Expand All @@ -883,7 +895,13 @@ function _handleTxPricing(method, tx) {
maxFeePerGas = tx.gasPrice;
delete tx.gasPrice;
} else {
maxPriorityFeePerGas = tx.maxPriorityFeePerGas || '0x9502F900'; // 2.5 Gwei
const feeHistory = await getFeeHistory(1);
const [baseFee] = feeHistory.baseFeePerGas;
const priorityFee = utils.numberToHex(
utils.hexToNumber(gasPrice) - utils.hexToNumber(baseFee)
);

maxPriorityFeePerGas = tx.maxPriorityFeePerGas || priorityFee || '0x9502F900'; // 2.5 Gwei
maxFeePerGas = tx.maxFeePerGas ||
utils.toHex(
utils.toBN(block.baseFeePerGas)
Expand Down
4 changes: 4 additions & 0 deletions test/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,10 @@ var runTests = function(contractFactory) {

provider.injectResult('0x45656456456456');

provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_feeHistory')
assert.deepEqual(payload.params, ['0x1', 'latest', null])
})

provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_sendTransaction');
Expand Down