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

Add types for user input in send/call #5960

Merged
merged 39 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
29a3e12
Add types for user input in send/call
nikoulai Mar 27, 2023
93f05cf
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
nikoulai Mar 27, 2023
021f6de
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
spacesailor24 Mar 28, 2023
e65fc1b
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
Muhammad-Altabba Apr 3, 2023
45591ea
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
Muhammad-Altabba Apr 3, 2023
205d4ac
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
nikoulai Apr 4, 2023
061bf24
Revert types
nikoulai Apr 4, 2023
f817f32
remove chainId, to, data & input from NonPayableCallOptions
nikoulai Apr 4, 2023
c78160d
Merge branch 'nikos/5945/inocrrect-type-for-options' of https://githu…
nikoulai Apr 4, 2023
ad0dcb3
Remove input from deployOptions
nikoulai Apr 4, 2023
0d30e8b
Fix createAccessListType
nikoulai Apr 4, 2023
180761a
Fix createAccessListType payable and estimateGas
nikoulai Apr 4, 2023
3505d9b
Fix send and call
nikoulai Apr 4, 2023
4f0e50a
Modify test
nikoulai Apr 4, 2023
488e9c5
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
nikoulai Apr 5, 2023
971e0f5
Remove unused types from NonPayableCallOptions
nikoulai Apr 5, 2023
87c4b30
Allow type in estimateGas
nikoulai Apr 5, 2023
675cd00
Revert deploy test
nikoulai Apr 5, 2023
6f0aa73
Fix contract test
nikoulai Apr 6, 2023
b1ae75d
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
avkos Apr 10, 2023
e43d526
Apply changes to docs
nikoulai Apr 11, 2023
7fb6fa8
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
jdevcs Apr 12, 2023
c1372dc
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
nikoulai Apr 20, 2023
53355bb
Delete properties again after merge
nikoulai Apr 20, 2023
c051bc0
Merge branch 'nikos/5945/inocrrect-type-for-options' of https://githu…
nikoulai Apr 20, 2023
b7cb424
Update changelog
nikoulai Apr 20, 2023
234501f
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
nikoulai Apr 20, 2023
3b7e8c1
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
nikoulai Apr 20, 2023
9f0a760
Address feedback for types
nikoulai Apr 20, 2023
71ac77e
Undo delete to property
nikoulai Apr 20, 2023
88c956c
Allow input for contract deployment
nikoulai Apr 20, 2023
e24754a
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
nikoulai Apr 20, 2023
b44d5dc
Remove delete to
nikoulai Apr 20, 2023
f8004c0
Fix types
nikoulai Apr 21, 2023
7240e5c
Address feedback
nikoulai Apr 21, 2023
a243767
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
nikoulai Apr 21, 2023
33ddd5f
Remove unecessary file
nikoulai Apr 24, 2023
0697462
Merge branch 'nikos/5945/inocrrect-type-for-options' of https://githu…
nikoulai Apr 24, 2023
f6e0fa0
Merge branch '4.x' into nikos/5945/inocrrect-type-for-options
spacesailor24 Apr 25, 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
2 changes: 1 addition & 1 deletion docs/docs/guides/sign_and_send_tx/wallet_of_eth_node.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ try {
const contract = new web3.eth.Contract(ContractAbi);
const contractDeployed = await contract
.deploy({
input: ContractBytecode,
data: ContractBytecode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data: ContractBytecode,
input: ContractBytecode,

Since input is the correct term

arguments: ['Constructor param1', 'Constructor param2'],
})
.send({
Expand Down
9 changes: 1 addition & 8 deletions packages/web3-eth-contract/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ export class Contract<Abi extends ContractAbi>
*
* ```ts
* myContract.deploy({
* input: '0x12345...',
* input: '0x12345...', //data keyword can be used, too. But if input is used, data will be ignored.
* arguments: [123, 'My String']
* })
* .send({
Expand Down Expand Up @@ -603,10 +603,6 @@ export class Contract<Abi extends ContractAbi>
> => {
const modifiedOptions = { ...options };

// Remove to address
// modifiedOptions.to = '0x0000000000000000000000000000000000000000';
delete modifiedOptions.to;

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return this._contractMethodDeploySend(
abi as AbiFunctionFragment,
Expand All @@ -621,9 +617,6 @@ export class Contract<Abi extends ContractAbi>
) => {
const modifiedOptions = { ...options };

// Remove to address
delete modifiedOptions.to;

return this._contractMethodEstimateGas({
abi: abi as AbiFunctionFragment,
params: args as unknown[],
Expand Down
14 changes: 7 additions & 7 deletions packages/web3-eth-contract/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export interface NonPayableMethodObject<Inputs = unknown[], Outputs = unknown[]>
* @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized can also be used. Useful for requesting data from or replaying transactions in past blocks.
* @returns The returned data of the createAccessList, e.g. The generated access list for transaction.
*
* ```ts
* ```ts
* const result = await MyContract.methods.myFunction().createAccessList();
* console.log(result);
*
Expand All @@ -319,7 +319,7 @@ export interface NonPayableMethodObject<Inputs = unknown[], Outputs = unknown[]>
* ],
* "gasUsed": "0x7671"
* }
* ```
* ```
*/
createAccessList(
tx?: NonPayableCallOptions,
Expand Down Expand Up @@ -376,7 +376,7 @@ export interface PayableMethodObject<Inputs = unknown[], Outputs = unknown[]> {
* @returns - The return value(s) of the smart contract method. If it returns a single value, it’s returned as is. If it has multiple return values they are returned as an object with properties and indices.
*/
call<SpecialOutput = Outputs>(
tx?: PayableCallOptions,
tx?: Omit<PayableCallOptions, 'nonce'>,
block?: BlockNumberOrTag,
): Promise<SpecialOutput>;

Expand Down Expand Up @@ -470,7 +470,7 @@ export interface PayableMethodObject<Inputs = unknown[], Outputs = unknown[]> {
* @returns - The gas amount estimated.
*/
estimateGas<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
options?: PayableCallOptions,
options?: Omit<PayableCallOptions, 'nonce'>,
returnFormat?: ReturnFormat,
): Promise<FormatType<Numbers, ReturnFormat>>;

Expand All @@ -493,7 +493,7 @@ export interface PayableMethodObject<Inputs = unknown[], Outputs = unknown[]> {
* @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized can also be used. Useful for requesting data from or replaying transactions in past blocks.
* @returns The returned data of the createAccessList, e.g. The generated access list for transaction.
*
* ```ts
* ```ts
* const result = await MyContract.methods.myFunction().createAccessList();
* console.log(result);
*
Expand All @@ -508,10 +508,10 @@ export interface PayableMethodObject<Inputs = unknown[], Outputs = unknown[]> {
* ],
* "gasUsed": "0x7671"
* }
* ```
*```
*/
createAccessList(
tx?: NonPayableCallOptions,
tx?: Omit<PayableCallOptions, 'nonce' | 'type'>,
block?: BlockNumberOrTag,
): Promise<AccessListResult>;
}
Expand Down
11 changes: 8 additions & 3 deletions packages/web3-eth-contract/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
TransactionWithSenderAPI,
TransactionCall,
HexString,
Address,
NonPayableCallOptions,
PayableCallOptions,
ContractInitOptions,
Expand All @@ -38,7 +39,11 @@ export const getSendTxParams = ({
}: {
abi: AbiFunctionFragment;
params: unknown[];
options?: PayableCallOptions | NonPayableCallOptions;
options?: (PayableCallOptions | NonPayableCallOptions) & {
input?: HexString;
data?: HexString;
to?: Address;
};
contractOptions: ContractOptions;
}): TransactionCall => {
const deploymentCall = options?.input ?? options?.data ?? contractOptions.input;
Expand Down Expand Up @@ -80,7 +85,7 @@ export const getEthTxCallParams = ({
}: {
abi: AbiFunctionFragment;
params: unknown[];
options?: PayableCallOptions | NonPayableCallOptions;
options?: (PayableCallOptions | NonPayableCallOptions) & { to?: Address };
contractOptions: ContractOptions;
}): TransactionCall => {
if (!options?.to && !contractOptions.address) {
Expand Down Expand Up @@ -162,7 +167,7 @@ export const getCreateAccessListParams = ({
}: {
abi: AbiFunctionFragment;
params: unknown[];
options?: PayableCallOptions | NonPayableCallOptions;
options?: (PayableCallOptions | NonPayableCallOptions) & { to?: Address };
contractOptions: ContractOptions;
}): TransactionForAccessList => {
if (!options?.to && !contractOptions.address) {
Expand Down
Loading