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

Update web3-eth-contract to use web3-eth methods #4806

Merged
merged 150 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
3fd0e9e
Add @ethereumjs/tx dependency
spacesailor24 Jan 10, 2022
f4f30dd
Update Web3BaseProvider to SupportedProviders for Web3Eth constructor
spacesailor24 Jan 10, 2022
4622b80
WIP eth-tx
spacesailor24 Jan 10, 2022
8fa2bc5
Add support for undefined values for convertToValidType
spacesailor24 Jan 12, 2022
eb2305c
Remove unused Web3BaseProvider
spacesailor24 Jan 12, 2022
30b289d
WIP eth-tx utils
spacesailor24 Jan 12, 2022
ff167ea
Export privateKeyToAddress
spacesailor24 Jan 14, 2022
907c7d0
Add web3-eth-accounts dependency
spacesailor24 Jan 14, 2022
f87ffc6
WIP web3-eth-tx util methods
spacesailor24 Jan 14, 2022
307201f
Replace inline errors with error constructors
spacesailor24 Jan 17, 2022
c553765
Change types for transaction r and s properties. Correct hardforks in…
spacesailor24 Jan 17, 2022
73c46d6
Init formatTransaction tests and fixture
spacesailor24 Jan 17, 2022
dfdf768
Init detectTransactionType and fixture
spacesailor24 Jan 17, 2022
9071db3
Add more descriptive error messages
spacesailor24 Jan 19, 2022
82d83fd
Logic fixes for validateTransactionForSigning
spacesailor24 Jan 19, 2022
953ee21
Init validateTransactionForSigning tests and fixtures
spacesailor24 Jan 19, 2022
77093a3
Add esModuleInterop: true to tsconfig
spacesailor24 Jan 19, 2022
281b6bd
Small bug fixes and added TODOs
spacesailor24 Jan 19, 2022
06f7575
Add parent describe to detect_transaction_type test
spacesailor24 Jan 19, 2022
143922b
Add parent describe to format_transaction test
spacesailor24 Jan 19, 2022
fb16061
Add web3-providers-http as dev dependency for tests
spacesailor24 Jan 19, 2022
dcf9037
Init populate_transaction tests
spacesailor24 Jan 19, 2022
17e418c
Move types from eth_tx.ts to types.ts
spacesailor24 Jan 19, 2022
b89b7e1
Merge branch '4.x' into wyatt/4.x/4652-eth-tx-refactor
spacesailor24 Jan 19, 2022
5c3abbd
Remove TODOs
spacesailor24 Jan 19, 2022
e6980c3
Merge branch 'wyatt/4.x/4652-eth-tx-refactor' of github.com:ChainSafe…
spacesailor24 Jan 19, 2022
6311872
Add missing ,
spacesailor24 Jan 19, 2022
11f8097
Remove TODO
spacesailor24 Jan 19, 2022
ef46dbc
Remove TODO
spacesailor24 Jan 19, 2022
cbe1c20
Fix transaction type import issues
spacesailor24 Jan 21, 2022
36a2ad8
Update convertToValidType test data for undefined
spacesailor24 Jan 21, 2022
008aed2
Update override method tests
spacesailor24 Jan 21, 2022
293be77
Update packages/web3-eth/src/eth_tx.ts
spacesailor24 Jan 24, 2022
e82d5d3
Move getBlock to after type check for populateTransaction
spacesailor24 Jan 24, 2022
7e661d8
Merge branch 'wyatt/4.x/4652-eth-tx-refactor' of github.com:ChainSafe…
spacesailor24 Jan 24, 2022
eaa4bd0
Replace N/A with name of error for error.msg
spacesailor24 Jan 24, 2022
92bcaaf
Assign formattedTransaction type Transaction<ReturnType>
spacesailor24 Jan 24, 2022
e41aed8
convertToValidType now throws error for value === undefined
spacesailor24 Jan 24, 2022
f7ff2d8
NumberType extends Numbers
spacesailor24 Jan 24, 2022
0f5bac0
Transaction type related changes
spacesailor24 Jan 24, 2022
b3d7e97
Refactor DesiredType logic
spacesailor24 Jan 24, 2022
307d7b3
Convert to deep copy for formatTransaction method
spacesailor24 Jan 24, 2022
d505d1e
skip override method test - needs to be refactored. General formatting
spacesailor24 Jan 24, 2022
7caa46f
Skip override method test - needs to be refactored. Set input.type > …
spacesailor24 Jan 24, 2022
6aec094
Refactor formatTransaction
spacesailor24 Jan 25, 2022
3fce2e9
Add error codes to web3-eth errors
spacesailor24 Jan 25, 2022
cd0ffb0
Refactor validateGate if statements into readable consts
spacesailor24 Jan 25, 2022
c393ea6
Update comment
spacesailor24 Jan 25, 2022
dd78824
Add link to error message from 1.x
spacesailor24 Jan 25, 2022
c06a8fa
Fix bug with is gas consts in validateGas
spacesailor24 Jan 25, 2022
8a2eeea
Init InvalidConvertibleValueError
spacesailor24 Jan 25, 2022
f70ac6e
Replace error with InvalidConvertibleValueError
spacesailor24 Jan 25, 2022
2be1e66
Update tests for formatting undefined
spacesailor24 Jan 25, 2022
4b38771
Update expected errors for validateGas tests
spacesailor24 Jan 25, 2022
741fa8c
No longer default tx.type if undefined
spacesailor24 Jan 25, 2022
07f5cd7
Refactor detectTransactionType
spacesailor24 Jan 26, 2022
cb6e7eb
Fix type error for return in detectTransactionType
spacesailor24 Jan 26, 2022
0ea5d7b
Init rpc_method_wrappers.ts
spacesailor24 Jan 26, 2022
27c5087
Remove Web3Eth import
spacesailor24 Jan 26, 2022
025bcc5
Refactor use of web3Context.defaults
spacesailor24 Jan 26, 2022
ec02b6f
Restore Formatted transaction types
spacesailor24 Jan 26, 2022
c5c40a0
Init web3_rpc_method_wrappers tests
spacesailor24 Jan 26, 2022
52b56ff
Refactor web3_eth_methods_with_parameters test
spacesailor24 Jan 31, 2022
9312028
Replace if X === undefined checks with ?
spacesailor24 Jan 31, 2022
abfd252
Un-export consts that aren't used
spacesailor24 Jan 31, 2022
64b9b08
Add defaultTransactionType and defaultMaxPriorityFeePerGas
spacesailor24 Feb 1, 2022
e9ae954
Merge branch '4.x' into wyatt/4.x/4652-eth-tx-refactor
spacesailor24 Feb 1, 2022
63d841d
Update defaults for chain and hardfork to mainnet and london
spacesailor24 Feb 1, 2022
aaa70ec
Update to use web3Context.default chain and hardfork. Init tests for …
spacesailor24 Feb 1, 2022
95aebb9
Update test to account for added defaults
spacesailor24 Feb 1, 2022
e91f019
Refactor validateGas to use helper methods
spacesailor24 Feb 1, 2022
1dec5c8
remove TODO
spacesailor24 Feb 1, 2022
b810f45
Init error TransactionGasMismatchError
spacesailor24 Feb 2, 2022
ccf4cc8
Fix tests and refactor transaction validator helper methods
spacesailor24 Feb 2, 2022
74989ad
Move validation methods to validation.ts
spacesailor24 Feb 2, 2022
6373134
Add input to Transaction type
spacesailor24 Feb 3, 2022
3c16575
Add @ethereumjs/common dependency
spacesailor24 Feb 3, 2022
989c2dd
yarn format
spacesailor24 Feb 3, 2022
aa985ac
Remove null for defaultTransactionType
spacesailor24 Feb 3, 2022
69cc3cf
Add default for defaultTransactionType
spacesailor24 Feb 3, 2022
2bf6c5b
Update default for defaultTransactionType
spacesailor24 Feb 3, 2022
0bcc33d
Bug fixes, refactors, and init prepareTransactionForSigning and tests
spacesailor24 Feb 3, 2022
55476e6
Remove unused test code
spacesailor24 Feb 3, 2022
2cbc215
revert transaction data and value to default to 0x
spacesailor24 Feb 5, 2022
ea49c6c
Fix failing populate_transaction tests
spacesailor24 Feb 5, 2022
49171a1
Solve merge conflicts
spacesailor24 Feb 5, 2022
3b5d041
Add defaultNetworkId to web3_config
spacesailor24 Feb 8, 2022
015d546
Add TODO for failing prepare_transaction_for_signing test
spacesailor24 Feb 8, 2022
57f6403
Merge branch '4.x' into wyatt/4.x/4652-eth-tx-refactor
spacesailor24 Feb 8, 2022
2eb1a5a
Remove TODO
spacesailor24 Feb 8, 2022
b65ffe9
Init TransactionDataAndInputError
spacesailor24 Feb 8, 2022
9a8db9b
Merge branch 'wyatt/4.x/4652-eth-tx-refactor' of github.com:ChainSafe…
spacesailor24 Feb 8, 2022
ff6d72e
Add else if to populateTransaction - data
spacesailor24 Feb 8, 2022
c428810
Refactor populateTransaction - chainId
spacesailor24 Feb 8, 2022
5d26cdd
Comment out unused ifs
spacesailor24 Feb 8, 2022
4bbf720
Remove populateTransaction - gas
spacesailor24 Feb 8, 2022
c305abf
Remove populateTransaction - hexTxType
spacesailor24 Feb 8, 2022
7d3c3a3
Replace use of ValidReturnTypes[ValidTypes.HexString] with HexString
spacesailor24 Feb 8, 2022
8cf4f04
Remove toHex import
spacesailor24 Feb 8, 2022
0e11ad6
Remove | null for Web3ConfigOptions defaultChain and defaultHardfork
spacesailor24 Feb 8, 2022
89c922b
Refactor getEthereumjsTransactionOptions
spacesailor24 Feb 8, 2022
6ea21eb
Remove no longer needed populateTransaction - gas test
spacesailor24 Feb 8, 2022
a808d0d
Update packages/web3-eth/src/validation.ts
spacesailor24 Feb 8, 2022
08880a5
Merge branch '4.x' into wyatt/4.x/4652-eth-tx-refactor
spacesailor24 Feb 8, 2022
380002c
Remove unnecessary rpc method wrappers
spacesailor24 Feb 10, 2022
c5cf8c2
Web3Eth now extends Web3Context instead of instantiating it
spacesailor24 Feb 13, 2022
e9a50e8
Solve merge conflicts
spacesailor24 Feb 13, 2022
1e35ca5
Init getPendingTransactions
spacesailor24 Feb 13, 2022
770b217
Init requestAccounts
spacesailor24 Feb 13, 2022
54cdc59
Add EIP-1102 as a comment for requestAccounts
spacesailor24 Feb 13, 2022
892b341
Init getChainId
spacesailor24 Feb 13, 2022
1ac1a9c
Init getProof
spacesailor24 Feb 15, 2022
499c39a
Init Web3EthExecutionAPI
spacesailor24 Feb 15, 2022
b40bb80
Merge branch '4.x' into wyatt/4.x/4608-web3-eth-extends-web3-context
spacesailor24 Feb 15, 2022
b30a0f2
Merge branch 'wyatt/4.x/4608-web3-eth-extends-web3-context' into wyat…
spacesailor24 Feb 15, 2022
23b4405
Solve merge conflicts
spacesailor24 Feb 19, 2022
c35ed3b
Fix imports for AccountObject in fixtures
spacesailor24 Feb 19, 2022
a99208f
Add formatting to getPendingTransactions. Move formatTransaction to s…
spacesailor24 Feb 19, 2022
d6ac3a6
Add TODO to investigate transaction.data
spacesailor24 Feb 21, 2022
627efdc
Add formatting to getChainId response
spacesailor24 Feb 21, 2022
5b8f781
Init getNodeInfo
spacesailor24 Feb 21, 2022
edf11f1
Revert esModuleInterop change
spacesailor24 Feb 21, 2022
0d1f59f
Combine networkId and chainId if statements
spacesailor24 Feb 22, 2022
3775121
Merge branch '4.x' into wyatt/4.x/4608-web3-eth-missing-rpc-methods
spacesailor24 Feb 22, 2022
825cc03
yarn format
spacesailor24 Feb 24, 2022
3e3e033
Add Partial to type of transaction for eth_sendTransaction
spacesailor24 Feb 24, 2022
a5da153
Init transactionReceiptPollingInterval and transactionConfirmationPol…
spacesailor24 Feb 24, 2022
e711e76
Add TODO and Partial to transaction type for sendTransaction
spacesailor24 Feb 24, 2022
2028c85
WIP sendTransaction and PromiEvent integration
spacesailor24 Feb 24, 2022
072123b
Solve merge conflicts
spacesailor24 Feb 24, 2022
039bc48
Add eslint-disable-next-line
spacesailor24 Feb 25, 2022
fb32bdc
Add eslint-disable-next-line
spacesailor24 Feb 25, 2022
f87e739
Move TransactionEvents
spacesailor24 Feb 25, 2022
2ed9b40
eslint fixes
spacesailor24 Feb 25, 2022
433ea15
Update sendSignedTransaction to use PromiEvent
spacesailor24 Feb 25, 2022
73a38e9
Init signTransaction
spacesailor24 Feb 25, 2022
0e75a2d
Refactor TransactionCall
spacesailor24 Feb 25, 2022
05522c9
Comment out validation for call
spacesailor24 Feb 25, 2022
b01dd30
Init TransactionCall type for web3-eth types
spacesailor24 Feb 25, 2022
be06ee5
Remove as BaseTransaction from isTransactionCall
spacesailor24 Feb 25, 2022
7afbb42
Implement call for rpc_method_wrappers
spacesailor24 Feb 25, 2022
96026ec
Uncomment sendTransaction, signTransaction, and call
spacesailor24 Feb 25, 2022
ec4d18f
:sparkles: Update estimate gas method to use web3-eth
nazarhussain Mar 1, 2022
5a31174
:art: Update contract mehtod send to use web3-eth utility functions
nazarhussain Mar 2, 2022
a479a7d
:art: Update contract method call to use web3-eth utilities
nazarhussain Mar 2, 2022
181d39d
Merge branch '4.x' into nh/4685-contract-use-eth
nazarhussain Mar 3, 2022
de3ba87
Merge branch '4.x' into nh/4685-contract-use-eth
spacesailor24 Mar 4, 2022
ba905bf
Merge branch '4.x' into nh/4685-contract-use-eth
spacesailor24 Mar 4, 2022
a5eedc3
:art: Fix code introduced in merge conflicts
nazarhussain Mar 4, 2022
9532924
Merge branch 'nh/4685-contract-use-eth' of github.com:ChainSafe/web3.…
nazarhussain Mar 4, 2022
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ Released with 1.0.0-beta.37 code base.
4. `recover` function's last param is boolean `hashed`, it is used to indicate if data provided is already hashed or not. By default this function will assume data is not hashed.
5. The `Wallet` no more supports address/number indexing. Have to use `wallet.get` instead.
6. `Wallet.create` function doesn't accepts `entropy` param
7. `contract.method.send()` will resolve to transaction receipt instead of `transactionHash`. User can use `receipt.transactionHash` instead.

