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

Commit b3ccd5c

Browse files
author
Alex
authored
change default to data (#6622)
* change default to data * fix config tests * fix test * address feedback and update changelog
1 parent e6d8c14 commit b3ccd5c

File tree

9 files changed

+27
-49
lines changed

9 files changed

+27
-49
lines changed

packages/web3-core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,7 @@ Documentation:
202202
- Added `isMetaMaskProvider` function to check if provider is metamask (#6534)
203203

204204
## [Unreleased]
205+
206+
### Changed
207+
208+
- Web3config `contractDataInputFill` has been defaulted to `data`, istead of `input`. (#6622)

packages/web3-core/src/web3_config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export abstract class Web3Config
7979
transactionConfirmationPollingInterval: undefined,
8080
blockHeaderTimeout: 10,
8181
maxListenersWarningThreshold: 100,
82-
contractDataInputFill: 'input',
82+
contractDataInputFill: 'data',
8383
defaultNetworkId: undefined,
8484
defaultChain: 'mainnet',
8585
defaultHardfork: 'london',

packages/web3-core/src/web3_request_manager.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import {
4242
Web3APISpec,
4343
Web3BaseProvider,
4444
Web3BaseProviderConstructor,
45-
JsonRpcRequest
4645
} from 'web3-types';
4746
import { isNullish, isPromise, jsonRpc, isResponseRpcError } from 'web3-utils';
4847
import {
@@ -51,7 +50,6 @@ import {
5150
isLegacySendAsyncProvider,
5251
isLegacySendProvider,
5352
isWeb3Provider,
54-
isMetaMaskProvider,
5553
} from './utils.js';
5654
import { Web3EventEmitter } from './web3_event_emitter.js';
5755

@@ -68,24 +66,6 @@ const availableProviders: {
6866
WebsocketProvider: WSProvider as Web3BaseProviderConstructor,
6967
};
7068

71-
72-
// if input was provided in params, change to data due to metamask only accepting data
73-
const metamaskPayload = (payload: JsonRpcRequest) => {
74-
75-
if(Array.isArray(payload.params)) {
76-
const params = payload.params[0] as Record<string, unknown>
77-
if (params.input && !params.data) {
78-
79-
return {...payload,
80-
params: [{...params,
81-
data: params.data ?? params.input}]
82-
}
83-
}
84-
}
85-
return payload;
86-
87-
}
88-
8969
export class Web3RequestManager<
9070
API extends Web3APISpec = EthExecutionAPI,
9171
> extends Web3EventEmitter<{
@@ -208,20 +188,10 @@ export class Web3RequestManager<
208188
);
209189
}
210190

211-
let payload = jsonRpc.isBatchRequest(request)
212-
? jsonRpc.toBatchPayload(request)
191+
const payload = jsonRpc.isBatchRequest(request)
192+
? jsonRpc.toBatchPayload(request)
213193
: jsonRpc.toPayload(request);
214194

215-
if(isMetaMaskProvider(provider)){ // metamask send_transaction accepts data and not input, so we change it
216-
if ((payload as JsonRpcRequest<ResponseType>).method === 'eth_sendTransaction'){
217-
if(!jsonRpc.isBatchRequest(payload)){
218-
payload = metamaskPayload(payload as JsonRpcRequest)
219-
} else {
220-
payload = payload.map(p => metamaskPayload(p as JsonRpcRequest))
221-
}
222-
}
223-
}
224-
225195
if (isWeb3Provider(provider)) {
226196
let response;
227197

packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Object {
55
"accountProvider": undefined,
66
"config": Object {
77
"blockHeaderTimeout": 10,
8-
"contractDataInputFill": "input",
8+
"contractDataInputFill": "data",
99
"defaultAccount": undefined,
1010
"defaultBlock": "latest",
1111
"defaultChain": "mainnet",

packages/web3-core/test/unit/web3_config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const defaultConfig = {
3333
useRpcCallSpecification: false,
3434
},
3535
handleRevert: false,
36-
contractDataInputFill: 'input',
36+
contractDataInputFill: 'data',
3737
maxListenersWarningThreshold: 100,
3838
transactionBlockTimeout: 50,
3939
transactionConfirmationBlocks: 24,

packages/web3-eth-contract/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,8 @@ Documentation:
347347

348348
- Will populate `data` for transactions in contract for metamask provider instead of `input` (#6534)
349349

350-
## [Unreleased]
350+
## [Unreleased]
351+
352+
### Changed
353+
354+
- `contractDataInputFill` has been defaulted to `data`, istead of `input`. (#6622)

packages/web3-eth-contract/test/unit/contract.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ describe('Contract', () => {
313313
.mockImplementation((_objInstance, _tx) => {
314314
const newContract = contract.clone();
315315
newContract.options.address = deployedAddr;
316-
expect(_tx.input).toBeDefined();
316+
expect(_tx.data).toBeDefined();
317317
if (
318-
_tx.input ===
318+
_tx.data ===
319319
'0xa41368620000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000548656c6c6f000000000000000000000000000000000000000000000000000000'
320320
) {
321321
// eslint-disable-next-line
@@ -330,7 +330,7 @@ describe('Contract', () => {
330330

331331
const deployedContract = await contract
332332
.deploy({
333-
input: GreeterBytecode,
333+
data: GreeterBytecode,
334334
arguments: ['My Greeting'],
335335
})
336336
.send(sendOptions);
@@ -340,7 +340,7 @@ describe('Contract', () => {
340340
spyTx.mockClear();
341341
});
342342

343-
it('send method on deployed contract should work using data', async () => {
343+
it('send method on deployed contract should work using data (default)', async () => {
344344
const arg = 'Hello';
345345
const contract = new Contract(GreeterAbi);
346346
sendOptions = {
@@ -537,13 +537,13 @@ describe('Contract', () => {
537537

538538
const spyEthCall = jest.spyOn(eth, 'call').mockImplementation((_objInstance, _tx) => {
539539
expect(_tx.to).toStrictEqual(deployedAddr);
540-
expect(_tx.input).toBe('0xcfae3217');
540+
expect(_tx.data).toBe('0xcfae3217');
541541
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
542542
return Promise.resolve(encodedArg) as any; // contract class should decode encodedArg
543543
});
544544
const deployedContract = await contract
545545
.deploy({
546-
input: GreeterBytecode,
546+
data: GreeterBytecode,
547547
arguments: ['My Greeting'],
548548
})
549549
.send(sendOptions);
@@ -759,7 +759,7 @@ describe('Contract', () => {
759759
// @ts-expect-error fix-types
760760
const spyEthCall = jest.spyOn(eth, 'call').mockImplementation((_objInstance, _tx) => {
761761
expect(_tx.to).toBe('0x1230B93ffd14F2F022039675fA3fc3A46eE4C701');
762-
expect(_tx.input).toBe(
762+
expect(_tx.data).toBe(
763763
'0x095ea7b300000000000000000000000000000000219ab540356cbb839cbe05303d7705fa0000000000000000000000000000000000000000000000000000000000000001',
764764
);
765765
return '0x00';
@@ -1449,7 +1449,7 @@ describe('Contract', () => {
14491449
.spyOn(eth, 'createAccessList')
14501450
.mockImplementation((_objInstance, _tx) => {
14511451
expect(_tx.to).toStrictEqual(deployedAddr);
1452-
expect(_tx.input).toBe('0xcfae3217');
1452+
expect(_tx.data).toBe('0xcfae3217');
14531453
expect(_tx.from).toBe(fromAddr);
14541454
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
14551455
return Promise.resolve(result) as any; // contract class should decode encodedArg

packages/web3/test/unit/web3.config.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ describe('web3config web3 tests', () => {
4747
expect(contract.getContextObject().config.contractDataInputFill).toBe("both");
4848

4949
// web3 config shouldn't change
50-
expect(web3.getContextObject().config.contractDataInputFill).toBe("input");
51-
expect(web3.config.contractDataInputFill).toBe("input");
52-
expect(web3.eth.getContextObject().config.contractDataInputFill).toBe("input")
50+
expect(web3.getContextObject().config.contractDataInputFill).toBe("data");
51+
expect(web3.config.contractDataInputFill).toBe("data");
52+
expect(web3.eth.getContextObject().config.contractDataInputFill).toBe("data")
5353
});
5454
it('should change web3 config context but not contract config context', async () => {
5555
const web3 = new Web3("http://127.0.0.1:8545");

tools/web3-plugin-example/test/unit/contract_method_wrappers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('ContractMethodWrappersPlugin', () => {
7272
method: 'eth_call',
7373
params: [
7474
expect.objectContaining({
75-
input: '0x70a082310000000000000000000000008da5e39ec14b57fb9bcd9aa2b4500e909119795d',
75+
data: '0x70a082310000000000000000000000008da5e39ec14b57fb9bcd9aa2b4500e909119795d',
7676
to: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
7777
}),
7878
'latest',
@@ -106,7 +106,7 @@ describe('ContractMethodWrappersPlugin', () => {
106106
method: 'eth_sendTransaction',
107107
params: [
108108
expect.objectContaining({
109-
input: '0xa9059cbb0000000000000000000000004f641def1e7845caab95ac717c80416082430d0d000000000000000000000000000000000000000000000000000000000000002a',
109+
data: '0xa9059cbb0000000000000000000000004f641def1e7845caab95ac717c80416082430d0d000000000000000000000000000000000000000000000000000000000000002a',
110110
from: sender,
111111
gasPrice: expectedGasPrice,
112112
maxFeePerGas: undefined,

0 commit comments

Comments
 (0)