Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 977f0f9

Browse files
Format baseFeePerGas to number in returned blocks - Closes #4326 (#4330)
* Add BigNumber formatter to baseFeePerGas in returned blocks * Update CHANGELOG * Update docs for getBlcok * Add baseFeePerGas to example output * Update formatting of baseFeePerGas to number * Add baseFeePerGas to BlockHeader type
1 parent 40974e9 commit 977f0f9

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,13 @@ Released with 1.0.0-beta.37 code base.
446446
- lerna from 3.22.1 to 4.0.0 (#4231)
447447
- Dropped build tests in CI for Node v8 and v10, and added support for Node v14
448448
- Change default value for `maxPriorityFeePerGas` from `1 Gwei` to `2.5 Gwei` (#4284)
449-
- Fixed bug in signTransaction (#4295)
450-
- Introduced new configuration "blockHeaderTimeout" for waiting of block headers for transaction receipt (#3891)
451449
- Fixed bug in signTransaction (#4295)
450+
- Format `block.baseFeePerGas` to number (#4330)
451+
- Introduced new configuration "blockHeaderTimeout" for waiting of block headers for transaction receipt (#3891)
452452

453453
## [Unreleased]
454454

455455
## [1.5.4]
456+
456457
### Changed
457458
- Not considering `tx.chainId` if `tx.common.customChain.chainId` is provided for `web3.eth.accounts.signTransaction` function (#4293)

docs/web3-eth.rst

+2
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ Returns
996996
- ``number`` - ``Number``: The block number. ``null`` if a pending block.
997997
- ``hash`` 32 Bytes - ``String``: Hash of the block. ``null`` if a pending block.
998998
- ``parentHash`` 32 Bytes - ``String``: Hash of the parent block.
999+
- ``baseFeePerGas`` - ``Number``: Minimum to be charged to send a transaction on the network
9991000
- ``nonce`` 8 Bytes - ``String``: Hash of the generated proof-of-work. ``null`` if a pending block.
10001001
- ``sha3Uncles`` 32 Bytes - ``String``: SHA3 of the uncles data in the block.
10011002
- ``logsBloom`` 256 Bytes - ``String``: The bloom filter for the logs of the block. ``null`` if a pending block.
@@ -1026,6 +1027,7 @@ Example
10261027
"number": 3,
10271028
"hash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46",
10281029
"parentHash": "0x2302e1c0b972d00932deb5dab9eb2982f570597d9d42504c05d9c2147eaf9c88",
1030+
"baseFeePerGas": 58713056622,
10291031
"nonce": "0xfb6e1a62d119228b",
10301032
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
10311033
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",

packages/web3-core-helpers/src/formatters.js

+3
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ var outputBlockFormatter = function (block) {
331331
if (block.miner)
332332
block.miner = utils.toChecksumAddress(block.miner);
333333

334+
if (block.baseFeePerGas)
335+
block.baseFeePerGas = utils.hexToNumber(block.baseFeePerGas)
336+
334337
return block;
335338
};
336339

packages/web3-eth/types/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ export interface BlockHeader {
409409
gasLimit: number;
410410
gasUsed: number;
411411
timestamp: number | string;
412+
baseFeePerGas?: number;
412413
}
413414

414415
// TODO: This interface does exist to provide backwards-compatibility and can get removed on a minor release

test/formatters.outputBlockFormatter.js

+49
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,54 @@ describe('formatters', function () {
7777
size: 1000
7878
});
7979
});
80+
81+
it('should return the correct value, when baseFeePerGas is present', function () {
82+
83+
assert.deepEqual(formatters.outputBlockFormatter({
84+
baseFeePerGas: "0x7",
85+
difficulty: "0x6cd6be3a",
86+
extraData: "0x796f75747562652e636f6d2f77617463683f763d6451773477395767586351",
87+
gasLimit: "0x1c9c381",
88+
gasUsed: "0x8dc073",
89+
hash: "0x846880b1158f434884f3637802ed09bac77eafc35b5f03b881ac88ce38a54907",
90+
logsBloom: "0x4020001000000000000000008000010000000000400200000001002140000008000000010000810020000840000204304000081000000b00400010000822200004200020020140000001000882000064000021303200020000400008800000000002202102000084010000090020a8000800002000000010000030300000000000000006001005000040080001010000010040018100004c0050004000000000420000000021000200000010020008100000004000080000000000000040000900080102004002000080210201081014004030200148101000002020108025000018020020102040000204240500010000002200048000401300080088000002",
91+
miner: "0x86864f1edf10eaf105b1bdc6e9aa8232b4c6aa00",
92+
mixHash: "0xa29afb1fa1aea9eeac72ff435a8fc420bbc1fa1be08223eb61f294ee32250bde",
93+
nonce: "0x122af1a5ccd78f3b",
94+
number: "0xa0d600",
95+
parentHash: "0x28f49150e1fe6f245655925b290f59e707d1e5c646dadaa22937169433b30294",
96+
receiptsRoot: "0xc97d4f9980d680053606318a5820261a1dccb556d1056b70f0d48fb384986be5",
97+
sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
98+
size: "0x2042",
99+
stateRoot: "0x116981b10423133ade5bd44f03c54cc3c57f4467a1c3d4b0c6d8d33a76c361ad",
100+
timestamp: "0x60dc24ec",
101+
totalDifficulty: "0x78828f2d886cbb",
102+
transactions: [],
103+
transactionsRoot: "0x738f53f745d58169da93ebbd52cc49e0c979d6ca68a6513007b546b19ab78ba4",
104+
uncles: []
105+
}), {
106+
baseFeePerGas: 7,
107+
difficulty: "1826012730",
108+
extraData: "0x796f75747562652e636f6d2f77617463683f763d6451773477395767586351",
109+
gasLimit: 30000001,
110+
gasUsed: 9289843,
111+
hash: "0x846880b1158f434884f3637802ed09bac77eafc35b5f03b881ac88ce38a54907",
112+
logsBloom: "0x4020001000000000000000008000010000000000400200000001002140000008000000010000810020000840000204304000081000000b00400010000822200004200020020140000001000882000064000021303200020000400008800000000002202102000084010000090020a8000800002000000010000030300000000000000006001005000040080001010000010040018100004c0050004000000000420000000021000200000010020008100000004000080000000000000040000900080102004002000080210201081014004030200148101000002020108025000018020020102040000204240500010000002200048000401300080088000002",
113+
miner: "0x86864F1edf10eAf105b1BDC6E9aA8232B4c6aA00",
114+
mixHash: "0xa29afb1fa1aea9eeac72ff435a8fc420bbc1fa1be08223eb61f294ee32250bde",
115+
nonce: "0x122af1a5ccd78f3b",
116+
number: 10540544,
117+
parentHash: "0x28f49150e1fe6f245655925b290f59e707d1e5c646dadaa22937169433b30294",
118+
receiptsRoot: "0xc97d4f9980d680053606318a5820261a1dccb556d1056b70f0d48fb384986be5",
119+
sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
120+
size: 8258,
121+
stateRoot: "0x116981b10423133ade5bd44f03c54cc3c57f4467a1c3d4b0c6d8d33a76c361ad",
122+
timestamp: 1625040108,
123+
totalDifficulty: "33920548661128379",
124+
transactions: [],
125+
transactionsRoot: "0x738f53f745d58169da93ebbd52cc49e0c979d6ca68a6513007b546b19ab78ba4",
126+
uncles: []
127+
});
128+
});
80129
});
81130
});

0 commit comments

Comments
 (0)