#### web3-net

Expand All @@ -368,3 +369,4 @@ Released with 1.0.0-beta.37 code base.
2. `setContent` is not supported in web3-eth-ens 4.x as its deprecated in ENS public resolver (https://github.com/ensdomains/resolvers/blob/master/contracts/PublicResolver.sol)
3. `getContent` is not supported in web3-eth-ens 4.x as its deprecated in ENS public resolver.
4. `getMultihash` is not supported in web3-eth-ens 4.x as its deprecated in ENS public resolver.

12 changes: 12 additions & 0 deletions packages/web3-common/src/web3_event_emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,16 @@ export class Web3EventEmitter<T extends Web3EventMap> implements Web3Emitter<T>
public emit<K extends Web3EventKey<T>>(eventName: K, params: T[K]) {
this._emitter.emit(eventName, params);
}

public listenerCount<K extends Web3EventKey<T>>(eventName: K) {
return this._emitter.listenerCount(eventName);
}

public listeners<K extends Web3EventKey<T>>(eventName: K) {
return this._emitter.listeners(eventName);
}

public eventNames() {
return this._emitter.eventNames();
}
}
3 changes: 2 additions & 1 deletion packages/web3-eth-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"web3-core": "4.0.0-alpha.0",
"web3-eth-abi": "4.0.0-alpha.0",
"web3-utils": "4.0.0-alpha.1",
"web3-validator": "0.1.0-alpha.0"
"web3-validator": "0.1.0-alpha.0",
"web3-eth": "4.0.0-alpha.1"
},
"devDependencies": {
"@humeris/espresso-shot": "^4.0.0",
Expand Down
151 changes: 67 additions & 84 deletions packages/web3-eth-contract/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import {
isAbiFunctionFragment,
jsonInterfaceMethodToString,
} from 'web3-eth-abi';
import { estimateGas, sendTransaction, call } from 'web3-eth/src/rpc_method_wrappers';
import {
Address,
BlockNumberOrTag,
BlockTags,
hexToNumber,
toChecksumAddress,
HexString,
toChecksumAddress,
ValidTypes,
} from 'web3-utils';
import { validator } from 'web3-validator';
import { decodeMethodReturn, encodeEventABI, encodeMethodABI } from './encoding';
Expand Down Expand Up @@ -164,47 +165,38 @@ export class Contract<Abi extends ContractAbi>

return {
arguments: args,
// TODO: Use `web3-eth-tx` package to return `PromiEvent` instead.
send: async (options?: PayableCallOptions) => {
const modifiedOptions = { ...options };
delete modifiedOptions.to;

const txHash = await this._contractMethodSend(
const promiEvent = this._contractMethodSend(
abi as AbiFunctionFragment,
args,
modifiedOptions,
contractOptions,
);

return txHash;

// TODO: Use eth-tx functions to
//
// 1. Get the transaction receipt from the above txHash
// 2. Extract the contract address from the receipt
// 3. Get the code from eth_getCode for the contract address
// 4. Return the contract instance with the new address and the code
//
// return new Contract<Abi>(this._jsonInterface, contractAddress as HexString, {
// gas: this.options.gas,
// gasPrice: this.options.gasPrice,
// gasLimit: this.options.gasLimit,
// from: this.options.from,
// data: this.options.data,
// provider: this.currentProvider,
// });
// eslint-disable-next-line no-void
void promiEvent.then(res => {
this._address = res.contractAddress;
});

return promiEvent;
},
estimateGas: async (options?: PayableCallOptions, block?: BlockNumberOrTag) => {
estimateGas: async <ReturnType extends ValidTypes = ValidTypes.HexString>(
options?: PayableCallOptions,
returnType?: ReturnType,
) => {
const modifiedOptions = { ...options };
delete modifiedOptions.to;

return this._contractMethodEstimateGas(
abi as AbiFunctionFragment,
args,
modifiedOptions,
block,
return this._contractMethodEstimateGas({
abi: abi as AbiFunctionFragment,
params: args,
returnType,
options: modifiedOptions,
contractOptions,
);
});
},
encodeABI: () => encodeMethodABI(abi as AbiFunctionFragment, args, data),
};
Expand Down Expand Up @@ -296,11 +288,12 @@ export class Contract<Abi extends ContractAbi>
arguments: params,
call: async (options?: PayableCallOptions, block?: BlockNumberOrTag) =>
this._contractMethodCall(abi, params, options, block),
// TODO: Use `web3-eth-tx` package to return `PromiEvent` instead.
send: async (options?: PayableCallOptions) =>
send: (options?: PayableCallOptions) =>
this._contractMethodSend(abi, params, options),
estimateGas: async (options?: PayableCallOptions, block?: BlockNumberOrTag) =>
this._contractMethodEstimateGas(abi, params, options, block),
estimateGas: async <ReturnType extends ValidTypes = ValidTypes.HexString>(
options?: PayableCallOptions,
returnType?: ReturnType,
) => this._contractMethodEstimateGas({ abi, params, returnType, options }),
encodeABI: () => encodeMethodABI(abi, params),
} as unknown as PayableMethodObject<
ContractMethod<T>['Inputs'],
Expand All @@ -312,10 +305,12 @@ export class Contract<Abi extends ContractAbi>
arguments: params,
call: async (options?: NonPayableCallOptions, block?: BlockNumberOrTag) =>
this._contractMethodCall(abi, params, options, block),
send: async (options?: NonPayableCallOptions) =>
send: (options?: NonPayableCallOptions) =>
this._contractMethodSend(abi, params, options),
estimateGas: async (options?: NonPayableCallOptions, block?: BlockNumberOrTag) =>
this._contractMethodEstimateGas(abi, params, options, block),
estimateGas: async <ReturnType extends ValidTypes = ValidTypes.HexString>(
options?: NonPayableCallOptions,
returnType?: ReturnType,
) => this._contractMethodEstimateGas({ abi, params, returnType, options }),
encodeABI: () => encodeMethodABI(abi, params),
} as unknown as NonPayableMethodObject<
ContractMethod<T>['Inputs'],
Expand All @@ -330,68 +325,56 @@ export class Contract<Abi extends ContractAbi>
options?: Options,
block?: BlockNumberOrTag,
) {
return decodeMethodReturn(
const tx = getEthTxCallParams({
abi,
await this.requestManager.send({
method: 'eth_call',
params: [
getEthTxCallParams({
abi,
params,
options,
contractOptions: this.options,
}),
block ?? BlockTags.LATEST,
],
}),
);
params,
options,
contractOptions: this.options,
});

return decodeMethodReturn(abi, await call(this, tx, block));
}

