From c2afc7ea633376839beed3d65205b70a6bd8ca94 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Wed, 15 Sep 2021 12:59:41 -1000 Subject: [PATCH 1/6] Add BigNumber formatter to baseFeePerGas in returned blocks --- packages/web3-core-helpers/src/formatters.js | 3 ++ test/formatters.outputBlockFormatter.js | 49 ++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 8947c68b94f..2d6aafbc474 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -331,6 +331,9 @@ var outputBlockFormatter = function (block) { if (block.miner) block.miner = utils.toChecksumAddress(block.miner); + if (block.baseFeePerGas) + block.baseFeePerGas = outputBigNumberFormatter(block.baseFeePerGas) + return block; }; diff --git a/test/formatters.outputBlockFormatter.js b/test/formatters.outputBlockFormatter.js index d6bf27563de..2485fb5754e 100644 --- a/test/formatters.outputBlockFormatter.js +++ b/test/formatters.outputBlockFormatter.js @@ -77,5 +77,54 @@ describe('formatters', function () { size: 1000 }); }); + + it('should return the correct value, when baseFeePerGas is present', function () { + + assert.deepEqual(formatters.outputBlockFormatter({ + baseFeePerGas: "0x7", + difficulty: "0x6cd6be3a", + extraData: "0x796f75747562652e636f6d2f77617463683f763d6451773477395767586351", + gasLimit: "0x1c9c381", + gasUsed: "0x8dc073", + hash: "0x846880b1158f434884f3637802ed09bac77eafc35b5f03b881ac88ce38a54907", + logsBloom: "0x4020001000000000000000008000010000000000400200000001002140000008000000010000810020000840000204304000081000000b00400010000822200004200020020140000001000882000064000021303200020000400008800000000002202102000084010000090020a8000800002000000010000030300000000000000006001005000040080001010000010040018100004c0050004000000000420000000021000200000010020008100000004000080000000000000040000900080102004002000080210201081014004030200148101000002020108025000018020020102040000204240500010000002200048000401300080088000002", + miner: "0x86864f1edf10eaf105b1bdc6e9aa8232b4c6aa00", + mixHash: "0xa29afb1fa1aea9eeac72ff435a8fc420bbc1fa1be08223eb61f294ee32250bde", + nonce: "0x122af1a5ccd78f3b", + number: "0xa0d600", + parentHash: "0x28f49150e1fe6f245655925b290f59e707d1e5c646dadaa22937169433b30294", + receiptsRoot: "0xc97d4f9980d680053606318a5820261a1dccb556d1056b70f0d48fb384986be5", + sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + size: "0x2042", + stateRoot: "0x116981b10423133ade5bd44f03c54cc3c57f4467a1c3d4b0c6d8d33a76c361ad", + timestamp: "0x60dc24ec", + totalDifficulty: "0x78828f2d886cbb", + transactions: [], + transactionsRoot: "0x738f53f745d58169da93ebbd52cc49e0c979d6ca68a6513007b546b19ab78ba4", + uncles: [] + }), { + baseFeePerGas: "7", + difficulty: "1826012730", + extraData: "0x796f75747562652e636f6d2f77617463683f763d6451773477395767586351", + gasLimit: 30000001, + gasUsed: 9289843, + hash: "0x846880b1158f434884f3637802ed09bac77eafc35b5f03b881ac88ce38a54907", + logsBloom: "0x4020001000000000000000008000010000000000400200000001002140000008000000010000810020000840000204304000081000000b00400010000822200004200020020140000001000882000064000021303200020000400008800000000002202102000084010000090020a8000800002000000010000030300000000000000006001005000040080001010000010040018100004c0050004000000000420000000021000200000010020008100000004000080000000000000040000900080102004002000080210201081014004030200148101000002020108025000018020020102040000204240500010000002200048000401300080088000002", + miner: "0x86864F1edf10eAf105b1BDC6E9aA8232B4c6aA00", + mixHash: "0xa29afb1fa1aea9eeac72ff435a8fc420bbc1fa1be08223eb61f294ee32250bde", + nonce: "0x122af1a5ccd78f3b", + number: 10540544, + parentHash: "0x28f49150e1fe6f245655925b290f59e707d1e5c646dadaa22937169433b30294", + receiptsRoot: "0xc97d4f9980d680053606318a5820261a1dccb556d1056b70f0d48fb384986be5", + sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + size: 8258, + stateRoot: "0x116981b10423133ade5bd44f03c54cc3c57f4467a1c3d4b0c6d8d33a76c361ad", + timestamp: 1625040108, + totalDifficulty: "33920548661128379", + transactions: [], + transactionsRoot: "0x738f53f745d58169da93ebbd52cc49e0c979d6ca68a6513007b546b19ab78ba4", + uncles: [] + }); + }); }); }); From c29dea12719d7e7d39081d301b857fc2f26651b5 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Wed, 15 Sep 2021 13:02:45 -1000 Subject: [PATCH 2/6] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e67e901b3a..6a9a2c80ca9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -447,4 +447,5 @@ Released with 1.0.0-beta.37 code base. - lerna from 3.22.1 to 4.0.0 (#4231) - Dropped build tests in CI for Node v8 and v10, and added support for Node v14 - Change default value for `maxPriorityFeePerGas` from `1 Gwei` to `2.5 Gwei` (#4284) -- Fixed bug in signTransaction (#4295) \ No newline at end of file +- Fixed bug in signTransaction (#4295) +- Format `block.baseFeePerGas` to big number (#4330) From 2b0a50d49b993cdb2e18cd64553d95752659a834 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Thu, 16 Sep 2021 16:48:16 -1000 Subject: [PATCH 3/6] Update docs for getBlcok --- docs/web3-eth.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/web3-eth.rst b/docs/web3-eth.rst index ce1da8866fb..c5515b0b19c 100644 --- a/docs/web3-eth.rst +++ b/docs/web3-eth.rst @@ -977,6 +977,7 @@ Returns - ``timestamp`` - ``Number``: The unix timestamp for when the block was collated. - ``transactions`` - ``Array``: Array of transaction objects, or 32 Bytes transaction hashes depending on the ``returnTransactionObjects`` parameter. - ``uncles`` - ``Array``: Array of uncle hashes. + - ``baseFeePerGas`` - ``String``: Minimum to be charged to send a transaction on the network (is a number string to avoid number overflow) ------- Example From 15b8f96b9a7c1468273b5bc05e8ded89e38b6e89 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Thu, 16 Sep 2021 16:49:42 -1000 Subject: [PATCH 4/6] Add baseFeePerGas to example output --- docs/web3-eth.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/web3-eth.rst b/docs/web3-eth.rst index c5515b0b19c..96713110380 100644 --- a/docs/web3-eth.rst +++ b/docs/web3-eth.rst @@ -962,6 +962,7 @@ Returns - ``number`` - ``Number``: The block number. ``null`` if a pending block. - ``hash`` 32 Bytes - ``String``: Hash of the block. ``null`` if a pending block. - ``parentHash`` 32 Bytes - ``String``: Hash of the parent block. + - ``baseFeePerGas`` - ``String``: Minimum to be charged to send a transaction on the network (is a number string to avoid number overflow) - ``nonce`` 8 Bytes - ``String``: Hash of the generated proof-of-work. ``null`` if a pending block. - ``sha3Uncles`` 32 Bytes - ``String``: SHA3 of the uncles data in the block. - ``logsBloom`` 256 Bytes - ``String``: The bloom filter for the logs of the block. ``null`` if a pending block. @@ -977,7 +978,6 @@ Returns - ``timestamp`` - ``Number``: The unix timestamp for when the block was collated. - ``transactions`` - ``Array``: Array of transaction objects, or 32 Bytes transaction hashes depending on the ``returnTransactionObjects`` parameter. - ``uncles`` - ``Array``: Array of uncle hashes. - - ``baseFeePerGas`` - ``String``: Minimum to be charged to send a transaction on the network (is a number string to avoid number overflow) ------- Example @@ -993,6 +993,7 @@ Example "number": 3, "hash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46", "parentHash": "0x2302e1c0b972d00932deb5dab9eb2982f570597d9d42504c05d9c2147eaf9c88", + "baseFeePerGas": "58713056622", "nonce": "0xfb6e1a62d119228b", "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", From 1a2ba8ac2979cee777689cae1eb2eb63909ffd96 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Sat, 18 Sep 2021 12:56:21 -1000 Subject: [PATCH 5/6] Update formatting of baseFeePerGas to number --- CHANGELOG.md | 2 +- docs/web3-eth.rst | 4 ++-- packages/web3-core-helpers/src/formatters.js | 2 +- test/formatters.outputBlockFormatter.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a9a2c80ca9..bf10e1c49d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -448,4 +448,4 @@ Released with 1.0.0-beta.37 code base. - Dropped build tests in CI for Node v8 and v10, and added support for Node v14 - Change default value for `maxPriorityFeePerGas` from `1 Gwei` to `2.5 Gwei` (#4284) - Fixed bug in signTransaction (#4295) -- Format `block.baseFeePerGas` to big number (#4330) +- Format `block.baseFeePerGas` to number (#4330) diff --git a/docs/web3-eth.rst b/docs/web3-eth.rst index 96713110380..c74f478faad 100644 --- a/docs/web3-eth.rst +++ b/docs/web3-eth.rst @@ -962,7 +962,7 @@ Returns - ``number`` - ``Number``: The block number. ``null`` if a pending block. - ``hash`` 32 Bytes - ``String``: Hash of the block. ``null`` if a pending block. - ``parentHash`` 32 Bytes - ``String``: Hash of the parent block. - - ``baseFeePerGas`` - ``String``: Minimum to be charged to send a transaction on the network (is a number string to avoid number overflow) + - ``baseFeePerGas`` - ``Number``: Minimum to be charged to send a transaction on the network - ``nonce`` 8 Bytes - ``String``: Hash of the generated proof-of-work. ``null`` if a pending block. - ``sha3Uncles`` 32 Bytes - ``String``: SHA3 of the uncles data in the block. - ``logsBloom`` 256 Bytes - ``String``: The bloom filter for the logs of the block. ``null`` if a pending block. @@ -993,7 +993,7 @@ Example "number": 3, "hash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46", "parentHash": "0x2302e1c0b972d00932deb5dab9eb2982f570597d9d42504c05d9c2147eaf9c88", - "baseFeePerGas": "58713056622", + "baseFeePerGas": 58713056622, "nonce": "0xfb6e1a62d119228b", "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 2d6aafbc474..94b29cfa432 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -332,7 +332,7 @@ var outputBlockFormatter = function (block) { block.miner = utils.toChecksumAddress(block.miner); if (block.baseFeePerGas) - block.baseFeePerGas = outputBigNumberFormatter(block.baseFeePerGas) + block.baseFeePerGas = utils.hexToNumber(block.baseFeePerGas) return block; }; diff --git a/test/formatters.outputBlockFormatter.js b/test/formatters.outputBlockFormatter.js index 2485fb5754e..6915be277df 100644 --- a/test/formatters.outputBlockFormatter.js +++ b/test/formatters.outputBlockFormatter.js @@ -103,7 +103,7 @@ describe('formatters', function () { transactionsRoot: "0x738f53f745d58169da93ebbd52cc49e0c979d6ca68a6513007b546b19ab78ba4", uncles: [] }), { - baseFeePerGas: "7", + baseFeePerGas: 7, difficulty: "1826012730", extraData: "0x796f75747562652e636f6d2f77617463683f763d6451773477395767586351", gasLimit: 30000001, From b43e9caabbcc6dc7b5d1eef8ec4740db86f5f798 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Tue, 21 Sep 2021 14:07:06 -1000 Subject: [PATCH 6/6] Add baseFeePerGas to BlockHeader type --- packages/web3-eth/types/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/web3-eth/types/index.d.ts b/packages/web3-eth/types/index.d.ts index ef5d86c0d0d..49c275e7211 100644 --- a/packages/web3-eth/types/index.d.ts +++ b/packages/web3-eth/types/index.d.ts @@ -409,6 +409,7 @@ export interface BlockHeader { gasLimit: number; gasUsed: number; timestamp: number | string; + baseFeePerGas?: number; } // TODO: This interface does exist to provide backwards-compatibility and can get removed on a minor release