Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gas and input instead of gasLimit and data #5915

Merged
merged 33 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d5db302
decodeSignedTransaction will now return gas instead of gasLimit when …
spacesailor24 Mar 11, 2023
aa54b7c
getEthereumJsTxDataFromTransaction will use gas property if gasLimit …
spacesailor24 Mar 11, 2023
9075607
Revert changes to decodeSignedTransaction in favor of refactor format…
spacesailor24 Mar 11, 2023
19ee02a
Update CHANGELOGs
spacesailor24 Mar 11, 2023
13cd852
Merge branch '4.x' into wyatt/4.x/5387-gaslimit-refactor
spacesailor24 Mar 15, 2023
a4535b5
Remove gasLimit from MissingGasError and TransactionGasMismatchError
spacesailor24 Mar 15, 2023
5adb6e7
Update formatTransaction to intake an optional transactionSchema so i…
spacesailor24 Mar 15, 2023
a2ed69f
Merge branch '4.x' into wyatt/4.x/5387-gaslimit-refactor
spacesailor24 Mar 15, 2023
5bba84a
Update formatTransaction to replace data with input
spacesailor24 Mar 15, 2023
f8ba84a
Update plugin tests to use input instead of data
spacesailor24 Mar 16, 2023
d53128e
Update sign_transaction to use input for expected sent tx obj
spacesailor24 Mar 16, 2023
69fbe3f
Update PopulatedUnsignedBaseTransaction to use input instead of data
spacesailor24 Mar 17, 2023
5c69557
Update getEthereumjsTxDataFromTransaction to get transaction.input
spacesailor24 Mar 17, 2023
4914397
Fix incorrect nonce in sign_transaction test
spacesailor24 Mar 17, 2023
d0efdbb
Update defaultTransactionBuilder to use replace data with input
spacesailor24 Mar 17, 2023
0d69f7f
Update test data for prepare_transaction_for_signing
spacesailor24 Mar 17, 2023
f1ba0b6
Update Contract to allow for use of input in place of data
spacesailor24 Mar 18, 2023
3fc3387
Merge branch '4.x' into wyatt/4.x/5387-gaslimit-refactor
spacesailor24 Mar 18, 2023
588dcf6
Fix test for cypress
spacesailor24 Mar 18, 2023
06b520b
Merge branch 'wyatt/4.x/5387-gaslimit-refactor' of github.com:web3/we…
spacesailor24 Mar 18, 2023
509d35f
Merge branch '4.x' into wyatt/4.x/5387-gaslimit-refactor
jdevcs Mar 20, 2023
429232f
Update CHANGELOGs
spacesailor24 Mar 21, 2023
26a66f1
Merge branch 'wyatt/4.x/5387-gaslimit-refactor' of github.com:web3/we…
spacesailor24 Mar 21, 2023
9ba4771
Add input to isContractInitOptions check
spacesailor24 Mar 21, 2023
e43d17e
CHANGELOG formatting
spacesailor24 Mar 21, 2023
90e708a
Add default_transaction_builder test for input prefix
spacesailor24 Mar 21, 2023
9682a21
Merge branch '4.x' into wyatt/4.x/5387-gaslimit-refactor
spacesailor24 Mar 21, 2023
41add7e
Merge branch '4.x' into wyatt/4.x/5387-gaslimit-refactor
spacesailor24 Mar 22, 2023
b357b29
Init ContractTransactionDataAndInputError
spacesailor24 Mar 23, 2023
37aa7b3
Remove data and gasLimit from ContractOptions type
spacesailor24 Mar 23, 2023
59650e5
Remove contractOptions.data from ternaries in contract util methods
spacesailor24 Mar 23, 2023
5cdfd60
Add ContractTransactionDataAndInputError check in Contract constructor
spacesailor24 Mar 23, 2023
f443211
Update CHANGELOGs
spacesailor24 Mar 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1291,3 +1291,34 @@ should use 4.0.1-alpha.0 for testing.
- Fixed getPastEventsError (#5819)

## [Unreleased]

### Changed

#### web3-core

- If a transaction object with a `data` property is passed to `txInputOptionsFormatter`, it will now be replaced with `input` (#5915)

#### web3-errors

- `gasLimit` is no longer accepted as a parameter for `MissingGasError` and `TransactionGasMismatchError`, and is also no longer included in error message (#5915)

#### web3-eth

- `signTransaction` will now return `gas` instead of `gasLimit` for returned transaction object regardless of what property name the provider uses (#5915)
- `formatTransaction` will now replace `data` transaction property with `input` (#5915)
- `isTransactionCall` will now check if `value.input` `isHexStrict` if provided (#5915)

#### web3-eth-contract

- `getSendTxParams` will now return `input` instead of `data` in returned transaction parameters object (#5915)

#### web3-types

- `data` property in `TransactionOutput` was renamed to `input` (#5915)

### Added

#### web3-eth-contract

- `input` is now an acceptable property for `ContractInitOptions` in place of `data` (either can be used, but `input` is used withing the
`Contract` class) (#5915)
4 changes: 4 additions & 0 deletions packages/web3-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support of `safe` and `finalized` block tags (#5823)

## [Unreleased]

### Changed

- If a transaction object with a `data` property is passed to `txInputOptionsFormatter`, it will now be replaced with `input` (#5915)
14 changes: 7 additions & 7 deletions packages/web3-core/src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,17 @@ export const txInputOptionsFormatter = (options: TransactionInput): Mutable<Tran
);
}

if (!options.data && options.input) {
modifiedOptions.data = options.input;
delete modifiedOptions.input;
if (!options.input && options.data) {
modifiedOptions.input = options.data;
delete modifiedOptions.data;
}

if (options.data && !options.data.startsWith('0x')) {
modifiedOptions.data = `0x${options.data}`;
if (options.input && !options.input.startsWith('0x')) {
modifiedOptions.input = `0x${options.input}`;
}

if (modifiedOptions.data && !isHexStrict(modifiedOptions.data)) {
throw new FormatterError('The data field must be HEX encoded data.');
if (modifiedOptions.input && !isHexStrict(modifiedOptions.input)) {
throw new FormatterError('The input field must be HEX encoded data.');
}

// allow both
Expand Down
20 changes: 10 additions & 10 deletions packages/web3-core/test/unit/formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,24 +189,24 @@ describe('formatters', () => {
);
});

it('should replace "data" with "input" if "input" is given and "data" is not', () => {
const result = txInputOptionsFormatter({ ...txInput, input: '0xff0011' });
it('should replace "input" with "data" if "data" is given and "input" is not', () => {
const result = txInputOptionsFormatter({ ...txInput, data: '0xff0011' });

expect(result).toEqual(expect.objectContaining({ data: '0xff0011' }));
expect(Object.keys(result)).not.toContain('input');
expect(result).toEqual(expect.objectContaining({ input: '0xff0011' }));
expect(Object.keys(result)).not.toContain('data');
});

it('should prefix "data" with "0x" if not already', () => {
expect(txInputOptionsFormatter({ ...txInput, data: 'ff0011' })).toEqual(
expect.objectContaining({ data: '0xff0011' }),
it('should prefix "input" with "0x" if not already', () => {
expect(txInputOptionsFormatter({ ...txInput, input: 'ff0011' })).toEqual(
expect.objectContaining({ input: '0xff0011' }),
);
});

it('should throw error if "data" is not a valid hex string', () => {
it('should throw error if "input" is not a valid hex string', () => {
jest.spyOn(utils, 'isHexStrict').mockReturnValue(false);

expect(() => txInputOptionsFormatter({ ...txInput, data: 'ff0011' })).toThrow(
'The data field must be HEX encoded data.',
expect(() => txInputOptionsFormatter({ ...txInput, input: 'ff0011' })).toThrow(
'The input field must be HEX encoded data.',
);
expect(utils.isHexStrict).toHaveBeenCalledWith('0xff0011');
});
Expand Down
4 changes: 4 additions & 0 deletions packages/web3-errors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `TransactionRevertWithCustomError` was added to handle custom solidity errors (#5854)

## [Unreleased]

### Changed

- `gasLimit` is no longer accepted as a parameter for `MissingGasError` and `TransactionGasMismatchError, and is also no longer included in error message (#5915)
22 changes: 10 additions & 12 deletions packages/web3-errors/src/errors/transaction_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,16 @@ export class MissingGasError extends InvalidValueError {

public constructor(value: {
gas: Numbers | undefined;
gasLimit: Numbers | undefined;
gasPrice: Numbers | undefined;
maxPriorityFeePerGas: Numbers | undefined;
maxFeePerGas: Numbers | undefined;
}) {
super(
`gas: ${value.gas ?? 'undefined'}, gasLimit: ${
value.gasLimit ?? 'undefined'
}, gasPrice: ${value.gasPrice ?? 'undefined'}, maxPriorityFeePerGas: ${
value.maxPriorityFeePerGas ?? 'undefined'
}, maxFeePerGas: ${value.maxFeePerGas ?? 'undefined'}`,
`gas: ${value.gas ?? 'undefined'}, gasPrice: ${
value.gasPrice ?? 'undefined'
}, maxPriorityFeePerGas: ${value.maxPriorityFeePerGas ?? 'undefined'}, maxFeePerGas: ${
value.maxFeePerGas ?? 'undefined'
}`,
'"gas" is missing',
);
}
Expand All @@ -331,17 +330,16 @@ export class TransactionGasMismatchError extends InvalidValueError {

public constructor(value: {
gas: Numbers | undefined;
gasLimit: Numbers | undefined;
gasPrice: Numbers | undefined;
maxPriorityFeePerGas: Numbers | undefined;
maxFeePerGas: Numbers | undefined;
}) {
super(
`gas: ${value.gas ?? 'undefined'}, gasLimit: ${
value.gasLimit ?? 'undefined'
}, gasPrice: ${value.gasPrice ?? 'undefined'}, maxPriorityFeePerGas: ${
value.maxPriorityFeePerGas ?? 'undefined'
}, maxFeePerGas: ${value.maxFeePerGas ?? 'undefined'}`,
`gas: ${value.gas ?? 'undefined'}, gasPrice: ${
value.gasPrice ?? 'undefined'
}, maxPriorityFeePerGas: ${value.maxPriorityFeePerGas ?? 'undefined'}, maxFeePerGas: ${
value.maxFeePerGas ?? 'undefined'
}`,
'transaction must specify legacy or fee market gas properties, not both',
);
}
Expand Down
9 changes: 9 additions & 0 deletions packages/web3-eth-contract/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,12 @@ const transactionHash = receipt.transactionHash;
- `decodeErrorData` is no longer exported (method was moved to `web3-eth-abi` and renamed `decodeContractErrorData`) (#5844)

## [Unreleased]

### Added

- `input` is now an acceptable property for `ContractInitOptions` in place of `data` (either can be used, but `input` is used withing the
`Contract` class) (#5915)

### Changed

- `getSendTxParams` will now return `input` instead of `data` in returned transaction parameters object (#5915)
10 changes: 6 additions & 4 deletions packages/web3-eth-contract/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export class Contract<Abi extends ContractAbi>
gasPrice: options?.gasPrice,
gasLimit: options?.gasLimit,
from: options?.from,
data: options?.data,
input: options?.data ?? options?.input,
};

this.syncWithContext = (options as ContractInitOptions)?.syncWithContext ?? false;
Expand Down Expand Up @@ -467,7 +467,7 @@ export class Contract<Abi extends ContractAbi>
gasPrice: this.options.gasPrice,
gasLimit: this.options.gasLimit,
from: this.options.from,
data: this.options.data,
input: this.options.input,
provider: this.currentProvider,
syncWithContext: this.syncWithContext,
},
Expand All @@ -481,7 +481,7 @@ export class Contract<Abi extends ContractAbi>
gasPrice: this.options.gasPrice,
gasLimit: this.options.gasLimit,
from: this.options.from,
data: this.options.data,
input: this.options.input,
provider: this.currentProvider,
syncWithContext: this.syncWithContext,
},
Expand Down Expand Up @@ -559,6 +559,7 @@ export class Contract<Abi extends ContractAbi>
* The byte code of the contract.
*/
data?: HexString;
input?: HexString;
/**
* The arguments which get passed to the constructor on deployment.
*/
Expand All @@ -576,7 +577,7 @@ export class Contract<Abi extends ContractAbi>

const data = format(
{ eth: 'bytes' },
deployOptions?.data ?? this.options.data,
deployOptions?.data ?? deployOptions?.input ?? this.options.input,
DEFAULT_RETURN_FORMAT,
);

Expand Down Expand Up @@ -1041,6 +1042,7 @@ export class Contract<Abi extends ContractAbi>
modifiedContractOptions = {
...modifiedContractOptions,
data: undefined,
input: undefined,
from: modifiedContractOptions.from ?? this.defaultAccount ?? undefined,
};

Expand Down
3 changes: 3 additions & 0 deletions packages/web3-eth-contract/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface ContractOptions {
* The byte code of the contract. Used when the contract gets {@link Contract.deploy | deployed}
*/
readonly data?: Bytes;
readonly input?: Bytes;
/**
* The {@doclink glossary/json_interface | json interface} object derived from the [ABI](https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI) of this contract.
*
Expand Down Expand Up @@ -150,6 +151,7 @@ export interface ContractInitOptions {
* The byte code of the contract. Used when the contract gets {@link Contract.deploy | deployed}
*/
readonly data?: Bytes;
readonly input?: Bytes;
readonly gasLimit?: Uint;
readonly provider?: SupportedProviders<EthExecutionAPI> | string;
/**
Expand All @@ -168,6 +170,7 @@ export interface NonPayableCallOptions {
from?: Address;
to?: Address;
data?: HexString;
input?: HexString;
/**
* The maximum gas provided for this call “transaction” (gas limit)
*/
Expand Down
24 changes: 13 additions & 11 deletions packages/web3-eth-contract/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export const getSendTxParams = ({
options?: PayableCallOptions | NonPayableCallOptions;
contractOptions: ContractOptions;
}): TransactionCall => {
const deploymentCall = options?.data ?? contractOptions.data;
const deploymentCall =
options?.data ?? options?.input ?? contractOptions.data ?? contractOptions.input;

if (!deploymentCall && !options?.to && !contractOptions.address) {
throw new Web3ContractError('Contract address not specified');
Expand All @@ -60,15 +61,15 @@ export const getSendTxParams = ({
gas: contractOptions.gas,
gasPrice: contractOptions.gasPrice,
from: contractOptions.from,
data: contractOptions.data,
input: contractOptions.data ?? contractOptions.input,
},
options as unknown as Record<string, unknown>,
) as unknown as TransactionCall;

if (!txParams.data || abi.type === 'constructor') {
if (!txParams.input || abi.type === 'constructor') {
txParams = {
...txParams,
data: encodeMethodABI(abi, params, txParams.data as HexString),
input: encodeMethodABI(abi, params, txParams.input as HexString),
};
}

Expand Down Expand Up @@ -96,14 +97,14 @@ export const getEthTxCallParams = ({
gas: contractOptions.gas,
gasPrice: contractOptions.gasPrice,
from: contractOptions.from,
data: contractOptions.data,
input: contractOptions.data ?? contractOptions.input,
},
options as unknown as Record<string, unknown>,
) as unknown as TransactionCall;

txParams = {
...txParams,
data: encodeMethodABI(abi, params, txParams.data ? toHex(txParams.data) : undefined),
input: encodeMethodABI(abi, params, txParams.input ? toHex(txParams.input) : undefined),
};

return txParams;
Expand All @@ -126,14 +127,14 @@ export const getEstimateGasParams = ({
gas: contractOptions.gas,
gasPrice: contractOptions.gasPrice,
from: contractOptions.from,
data: contractOptions.data,
input: contractOptions.data ?? contractOptions.input,
},
options as unknown as Record<string, unknown>,
) as unknown as TransactionCall;

txParams = {
...txParams,
data: encodeMethodABI(abi, params, txParams.data ? toHex(txParams.data) : undefined),
input: encodeMethodABI(abi, params, txParams.input ? toHex(txParams.input) : undefined),
};

return txParams as TransactionWithSenderAPI;
Expand All @@ -143,6 +144,7 @@ export const isContractInitOptions = (options: unknown): options is ContractInit
typeof options === 'object' &&
!isNullish(options) &&
[
'input',
'data',
'from',
'gas',
Expand Down Expand Up @@ -181,15 +183,15 @@ export const getCreateAccessListParams = ({
gas: contractOptions.gas,
gasPrice: contractOptions.gasPrice,
from: contractOptions.from,
data: contractOptions.data,
input: contractOptions.data ?? contractOptions.input,
},
options as unknown as Record<string, unknown>,
) as unknown as TransactionForAccessList;

if (!txParams.data || abi.type === 'constructor') {
if (!txParams.input || abi.type === 'constructor') {
txParams = {
...txParams,
data: encodeMethodABI(abi, params, txParams.data as HexString),
input: encodeMethodABI(abi, params, txParams.input as HexString),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('contract', () => {
it('should run send method of the contract if data is provided at initiation', async () => {
const tempContract = new Contract(BasicAbi, {
provider: getSystemTestProvider(),
data: BasicBytecode,
input: BasicBytecode,
from: acc.address,
gas: '1000000',
});
Expand Down
Loading