From e774646b32c2c090e6ba0886e43e27feba3e865e Mon Sep 17 00:00:00 2001 From: Muhammad Altabba <24407834+Muhammad-Altabba@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:42:54 +0100 Subject: [PATCH] feat: Add getMaxPriorityFeePerGas method (#6748) * add getMaxPriorityFeePerGas method * update CHANGELOG.md files * add integration test * add a unit test --------- Co-authored-by: Alex --- packages/web3-eth/CHANGELOG.md | 4 + packages/web3-eth/src/rpc_method_wrappers.ts | 12 + packages/web3-eth/src/web3_eth.ts | 305 +++++++++--------- .../web3_eth/send_transaction.test.ts | 117 ++++--- .../web3_eth_methods_no_parameters.test.ts | 5 + packages/web3-rpc-methods/CHANGELOG.md | 3 + .../web3-rpc-methods/src/eth_rpc_methods.ts | 7 + .../get_maxPriorityFeePerGas.ts | 52 +++ .../web3-types/src/apis/eth_execution_api.ts | 6 +- 9 files changed, 304 insertions(+), 207 deletions(-) create mode 100644 packages/web3-rpc-methods/test/unit/eth_rpc_methods/get_maxPriorityFeePerGas.ts diff --git a/packages/web3-eth/CHANGELOG.md b/packages/web3-eth/CHANGELOG.md index 021eb321d59..f1ab3d6b532 100644 --- a/packages/web3-eth/CHANGELOG.md +++ b/packages/web3-eth/CHANGELOG.md @@ -220,3 +220,7 @@ Documentation: - Catch `TransactionPollingTimeoutError` was added to send transaction events (#6623) ## [Unreleased] + +### Added + +- Added `eth.getMaxPriorityFeePerGas` method (#6748) diff --git a/packages/web3-eth/src/rpc_method_wrappers.ts b/packages/web3-eth/src/rpc_method_wrappers.ts index 4dd01805603..1a2cac1ffd8 100644 --- a/packages/web3-eth/src/rpc_method_wrappers.ts +++ b/packages/web3-eth/src/rpc_method_wrappers.ts @@ -138,6 +138,18 @@ export async function getGasPrice( return format({ format: 'uint' }, response as Numbers, returnFormat); } +/** + * View additional documentations here: {@link Web3Eth.getMaxPriorityFeePerGas} + * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc. + */ +export async function getMaxPriorityFeePerGas( + web3Context: Web3Context, + returnFormat: ReturnFormat, +) { + const response = await ethRpcMethods.getMaxPriorityFeePerGas(web3Context.requestManager); + + return format({ format: 'uint' }, response as Numbers, returnFormat); +} /** * View additional documentations here: {@link Web3Eth.getBlockNumber} * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc. diff --git a/packages/web3-eth/src/web3_eth.ts b/packages/web3-eth/src/web3_eth.ts index 42ca62e7b54..05fa88926d5 100644 --- a/packages/web3-eth/src/web3_eth.ts +++ b/packages/web3-eth/src/web3_eth.ts @@ -238,6 +238,24 @@ export class Web3Eth extends Web3Context 20000000000n + * + * web3.eth.getMaxPriorityFeePerGas({ number: FMT_NUMBER.HEX , bytes: FMT_BYTES.HEX }).then(console.log); + * > "0x4a817c800" + * ``` + */ + public async getMaxPriorityFeePerGas< + ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT, + >(returnFormat: ReturnFormat = DEFAULT_RETURN_FORMAT as ReturnFormat) { + return rpcMethodsWrappers.getMaxPriorityFeePerGas(this, returnFormat); + } + /** * @returns A list of accounts the node controls (addresses are checksummed). * @@ -326,13 +344,7 @@ export class Web3Eth extends Web3Context 1 * ``` */ - public async getTransactionCount< - ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT, - >( + public async getTransactionCount( address: Address, blockNumber: BlockNumberOrTag = this.defaultBlock, returnFormat: ReturnFormat = DEFAULT_RETURN_FORMAT as ReturnFormat, @@ -1579,137 +1580,137 @@ export class Web3Eth extends Web3Context console.log(data)); - * logSubscription.on('error', (error: any) => console.log(error)); - * - * ``` - * - * @example **Subscribe to new block headers** - * ```ts - * // Subscribe to `newBlockHeaders` - * const newBlocksSubscription = await web3.eth.subscribe('newBlockHeaders'); - * - * newBlocksSubscription.on('data', async blockhead => { - * console.log('New block header: ', blockhead); - * - * // You do not need the next line, if you like to keep notified for every new block - * await newBlocksSubscription.unsubscribe(); - * console.log('Unsubscribed from new block headers.'); - * }); - * newBlocksSubscription.on('error', error => - * console.log('Error when subscribing to New block header: ', error), - * ); - * ``` - * - * ### subscribe('pendingTransactions') - * - * Subscribes to incoming pending transactions. - * You can subscribe to pending transactions by calling web3.eth.subscribe('pendingTransactions'). - * - * ```ts - * (await web3.eth.subscribe('pendingTransactions')).on('data', console.log); - * ``` - * - * ### subscribe('newHeads') - * ( same as subscribe('newBlockHeaders')) - * Subscribes to incoming block headers. This can be used as timer to check for changes on the blockchain. - * - * The structure of a returned block header is {@link BlockHeaderOutput}: - * - * ```ts - * (await web3.eth.subscribe('newHeads')).on( // 'newBlockHeaders' would work as well - * 'data', - * console.log - * ); - * >{ - * parentHash: '0x9e746a1d906b299def98c75b06f714d62dacadd567c7515d76eeaa8c8074c738', - * sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', - * miner: '0x0000000000000000000000000000000000000000', - * stateRoot: '0xe0f04b04861ecfa95e82a9310d6a7ef7aef8d7417f5209c182582bfb98a8e307', - * transactionsRoot: '0x31ab4ea571a9e10d3a19aaed07d190595b1dfa34e03960c04293fec565dea536', - * logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', - * difficulty: 2n, - * number: 21n, - * gasLimit: 11738125n, - * gasUsed: 830006n, - * timestamp: 1678797237n, - * extraData: '0xd883010b02846765746888676f312e32302e31856c696e757800000000000000e0a6e93cf40e2e71a72e493272210c3f43738ccc7e7d7b14ffd51833797d896c09117e8dc4fbcbc969bd21b42e5af3e276a911524038c001b2109b63b8e0352601', - * nonce: 0n - * } - * ``` - * - * ### subscribe('syncing') - * Subscribe to syncing events. This will return `true` when the node is syncing and when it’s finished syncing will return `false`, for the `changed` event. - * - * ```ts - * (await web3.eth.subscribe('syncing')).on('changed', console.log); - * > `true` // when syncing - * - * (await web3.eth.subscribe('syncing')).on('data', console.log); - * > { - * startingBlock: 0, - * currentBlock: 0, - * highestBlock: 0, - * pulledStates: 0, - * knownStates: 0 - * } - * ``` - * - * ### subscribe('logs', options) - * Subscribes to incoming logs, filtered by the given options. If a valid numerical fromBlock options property is set, web3.js will retrieve logs beginning from this point, backfilling the response as necessary. - * - * options: You can subscribe to logs matching a given filter object, which can take the following parameters: - * - `fromBlock`: (optional, default: 'latest') Integer block number, or `'latest'` for the last mined block or `'pending'`, `'earliest'` for not yet mined transactions. - * - `address`: (optional) Contract address or a list of addresses from which logs should originate. - * - `topics`: (optional) Array of 32 Bytes DATA topics. Topics are order-dependent. Each topic can also be an array of DATA with `or` options. - * - * ```ts - * (await web3.eth.subscribe('logs', { - * address: '0xdac17f958d2ee523a2206206994597c13d831ec7', - * })).on('data', console.log); - * - * > { - * removed: false, - * logIndex: 119n, - * transactionIndex: 58n, - * transactionHash: '0x61533efa77937360215069d5d6cb0be09a22af9721e6dc3df59d957833ed8870', - * blockHash: '0xe32bb97084479d32247f66f8b46d00af2fbc3c2db2bc6e5843fe2e4d1ca9b099', - * blockNumber: 18771966n, - * address: '0xdac17f958d2ee523a2206206994597c13d831ec7', - * data: '0x00000000000000000000000000000000000000000000000000000000d88b2e40', - * topics: [ - * '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', - * '0x0000000000000000000000002fb2457f6ec1865dc0d4e7300c696b69c2a1b989', - * '0x00000000000000000000000027fd43babfbe83a81d14665b1a6fb8030a60c9b4' - * ] - * } - *``` - */ + * Lets you subscribe to specific events in the blockchain. + * + * @param name - The subscription you want to subscribe to. + * @param args - Optional additional parameters, depending on the subscription type. + * @returns A subscription object of type {@link RegisteredSubscription}. The object contains: + * - subscription.id: The subscription id, used to identify and unsubscribing the subscription. + * - subscription.subscribe(): Can be used to re-subscribe with the same parameters. + * - subscription.unsubscribe(): Unsubscribes the subscription and returns TRUE in the callback if successful. + * - subscription.args: The subscription arguments, used when re-subscribing. + * + * + * You can use the subscription object to listen on: + * + * - on("data") - Fires on each incoming log with the log object as argument. + * - on("changed") - Fires on each log which was removed from the blockchain. The log will have the additional property "removed: true". + * - on("error") - Fires when an error in the subscription occurs. + * - on("connected") - Fires once after the subscription successfully connected. Returns the subscription id. + * + * @example **Subscribe to Smart Contract events** + * ```ts + * // Subscribe to `logs` + * const logSubscription = web3.eth.subscribe('logs', { + * address: '0x1234567890123456789012345678901234567890', + * topics: ['0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234'] + * }); + * logSubscription.on('data', (data: any) => console.log(data)); + * logSubscription.on('error', (error: any) => console.log(error)); + * + * ``` + * + * @example **Subscribe to new block headers** + * ```ts + * // Subscribe to `newBlockHeaders` + * const newBlocksSubscription = await web3.eth.subscribe('newBlockHeaders'); + * + * newBlocksSubscription.on('data', async blockhead => { + * console.log('New block header: ', blockhead); + * + * // You do not need the next line, if you like to keep notified for every new block + * await newBlocksSubscription.unsubscribe(); + * console.log('Unsubscribed from new block headers.'); + * }); + * newBlocksSubscription.on('error', error => + * console.log('Error when subscribing to New block header: ', error), + * ); + * ``` + * + * ### subscribe('pendingTransactions') + * + * Subscribes to incoming pending transactions. + * You can subscribe to pending transactions by calling web3.eth.subscribe('pendingTransactions'). + * + * ```ts + * (await web3.eth.subscribe('pendingTransactions')).on('data', console.log); + * ``` + * + * ### subscribe('newHeads') + * ( same as subscribe('newBlockHeaders')) + * Subscribes to incoming block headers. This can be used as timer to check for changes on the blockchain. + * + * The structure of a returned block header is {@link BlockHeaderOutput}: + * + * ```ts + * (await web3.eth.subscribe('newHeads')).on( // 'newBlockHeaders' would work as well + * 'data', + * console.log + * ); + * >{ + * parentHash: '0x9e746a1d906b299def98c75b06f714d62dacadd567c7515d76eeaa8c8074c738', + * sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', + * miner: '0x0000000000000000000000000000000000000000', + * stateRoot: '0xe0f04b04861ecfa95e82a9310d6a7ef7aef8d7417f5209c182582bfb98a8e307', + * transactionsRoot: '0x31ab4ea571a9e10d3a19aaed07d190595b1dfa34e03960c04293fec565dea536', + * logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + * difficulty: 2n, + * number: 21n, + * gasLimit: 11738125n, + * gasUsed: 830006n, + * timestamp: 1678797237n, + * extraData: '0xd883010b02846765746888676f312e32302e31856c696e757800000000000000e0a6e93cf40e2e71a72e493272210c3f43738ccc7e7d7b14ffd51833797d896c09117e8dc4fbcbc969bd21b42e5af3e276a911524038c001b2109b63b8e0352601', + * nonce: 0n + * } + * ``` + * + * ### subscribe('syncing') + * Subscribe to syncing events. This will return `true` when the node is syncing and when it’s finished syncing will return `false`, for the `changed` event. + * + * ```ts + * (await web3.eth.subscribe('syncing')).on('changed', console.log); + * > `true` // when syncing + * + * (await web3.eth.subscribe('syncing')).on('data', console.log); + * > { + * startingBlock: 0, + * currentBlock: 0, + * highestBlock: 0, + * pulledStates: 0, + * knownStates: 0 + * } + * ``` + * + * ### subscribe('logs', options) + * Subscribes to incoming logs, filtered by the given options. If a valid numerical fromBlock options property is set, web3.js will retrieve logs beginning from this point, backfilling the response as necessary. + * + * options: You can subscribe to logs matching a given filter object, which can take the following parameters: + * - `fromBlock`: (optional, default: 'latest') Integer block number, or `'latest'` for the last mined block or `'pending'`, `'earliest'` for not yet mined transactions. + * - `address`: (optional) Contract address or a list of addresses from which logs should originate. + * - `topics`: (optional) Array of 32 Bytes DATA topics. Topics are order-dependent. Each topic can also be an array of DATA with `or` options. + * + * ```ts + * (await web3.eth.subscribe('logs', { + * address: '0xdac17f958d2ee523a2206206994597c13d831ec7', + * })).on('data', console.log); + * + * > { + * removed: false, + * logIndex: 119n, + * transactionIndex: 58n, + * transactionHash: '0x61533efa77937360215069d5d6cb0be09a22af9721e6dc3df59d957833ed8870', + * blockHash: '0xe32bb97084479d32247f66f8b46d00af2fbc3c2db2bc6e5843fe2e4d1ca9b099', + * blockNumber: 18771966n, + * address: '0xdac17f958d2ee523a2206206994597c13d831ec7', + * data: '0x00000000000000000000000000000000000000000000000000000000d88b2e40', + * topics: [ + * '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', + * '0x0000000000000000000000002fb2457f6ec1865dc0d4e7300c696b69c2a1b989', + * '0x00000000000000000000000027fd43babfbe83a81d14665b1a6fb8030a60c9b4' + * ] + * } + *``` + */ public async subscribe< T extends keyof RegisteredSubscription, diff --git a/packages/web3-eth/test/integration/web3_eth/send_transaction.test.ts b/packages/web3-eth/test/integration/web3_eth/send_transaction.test.ts index a5203a93332..de7b7f1edb6 100644 --- a/packages/web3-eth/test/integration/web3_eth/send_transaction.test.ts +++ b/packages/web3-eth/test/integration/web3_eth/send_transaction.test.ts @@ -37,8 +37,9 @@ import { createTempAccount, getSystemTestBackend, getSystemTestProvider, + isGeth, itIf, - BACKEND + BACKEND, } from '../../fixtures/system_test_utils'; import { SimpleRevertAbi, SimpleRevertDeploymentData } from '../../fixtures/simple_revert'; @@ -89,9 +90,7 @@ describe('Web3Eth.sendTransaction', () => { expect(response.status).toBe(BigInt(1)); expect(response.events).toBeUndefined(); - const minedTransactionData = await web3EthWithWallet.getTransaction( - response.transactionHash, - ); + const minedTransactionData = await web3EthWithWallet.getTransaction(response.transactionHash); expect(minedTransactionData).toMatchObject({ from: tempAcc.address, @@ -120,9 +119,7 @@ describe('Web3Eth.sendTransaction', () => { expect(response.status).toBe(BigInt(1)); expect(response.events).toBeUndefined(); - const minedTransactionData = await web3EthWithWallet.getTransaction( - response.transactionHash, - ); + const minedTransactionData = await web3EthWithWallet.getTransaction(response.transactionHash); expect(minedTransactionData).toMatchObject({ from: tempAcc.address, @@ -155,9 +152,7 @@ describe('Web3Eth.sendTransaction', () => { expect(response.status).toBe(BigInt(1)); expect(response.events).toBeUndefined(); - const minedTransactionData = await web3EthWithWallet.getTransaction( - response.transactionHash, - ); + const minedTransactionData = await web3EthWithWallet.getTransaction(response.transactionHash); expect(minedTransactionData).toMatchObject({ from: tempAcc.address, @@ -371,6 +366,29 @@ describe('Web3Eth.sendTransaction', () => { expect(minedTransactionData).toMatchObject(transaction); }); + itIf(isGeth)( + 'should send type 0x2 transaction with maxPriorityFeePerGas got from await web3Eth.getMaxPriorityFeePerGas()', + async () => { + const transaction: Transaction = { + from: tempAcc.address, + to: '0x0000000000000000000000000000000000000000', + value: BigInt(1), + maxPriorityFeePerGas: await web3Eth.getMaxPriorityFeePerGas(), + }; + const response = await web3Eth.sendTransaction(transaction); + + // eslint-disable-next-line jest/no-standalone-expect + expect(response.events).toBeUndefined(); + // eslint-disable-next-line jest/no-standalone-expect + expect(response.type).toBe(BigInt(2)); + // eslint-disable-next-line jest/no-standalone-expect + expect(response.status).toBe(BigInt(1)); + const minedTransactionData = await web3Eth.getTransaction(response.transactionHash); + // eslint-disable-next-line jest/no-standalone-expect + expect(minedTransactionData).toMatchObject(transaction); + }, + ); + describe('Transaction PromiEvents', () => { let transaction: Transaction; @@ -476,12 +494,9 @@ describe('Web3Eth.sendTransaction', () => { from: tempAcc.address, data: SimpleRevertDeploymentData, }; - simpleRevertDeployTransaction.gas = await web3Eth.estimateGas( - simpleRevertDeployTransaction, - ); - simpleRevertContractAddress = ( - await web3Eth.sendTransaction(simpleRevertDeployTransaction) - ).contractAddress as Address; + simpleRevertDeployTransaction.gas = await web3Eth.estimateGas(simpleRevertDeployTransaction); + simpleRevertContractAddress = (await web3Eth.sendTransaction(simpleRevertDeployTransaction)) + .contractAddress as Address; }); it('Should throw TransactionRevertInstructionError because gas too low', async () => { @@ -500,51 +515,51 @@ describe('Web3Eth.sendTransaction', () => { ? 'err: intrinsic gas too low: have 1, want 21000 (supplied gas 1)' : 'base fee exceeds gas limit', }; - - if(getSystemTestBackend() !== BACKEND.HARDHAT){ + + if (getSystemTestBackend() !== BACKEND.HARDHAT) { await expect( web3Eth .sendTransaction(transaction) .on('error', error => expect(error).toMatchObject(expectedThrownError)), ).rejects.toMatchObject(expectedThrownError); } else { - try { await web3Eth.sendTransaction(transaction); - } catch (error) { + } catch (error) { expect((error as any).name).toEqual(expectedThrownError.name); expect((error as any).code).toEqual(expectedThrownError.code); expect((error as any).reason).toContain(expectedThrownError.reason); - } + } } }); - itIf(getSystemTestBackend() !== BACKEND.HARDHAT)('Should throw TransactionRevertInstructionError because insufficient funds', async () => { - const transaction: Transaction = { - from: tempAcc.address, - to: '0x0000000000000000000000000000000000000000', - value: BigInt('99999999999999999999999999999999999999999999999999999999999999999'), - }; - - const expectedThrownError = { - name: 'TransactionRevertInstructionError', - message: 'Transaction has been reverted by the EVM', - code: 402, - reason: - getSystemTestBackend() === BACKEND.GETH - ? expect.stringContaining( - 'err: insufficient funds for gas * price + value: address', - ) - : 'VM Exception while processing transaction: insufficient balance', - }; - - // eslint-disable-next-line jest/no-standalone-expect - await expect( - web3Eth - .sendTransaction(transaction) - // eslint-disable-next-line jest/no-standalone-expect - .on('error', error => expect(error).toMatchObject(expectedThrownError)), - ).rejects.toMatchObject(expectedThrownError); - }); + itIf(getSystemTestBackend() !== BACKEND.HARDHAT)( + 'Should throw TransactionRevertInstructionError because insufficient funds', + async () => { + const transaction: Transaction = { + from: tempAcc.address, + to: '0x0000000000000000000000000000000000000000', + value: BigInt('99999999999999999999999999999999999999999999999999999999999999999'), + }; + + const expectedThrownError = { + name: 'TransactionRevertInstructionError', + message: 'Transaction has been reverted by the EVM', + code: 402, + reason: + getSystemTestBackend() === BACKEND.GETH + ? expect.stringContaining('err: insufficient funds for gas * price + value: address') + : 'VM Exception while processing transaction: insufficient balance', + }; + + // eslint-disable-next-line jest/no-standalone-expect + await expect( + web3Eth + .sendTransaction(transaction) + // eslint-disable-next-line jest/no-standalone-expect + .on('error', error => expect(error).toMatchObject(expectedThrownError)), + ).rejects.toMatchObject(expectedThrownError); + }, + ); it('Should throw TransactionRevertInstructionError because of contract revert and return revert reason', async () => { const transaction: Transaction = { @@ -589,7 +604,7 @@ describe('Web3Eth.sendTransaction', () => { reason: getSystemTestBackend() === BACKEND.GETH ? 'execution reverted' - : "Error: VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0x72090e4d)", + : 'Error: VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0x72090e4d)', signature: '0x72090e4d', customErrorName: 'ErrorWithNoParams', customErrorDecodedSignature: 'ErrorWithNoParams()', @@ -619,7 +634,7 @@ describe('Web3Eth.sendTransaction', () => { reason: getSystemTestBackend() === BACKEND.GETH ? 'execution reverted' - : "Error: VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0xc85bda60000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001c5468697320697320616e206572726f72207769746820706172616d7300000000)", + : 'Error: VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0xc85bda60000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001c5468697320697320616e206572726f72207769746820706172616d7300000000)', signature: '0xc85bda60', data: '000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001c5468697320697320616e206572726f72207769746820706172616d7300000000', customErrorName: 'ErrorWithParams', @@ -657,7 +672,7 @@ describe('Web3Eth.sendTransaction', () => { signature: '0x08c379a0', data: '000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000155468697320697320612073656e64207265766572740000000000000000000000', }; - + await expect( web3Eth .sendTransaction(transaction) diff --git a/packages/web3-eth/test/unit/web3_eth_methods_no_parameters.test.ts b/packages/web3-eth/test/unit/web3_eth_methods_no_parameters.test.ts index 6865188b456..a66a1ecdd46 100644 --- a/packages/web3-eth/test/unit/web3_eth_methods_no_parameters.test.ts +++ b/packages/web3-eth/test/unit/web3_eth_methods_no_parameters.test.ts @@ -76,5 +76,10 @@ describe('web3_eth_methods_no_parameters', () => { await web3Eth.getNodeInfo(); expect(ethRpcMethods.getNodeInfo).toHaveBeenCalledWith(web3Eth.requestManager); }); + + it('getMaxPriorityFeePerGas', async () => { + await web3Eth.getMaxPriorityFeePerGas(); + expect(ethRpcMethods.getMaxPriorityFeePerGas).toHaveBeenCalledWith(web3Eth.requestManager); + }); }); }); diff --git a/packages/web3-rpc-methods/CHANGELOG.md b/packages/web3-rpc-methods/CHANGELOG.md index 29de022b81c..9b2c602e962 100644 --- a/packages/web3-rpc-methods/CHANGELOG.md +++ b/packages/web3-rpc-methods/CHANGELOG.md @@ -134,3 +134,6 @@ Documentation: ## [Unreleased] +### Added + +- Added `getMaxPriorityFeePerGas` method (#6748) diff --git a/packages/web3-rpc-methods/src/eth_rpc_methods.ts b/packages/web3-rpc-methods/src/eth_rpc_methods.ts index 59c269051a4..b33857d7d80 100644 --- a/packages/web3-rpc-methods/src/eth_rpc_methods.ts +++ b/packages/web3-rpc-methods/src/eth_rpc_methods.ts @@ -73,6 +73,13 @@ export async function getGasPrice(requestManager: Web3RequestManager) { }); } +export async function getMaxPriorityFeePerGas(requestManager: Web3RequestManager) { + return requestManager.send({ + method: 'eth_maxPriorityFeePerGas', + params: [], + }); +} + export async function getAccounts(requestManager: Web3RequestManager) { return requestManager.send({ method: 'eth_accounts', diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/get_maxPriorityFeePerGas.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/get_maxPriorityFeePerGas.ts new file mode 100644 index 00000000000..bafe6a92c03 --- /dev/null +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/get_maxPriorityFeePerGas.ts @@ -0,0 +1,52 @@ +/* +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 . +*/ + +// 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 { Web3RequestManager } from 'web3-core'; + +import { ethRpcMethods } from '../../../src/index'; + +describe('getMaxPriorityFeePerGas', () => { + let requestManagerSendSpy: jest.Mock; + let requestManager: Web3RequestManager; + + beforeAll(() => { + requestManager = new Web3RequestManager('http://127.0.0.1:8545'); + requestManagerSendSpy = jest.fn(); + requestManager.send = requestManagerSendSpy; + }); + + it('should call requestManager.send with getMaxPriorityFeePerGas method', async () => { + await ethRpcMethods.getMaxPriorityFeePerGas(requestManager); + expect(requestManagerSendSpy).toHaveBeenCalledWith({ + method: 'eth_maxPriorityFeePerGas', + params: [], + }); + }); +}); diff --git a/packages/web3-types/src/apis/eth_execution_api.ts b/packages/web3-types/src/apis/eth_execution_api.ts index e015e6b9ed3..3abb0b29af0 100644 --- a/packages/web3-types/src/apis/eth_execution_api.ts +++ b/packages/web3-types/src/apis/eth_execution_api.ts @@ -193,10 +193,7 @@ export type EthExecutionAPI = { eth_getUncleCountByBlockHash: (blockHash: HexString32Bytes) => Uint; eth_getUncleCountByBlockNumber: (blockNumber: BlockNumberOrTag) => Uint; eth_getUncleByBlockHashAndIndex: (blockHash: HexString32Bytes, uncleIndex: Uint) => BlockAPI; - eth_getUncleByBlockNumberAndIndex: ( - blockNumber: BlockNumberOrTag, - uncleIndex: Uint, - ) => BlockAPI; + eth_getUncleByBlockNumberAndIndex: (blockNumber: BlockNumberOrTag, uncleIndex: Uint) => BlockAPI; // https://github.com/ethereum/execution-apis/blob/main/src/eth/transaction.yaml eth_getTransactionByHash: (transactionHash: HexString32Bytes) => TransactionInfoAPI | undefined; @@ -233,6 +230,7 @@ export type EthExecutionAPI = { newestBlock: BlockNumberOrTag, rewardPercentiles: number[], ) => FeeHistoryResultAPI; + eth_maxPriorityFeePerGas: () => Uint; // https://github.com/ethereum/execution-apis/blob/main/src/eth/filter.yaml eth_newFilter: (filter: Filter) => Uint;