private async _contractMethodSend<Options extends PayableCallOptions | NonPayableCallOptions>(
private _contractMethodSend<Options extends PayableCallOptions | NonPayableCallOptions>(
abi: AbiFunctionFragment,
params: unknown[],
options?: Options,
contractOptions?: ContractOptions,
) {
return decodeMethodReturn(
const tx = getSendTxParams({
abi,
await this.requestManager.send({
method: 'eth_sendTransaction',
params: [
getSendTxParams({
abi,
params,
options,
contractOptions: contractOptions ?? this.options,
}),
],
}),
);
params,
options,
contractOptions: contractOptions ?? this.options,
});

return sendTransaction(this, tx);
}

private async _contractMethodEstimateGas<
Options extends PayableCallOptions | NonPayableCallOptions,
>(
abi: AbiFunctionFragment,
params: unknown[],
options?: Options,
block?: BlockNumberOrTag,
contractOptions?: ContractOptions,
) {
return hexToNumber(
await this.requestManager.send({
method: 'eth_estimateGas',
params: [
getEstimateGasParams({
abi,
params,
options,
contractOptions: contractOptions ?? this.options,
}),
block ?? BlockTags.LATEST,
],
}),
);
ReturnType extends ValidTypes = ValidTypes.HexString,
>({
abi,
params,
returnType,
options,
contractOptions,
}: {
abi: AbiFunctionFragment;
params: unknown[];
returnType?: ReturnType;
options?: Options;
contractOptions?: ContractOptions;
}) {
const tx = getEstimateGasParams({
abi,
params,
options,
contractOptions: contractOptions ?? this.options,
});

return estimateGas(this, tx, BlockTags.LATEST, returnType);
}

// eslint-disable-next-line class-methods-use-this
Expand Down
55 changes: 17 additions & 38 deletions packages/web3-eth-contract/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { EthExecutionAPI, PromiEvent, ReceiptInfo } from 'web3-common';
import { EthExecutionAPI, ReceiptInfo } from 'web3-common';
import { SupportedProviders } from 'web3-core';
import { ContractAbi } from 'web3-eth-abi';
import { Address, BlockNumberOrTag, Bytes, Filter, HexString, Numbers, Uint } from 'web3-utils';
import { sendTransaction } from 'web3-eth/src/rpc_method_wrappers';
import { Address, BlockNumberOrTag, Bytes, Filter, HexString, Uint, ValidTypes } from 'web3-utils';

export interface EventLog {
event: string;
Expand Down Expand Up @@ -43,14 +44,14 @@ export interface ContractInitOptions {
export type TransactionReceipt = ReceiptInfo;

export interface NonPayableCallOptions {
nonce?: Numbers;
chainId?: Numbers;
nonce?: HexString;
chainId?: HexString;
from?: Address;
to?: Address;
data?: HexString;
gas?: string;
maxPriorityFeePerGas?: Numbers;
maxFeePerGas?: Numbers;
maxPriorityFeePerGas?: HexString;
maxFeePerGas?: HexString;
gasPrice?: string;
}

Expand All @@ -61,43 +62,21 @@ export interface PayableCallOptions extends NonPayableCallOptions {
export interface NonPayableMethodObject<Inputs = unknown[], Outputs = unknown[]> {
arguments: Inputs;
call(tx?: NonPayableCallOptions, block?: BlockNumberOrTag): Promise<Outputs>;
send(tx?: NonPayableCallOptions): PromiEvent<
TransactionReceipt,
{
sending: object;
sent: object;
transactionHash: string;
receipt: TransactionReceipt;
confirmation: {
confirmations: number;
receipt: TransactionReceipt;
latestBlockHash: HexString;
};
error: Error;
}
>;
estimateGas(tx?: NonPayableCallOptions): Promise<number>;
send(tx?: NonPayableCallOptions): ReturnType<typeof sendTransaction>;
estimateGas<ReturnType extends ValidTypes = ValidTypes.HexString>(
options?: NonPayableCallOptions,
returnType?: ReturnType,
): Promise<ReturnType>;
encodeABI(): string;
}

export interface PayableMethodObject<Inputs = unknown[], Outputs = unknown[]> {
arguments: Inputs;
call(tx?: PayableCallOptions, block?: BlockNumberOrTag): Promise<Outputs>;
send(tx?: PayableCallOptions): PromiEvent<
TransactionReceipt,
{
sending: object;
sent: object;
transactionHash: string;
receipt: TransactionReceipt;
confirmation: {
confirmations: number;
receipt: TransactionReceipt;
latestBlockHash: HexString;
};
error: Error;
}
>;
estimateGas(tx?: PayableCallOptions): Promise<number>;
send(tx?: PayableCallOptions): ReturnType<typeof sendTransaction>;
estimateGas<ReturnType extends ValidTypes = ValidTypes.HexString>(
options?: PayableCallOptions,
returnType?: ReturnType,
): Promise<ReturnType>;
encodeABI(): HexString;
}
9 changes: 5 additions & 4 deletions packages/web3-eth-contract/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TransactionCall, TransactionWithSender } from 'web3-common';
import { TransactionWithSender } from 'web3-common';
import { AbiFunctionFragment } from 'web3-eth-abi';
import { mergeDeep } from 'web3-utils';
import { TransactionCall } from 'web3-eth/src/types';
import { encodeMethodABI } from './encoding';
import { Web3ContractError } from './errors';
import { NonPayableCallOptions, PayableCallOptions, ContractOptions } from './types';
Expand All @@ -15,7 +16,7 @@ export const getSendTxParams = ({
params: unknown[];
options?: PayableCallOptions | NonPayableCallOptions;
contractOptions: ContractOptions;
}): TransactionWithSender & { data: string } => {
}): TransactionCall => {
if (!options?.to && !contractOptions.address) {
throw new Web3ContractError('Contract address not specified');
}
Expand All @@ -33,7 +34,7 @@ export const getSendTxParams = ({
data: contractOptions.data,
},
options as unknown as Record<string, unknown>,
) as unknown as TransactionWithSender & { data: string };
) as unknown as TransactionCall;

if (!txParams.data) {
txParams = {
Expand Down Expand Up @@ -114,5 +115,5 @@ export const getEstimateGasParams = ({
};
}

return txParams;
return txParams as TransactionWithSender;
};
Loading