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

Result of contract method .send is hard to type #6883

Merged
merged 11 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,13 @@ jobs:
with:
architecture: x64
node-version: ${{ matrix.node }}
cache: yarn
- uses: actions/cache/restore@v3
with:
path: ./
key: web3-${{ matrix.node }}-${{github.sha}}
- run: yarn install --ignore-scripts
- run: yarn build:cjs
- run: yarn test:unit
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
31 changes: 22 additions & 9 deletions packages/web3-eth-contract/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,16 @@ import {
EventLog,
ContractAbiWithSignature,
ContractOptions,
TransactionReceipt,
FormatType,
} from 'web3-types';
import { format, isDataFormat, keccak256, toChecksumAddress , isContractInitOptions } from 'web3-utils';
import {
format,
isDataFormat,
keccak256,
toChecksumAddress,
isContractInitOptions,
} from 'web3-utils';
import {
isNullish,
validator,
Expand Down Expand Up @@ -113,7 +121,7 @@ type ContractBoundMethod<
Abi extends AbiFunctionFragment,
Method extends ContractMethod<Abi> = ContractMethod<Abi>,
> = (
...args: Method['Inputs'] extends undefined|unknown ? any[] : Method['Inputs']
...args: Method['Inputs'] extends undefined | unknown ? any[] : Method['Inputs']
) => Method['Abi']['stateMutability'] extends 'payable' | 'pure'
? PayableMethodObject<Method['Inputs'], Method['Outputs']>
: NonPayableMethodObject<Method['Inputs'], Method['Outputs']>;
Expand Down Expand Up @@ -148,6 +156,16 @@ export type ContractMethodsInterface<Abi extends ContractAbi> = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} & { [key: string]: ContractBoundMethod<any> };

export type ContractMethodSend = Web3PromiEvent<
FormatType<TransactionReceipt, typeof DEFAULT_RETURN_FORMAT>,
SendTransactionEvents<typeof DEFAULT_RETURN_FORMAT>
>;
export type ContractDeploySend<Abi extends ContractAbi> = Web3PromiEvent<
// eslint-disable-next-line no-use-before-define
Contract<Abi>,
SendTransactionEvents<typeof DEFAULT_RETURN_FORMAT>
>;

/**
* @hidden
* The event object can be accessed from `myContract.events.myEvent`.
Expand Down Expand Up @@ -768,12 +786,7 @@ export class Contract<Abi extends ContractAbi>
const deployData = _input ?? _data;
return {
arguments: args,
send: (
options?: PayableTxOptions,
): Web3PromiEvent<
Contract<Abi>,
SendTransactionEvents<typeof DEFAULT_RETURN_FORMAT>
> => {
send: (options?: PayableTxOptions): ContractDeploySend<Abi> => {
const modifiedOptions = { ...options };

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
Expand Down Expand Up @@ -1101,7 +1114,7 @@ export class Contract<Abi extends ContractAbi>
block,
),

send: (options?: PayableTxOptions | NonPayableTxOptions) =>
send: (options?: PayableTxOptions | NonPayableTxOptions): ContractMethodSend =>
this._contractMethodSend(methodAbi, abiParams, internalErrorsAbis, options),

estimateGas: async <ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(
Expand Down
4 changes: 2 additions & 2 deletions packages/web3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ export default Web3;
* Named exports for all objects which are the default-exported-object in their packages
*/
export { Web3 };
export { Web3Context, Web3PluginBase, Web3EthPluginBase } from 'web3-core';
export { Web3Context, Web3PluginBase, Web3EthPluginBase, Web3PromiEvent } from 'web3-core';
export { Web3Eth } from 'web3-eth';
export { Contract } from 'web3-eth-contract';
export { Contract, ContractDeploySend, ContractMethodSend } from 'web3-eth-contract';
export { Iban } from 'web3-eth-iban';
export { Personal } from 'web3-eth-personal';
export { Net } from 'web3-net';
Expand Down
Loading