diff --git a/packages/web3-core/CHANGELOG.md b/packages/web3-core/CHANGELOG.md index c07e7d02cd1..2c782c67f4d 100644 --- a/packages/web3-core/CHANGELOG.md +++ b/packages/web3-core/CHANGELOG.md @@ -202,3 +202,7 @@ Documentation: - Added `isMetaMaskProvider` function to check if provider is metamask (#6534) ## [Unreleased] + +### Changed + +- Web3config `contractDataInputFill` has been defaulted to `data`, istead of `input`. (#6622) \ No newline at end of file diff --git a/packages/web3-core/src/web3_config.ts b/packages/web3-core/src/web3_config.ts index f6ac722bc0e..11e80a843b1 100644 --- a/packages/web3-core/src/web3_config.ts +++ b/packages/web3-core/src/web3_config.ts @@ -79,7 +79,7 @@ export abstract class Web3Config transactionConfirmationPollingInterval: undefined, blockHeaderTimeout: 10, maxListenersWarningThreshold: 100, - contractDataInputFill: 'input', + contractDataInputFill: 'data', defaultNetworkId: undefined, defaultChain: 'mainnet', defaultHardfork: 'london', diff --git a/packages/web3-core/src/web3_request_manager.ts b/packages/web3-core/src/web3_request_manager.ts index 5fe063a7881..df12bc5b13d 100644 --- a/packages/web3-core/src/web3_request_manager.ts +++ b/packages/web3-core/src/web3_request_manager.ts @@ -42,7 +42,6 @@ import { Web3APISpec, Web3BaseProvider, Web3BaseProviderConstructor, - JsonRpcRequest } from 'web3-types'; import { isNullish, isPromise, jsonRpc, isResponseRpcError } from 'web3-utils'; import { @@ -51,7 +50,6 @@ import { isLegacySendAsyncProvider, isLegacySendProvider, isWeb3Provider, - isMetaMaskProvider, } from './utils.js'; import { Web3EventEmitter } from './web3_event_emitter.js'; @@ -68,24 +66,6 @@ const availableProviders: { WebsocketProvider: WSProvider as Web3BaseProviderConstructor, }; - -// if input was provided in params, change to data due to metamask only accepting data -const metamaskPayload = (payload: JsonRpcRequest) => { - - if(Array.isArray(payload.params)) { - const params = payload.params[0] as Record - if (params.input && !params.data) { - - return {...payload, - params: [{...params, - data: params.data ?? params.input}] - } - } -} -return payload; - -} - export class Web3RequestManager< API extends Web3APISpec = EthExecutionAPI, > extends Web3EventEmitter<{ @@ -208,20 +188,10 @@ export class Web3RequestManager< ); } - let payload = jsonRpc.isBatchRequest(request) - ? jsonRpc.toBatchPayload(request) + const payload = jsonRpc.isBatchRequest(request) + ? jsonRpc.toBatchPayload(request) : jsonRpc.toPayload(request); - if(isMetaMaskProvider(provider)){ // metamask send_transaction accepts data and not input, so we change it - if ((payload as JsonRpcRequest).method === 'eth_sendTransaction'){ - if(!jsonRpc.isBatchRequest(payload)){ - payload = metamaskPayload(payload as JsonRpcRequest) - } else { - payload = payload.map(p => metamaskPayload(p as JsonRpcRequest)) - } - } - } - if (isWeb3Provider(provider)) { let response; diff --git a/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap b/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap index bcfd03001aa..e6299f6d583 100644 --- a/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap +++ b/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap @@ -5,7 +5,7 @@ Object { "accountProvider": undefined, "config": Object { "blockHeaderTimeout": 10, - "contractDataInputFill": "input", + "contractDataInputFill": "data", "defaultAccount": undefined, "defaultBlock": "latest", "defaultChain": "mainnet", diff --git a/packages/web3-core/test/unit/web3_config.test.ts b/packages/web3-core/test/unit/web3_config.test.ts index c5950117a03..121e5cb94cf 100644 --- a/packages/web3-core/test/unit/web3_config.test.ts +++ b/packages/web3-core/test/unit/web3_config.test.ts @@ -33,7 +33,7 @@ const defaultConfig = { useRpcCallSpecification: false, }, handleRevert: false, - contractDataInputFill: 'input', + contractDataInputFill: 'data', maxListenersWarningThreshold: 100, transactionBlockTimeout: 50, transactionConfirmationBlocks: 24, diff --git a/packages/web3-eth-contract/CHANGELOG.md b/packages/web3-eth-contract/CHANGELOG.md index dfc013c1d90..d34fa85d053 100644 --- a/packages/web3-eth-contract/CHANGELOG.md +++ b/packages/web3-eth-contract/CHANGELOG.md @@ -347,4 +347,8 @@ Documentation: - Will populate `data` for transactions in contract for metamask provider instead of `input` (#6534) -## [Unreleased] \ No newline at end of file +## [Unreleased] + +### Changed + +- `contractDataInputFill` has been defaulted to `data`, istead of `input`. (#6622) \ No newline at end of file diff --git a/packages/web3-eth-contract/test/unit/contract.test.ts b/packages/web3-eth-contract/test/unit/contract.test.ts index 173ac8a5e4e..bee7d90999c 100644 --- a/packages/web3-eth-contract/test/unit/contract.test.ts +++ b/packages/web3-eth-contract/test/unit/contract.test.ts @@ -313,9 +313,9 @@ describe('Contract', () => { .mockImplementation((_objInstance, _tx) => { const newContract = contract.clone(); newContract.options.address = deployedAddr; - expect(_tx.input).toBeDefined(); + expect(_tx.data).toBeDefined(); if ( - _tx.input === + _tx.data === '0xa41368620000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000548656c6c6f000000000000000000000000000000000000000000000000000000' ) { // eslint-disable-next-line @@ -330,7 +330,7 @@ describe('Contract', () => { const deployedContract = await contract .deploy({ - input: GreeterBytecode, + data: GreeterBytecode, arguments: ['My Greeting'], }) .send(sendOptions); @@ -340,7 +340,7 @@ describe('Contract', () => { spyTx.mockClear(); }); - it('send method on deployed contract should work using data', async () => { + it('send method on deployed contract should work using data (default)', async () => { const arg = 'Hello'; const contract = new Contract(GreeterAbi); sendOptions = { @@ -537,13 +537,13 @@ describe('Contract', () => { const spyEthCall = jest.spyOn(eth, 'call').mockImplementation((_objInstance, _tx) => { expect(_tx.to).toStrictEqual(deployedAddr); - expect(_tx.input).toBe('0xcfae3217'); + expect(_tx.data).toBe('0xcfae3217'); // eslint-disable-next-line @typescript-eslint/no-unsafe-return return Promise.resolve(encodedArg) as any; // contract class should decode encodedArg }); const deployedContract = await contract .deploy({ - input: GreeterBytecode, + data: GreeterBytecode, arguments: ['My Greeting'], }) .send(sendOptions); @@ -759,7 +759,7 @@ describe('Contract', () => { // @ts-expect-error fix-types const spyEthCall = jest.spyOn(eth, 'call').mockImplementation((_objInstance, _tx) => { expect(_tx.to).toBe('0x1230B93ffd14F2F022039675fA3fc3A46eE4C701'); - expect(_tx.input).toBe( + expect(_tx.data).toBe( '0x095ea7b300000000000000000000000000000000219ab540356cbb839cbe05303d7705fa0000000000000000000000000000000000000000000000000000000000000001', ); return '0x00'; @@ -1449,7 +1449,7 @@ describe('Contract', () => { .spyOn(eth, 'createAccessList') .mockImplementation((_objInstance, _tx) => { expect(_tx.to).toStrictEqual(deployedAddr); - expect(_tx.input).toBe('0xcfae3217'); + expect(_tx.data).toBe('0xcfae3217'); expect(_tx.from).toBe(fromAddr); // eslint-disable-next-line @typescript-eslint/no-unsafe-return return Promise.resolve(result) as any; // contract class should decode encodedArg diff --git a/packages/web3/test/unit/web3.config.test.ts b/packages/web3/test/unit/web3.config.test.ts index dc7217dff7d..dbe6682c391 100644 --- a/packages/web3/test/unit/web3.config.test.ts +++ b/packages/web3/test/unit/web3.config.test.ts @@ -47,9 +47,9 @@ describe('web3config web3 tests', () => { expect(contract.getContextObject().config.contractDataInputFill).toBe("both"); // web3 config shouldn't change - expect(web3.getContextObject().config.contractDataInputFill).toBe("input"); - expect(web3.config.contractDataInputFill).toBe("input"); - expect(web3.eth.getContextObject().config.contractDataInputFill).toBe("input") + expect(web3.getContextObject().config.contractDataInputFill).toBe("data"); + expect(web3.config.contractDataInputFill).toBe("data"); + expect(web3.eth.getContextObject().config.contractDataInputFill).toBe("data") }); it('should change web3 config context but not contract config context', async () => { const web3 = new Web3("http://127.0.0.1:8545"); diff --git a/tools/web3-plugin-example/test/unit/contract_method_wrappers.test.ts b/tools/web3-plugin-example/test/unit/contract_method_wrappers.test.ts index 0f79df21e49..aae3ba16310 100644 --- a/tools/web3-plugin-example/test/unit/contract_method_wrappers.test.ts +++ b/tools/web3-plugin-example/test/unit/contract_method_wrappers.test.ts @@ -72,7 +72,7 @@ describe('ContractMethodWrappersPlugin', () => { method: 'eth_call', params: [ expect.objectContaining({ - input: '0x70a082310000000000000000000000008da5e39ec14b57fb9bcd9aa2b4500e909119795d', + data: '0x70a082310000000000000000000000008da5e39ec14b57fb9bcd9aa2b4500e909119795d', to: '0xdAC17F958D2ee523a2206206994597C13D831ec7', }), 'latest', @@ -106,7 +106,7 @@ describe('ContractMethodWrappersPlugin', () => { method: 'eth_sendTransaction', params: [ expect.objectContaining({ - input: '0xa9059cbb0000000000000000000000004f641def1e7845caab95ac717c80416082430d0d000000000000000000000000000000000000000000000000000000000000002a', + data: '0xa9059cbb0000000000000000000000004f641def1e7845caab95ac717c80416082430d0d000000000000000000000000000000000000000000000000000000000000002a', from: sender, gasPrice: expectedGasPrice, maxFeePerGas: undefined,