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

Commit 2373e94

Browse files
authored
Result of contract method .send is hard to type (#6883)
* fix: Add videos to Plugin Section * add deploy and send types * lint fix * add types to web3 packcage * fix unit tests * test * test * test * revert * changelog
1 parent 16a2c27 commit 2373e94

File tree

5 files changed

+44
-13
lines changed

5 files changed

+44
-13
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2383,4 +2383,14 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
23832383

23842384
- replaced our eventEmitter to EventEmitter3 to support react native builds (#6253)
23852385

2386-
## [Unreleased]
2386+
## [Unreleased]
2387+
### Changed
2388+
2389+
#### web3
2390+
2391+
- Types `ContractDeploySend`, `ContractMethodSend`, `Web3PromiEvent` was exported (#6883)
2392+
2393+
### Added
2394+
2395+
#### web3-eth-contract
2396+

packages/web3-eth-contract/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,7 @@ Documentation:
365365
- Fixed: The Contract is not using the context wallet passed if context was passed at constructor. (#6661)
366366

367367
## [Unreleased]
368+
369+
### Added
370+
371+
- Types `ContractDeploySend`, `ContractMethodSend` was added (#6883)

packages/web3-eth-contract/src/contract.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,16 @@ import {
8282
EventLog,
8383
ContractAbiWithSignature,
8484
ContractOptions,
85+
TransactionReceipt,
86+
FormatType,
8587
} from 'web3-types';
86-
import { format, isDataFormat, keccak256, toChecksumAddress , isContractInitOptions } from 'web3-utils';
88+
import {
89+
format,
90+
isDataFormat,
91+
keccak256,
92+
toChecksumAddress,
93+
isContractInitOptions,
94+
} from 'web3-utils';
8795
import {
8896
isNullish,
8997
validator,
@@ -113,7 +121,7 @@ type ContractBoundMethod<
113121
Abi extends AbiFunctionFragment,
114122
Method extends ContractMethod<Abi> = ContractMethod<Abi>,
115123
> = (
116-
...args: Method['Inputs'] extends undefined|unknown ? any[] : Method['Inputs']
124+
...args: Method['Inputs'] extends undefined | unknown ? any[] : Method['Inputs']
117125
) => Method['Abi']['stateMutability'] extends 'payable' | 'pure'
118126
? PayableMethodObject<Method['Inputs'], Method['Outputs']>
119127
: NonPayableMethodObject<Method['Inputs'], Method['Outputs']>;
@@ -148,6 +156,16 @@ export type ContractMethodsInterface<Abi extends ContractAbi> = {
148156
// eslint-disable-next-line @typescript-eslint/no-explicit-any
149157
} & { [key: string]: ContractBoundMethod<any> };
150158

159+
export type ContractMethodSend = Web3PromiEvent<
160+
FormatType<TransactionReceipt, typeof DEFAULT_RETURN_FORMAT>,
161+
SendTransactionEvents<typeof DEFAULT_RETURN_FORMAT>
162+
>;
163+
export type ContractDeploySend<Abi extends ContractAbi> = Web3PromiEvent<
164+
// eslint-disable-next-line no-use-before-define
165+
Contract<Abi>,
166+
SendTransactionEvents<typeof DEFAULT_RETURN_FORMAT>
167+
>;
168+
151169
/**
152170
* @hidden
153171
* The event object can be accessed from `myContract.events.myEvent`.
@@ -768,12 +786,7 @@ export class Contract<Abi extends ContractAbi>
768786
const deployData = _input ?? _data;
769787
return {
770788
arguments: args,
771-
send: (
772-
options?: PayableTxOptions,
773-
): Web3PromiEvent<
774-
Contract<Abi>,
775-
SendTransactionEvents<typeof DEFAULT_RETURN_FORMAT>
776-
> => {
789+
send: (options?: PayableTxOptions): ContractDeploySend<Abi> => {
777790
const modifiedOptions = { ...options };
778791

779792
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
@@ -1101,7 +1114,7 @@ export class Contract<Abi extends ContractAbi>
11011114
block,
11021115
),
11031116

1104-
send: (options?: PayableTxOptions | NonPayableTxOptions) =>
1117+
send: (options?: PayableTxOptions | NonPayableTxOptions): ContractMethodSend =>
11051118
this._contractMethodSend(methodAbi, abiParams, internalErrorsAbis, options),
11061119

11071120
estimateGas: async <ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(

packages/web3/CHANGELOG.md

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

198198
- Added EIP-6963 utility function `requestEIP6963Providers` for multi provider discovery ( other details are in root changelog )
199199

200-
## [Unreleased]
200+
## [Unreleased]
201+
202+
### Changed
203+
204+
- Types `ContractDeploySend`, `ContractMethodSend`, `Web3PromiEvent` was exported (#6883)

packages/web3/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ export default Web3;
333333
* Named exports for all objects which are the default-exported-object in their packages
334334
*/
335335
export { Web3 };
336-
export { Web3Context, Web3PluginBase, Web3EthPluginBase } from 'web3-core';
336+
export { Web3Context, Web3PluginBase, Web3EthPluginBase, Web3PromiEvent } from 'web3-core';
337337
export { Web3Eth } from 'web3-eth';
338-
export { Contract } from 'web3-eth-contract';
338+
export { Contract, ContractDeploySend, ContractMethodSend } from 'web3-eth-contract';
339339
export { Iban } from 'web3-eth-iban';
340340
export { Personal } from 'web3-eth-personal';
341341
export { Net } from 'web3-net';

0 commit comments

Comments
 (0)