diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ed922075ca..44314e4fdf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -497,5 +497,6 @@ Released with 1.0.0-beta.37 code base. ### Fixed - Fix a typo in the documentation for `methods.myMethod.send` (#4599) +- Added effectiveGasPrice to TransactionReceipt (#4692) - Correction in documentation for `web3.eth.accounts.signTransaction` (#4576) - Updated README to include Webpack 5 create-react-app support instructions (#4173) diff --git a/docs/web3-eth.rst b/docs/web3-eth.rst index 3194ef7287d..e5ff527189a 100644 --- a/docs/web3-eth.rst +++ b/docs/web3-eth.rst @@ -1402,8 +1402,9 @@ Returns - ``to`` - ``String``: Address of the receiver. ``null`` when it's a contract creation transaction. - ``contractAddress`` - ``String``: The contract address created, if the transaction was a contract creation, otherwise ``null``. - ``cumulativeGasUsed`` - ``Number``: The total amount of gas used when this transaction was executed in the block. - - ``gasUsed``- ``Number``: The amount of gas used by this specific transaction alone. + - ``gasUsed`` - ``Number``: The amount of gas used by this specific transaction alone. - ``logs`` - ``Array``: Array of log objects, which this transaction generated. + - ``effectiveGasPrice`` - ``Number``: The actual value per gas deducted from the senders account. Before EIP-1559, this is equal to the transaction's gas price. After, it is equal to baseFeePerGas + min(maxFeePerGas - baseFeePerGas, maxPriorityFeePerGas). ------- Example diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 94b29cfa432..cef20a7090b 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -288,6 +288,9 @@ var outputTransactionReceiptFormatter = function (receipt) { receipt.logs = receipt.logs.map(outputLogFormatter); } + if (receipt.effectiveGasPrice) { + receipt.effectiveGasPrice = utils.hexToNumber(receipt.effectiveGasPrice) + } if (receipt.contractAddress) { receipt.contractAddress = utils.toChecksumAddress(receipt.contractAddress); } diff --git a/packages/web3-core/types/index.d.ts b/packages/web3-core/types/index.d.ts index 4065992bc7b..3015bf288a3 100644 --- a/packages/web3-core/types/index.d.ts +++ b/packages/web3-core/types/index.d.ts @@ -213,6 +213,7 @@ export interface TransactionReceipt { contractAddress?: string; cumulativeGasUsed: number; gasUsed: number; + effectiveGasPrice: number; logs: Log[]; logsBloom: string; events?: { diff --git a/test/eth.getTransactionReceipt.js b/test/eth.getTransactionReceipt.js index dabb7f6bb64..ee86e5bf85d 100644 --- a/test/eth.getTransactionReceipt.js +++ b/test/eth.getTransactionReceipt.js @@ -10,6 +10,7 @@ var txResult = { "contractAddress":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", "cumulativeGasUsed":"0x7f110", "gasUsed": "0x7f110", + "effectiveGasPrice": "0x09184e72a000", "logs": [{ transactionIndex: '0x3e8', logIndex: '0x3e8', @@ -36,6 +37,7 @@ var formattedTxResult = { "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "cumulativeGasUsed": 520464, "gasUsed": 520464, + "effectiveGasPrice": 10000000000000, "logs": [{ id: "log_2b801386", transactionIndex: 1000,