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 145 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,4 @@ 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.
17 changes: 12 additions & 5 deletions packages/web3-common/src/eth_execution_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ export type AccessList = AccessListEntry[];
export type TransactionHash = HexString;
export type Uncles = HexString32Bytes[];

// TODO Should probably support EIP-2930 and EIP-1559
export interface TransactionCall {
readonly from?: Address;
readonly to: Address;
readonly gas?: Uint;
readonly gasPrice?: Uint;
readonly value?: Uint;
readonly data?: HexString;
readonly data?: HexStringBytes;
readonly type?: HexStringSingleByte;
readonly maxFeePerGas?: Uint;
readonly maxPriorityFeePerGas?: Uint;
readonly accessList?: AccessList;
}

export interface BaseTransaction {
Expand All @@ -42,7 +45,7 @@ export interface BaseTransaction {
readonly value: Uint;
// TODO - Investigate if this should actually be data instead of input
readonly input: HexStringBytes;
chainId?: Uint;
readonly chainId?: Uint;
}

export interface Transaction1559Unsigned extends BaseTransaction {
Expand Down Expand Up @@ -257,7 +260,9 @@ export type EthExecutionAPI = {

// https://github.com/ethereum/execution-apis/blob/main/src/eth/sign.json
eth_sign: (address: Address, message: HexStringBytes) => HexString256Bytes;
eth_signTransaction: (transaction: TransactionWithSender) => HexStringBytes;
eth_signTransaction: (
transaction: TransactionWithSender | Partial<TransactionWithSender>,
) => HexStringBytes;

// https://github.com/ethereum/execution-apis/blob/main/src/eth/state.json
eth_getBalance: (address: Address, blockNumber: BlockNumberOrTag) => Uint;
Expand All @@ -270,7 +275,9 @@ export type EthExecutionAPI = {
eth_getCode: (address: Address, blockNumber: BlockNumberOrTag) => HexStringBytes;

// https://github.com/ethereum/execution-apis/blob/main/src/eth/submit.json
eth_sendTransaction: (transaction: TransactionWithSender) => HexString32Bytes;
eth_sendTransaction: (
transaction: TransactionWithSender | Partial<TransactionWithSender>,
) => HexString32Bytes;
eth_sendRawTransaction: (transaction: HexStringBytes) => HexString32Bytes;

// https://geth.ethereum.org/docs/rpc/pubsub
Expand Down
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();
}
}
2 changes: 2 additions & 0 deletions packages/web3-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export interface Web3ConfigOptions {
transactionBlockTimeout: number;
transactionConfirmationBlocks: number;
transactionPollingTimeout: number;
transactionReceiptPollingInterval: number;
transactionConfirmationPollingInterval: number;
blockHeaderTimeout: number;
maxListenersWarningThreshold: number;
defaultNetworkId: Numbers | null;
Expand Down
30 changes: 30 additions & 0 deletions packages/web3-core/src/web3_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export abstract class Web3Config
transactionBlockTimeout: 50,
transactionConfirmationBlocks: 24,
transactionPollingTimeout: 750,
transactionReceiptPollingInterval: 1000,
transactionConfirmationPollingInterval: 13000,
blockHeaderTimeout: 10,
maxListenersWarningThreshold: 100,
defaultNetworkId: null,
Expand Down Expand Up @@ -118,6 +120,34 @@ export abstract class Web3Config
this._config.transactionPollingTimeout = val;
}

public get transactionReceiptPollingInterval() {
return this._config.transactionReceiptPollingInterval;
}

public set transactionReceiptPollingInterval(val) {
this.emit(Web3ConfigEvent.CONFIG_CHANGE, {
name: 'transactionReceiptPollingInterval',
oldValue: this._config.transactionReceiptPollingInterval,
newValue: val,
});

this._config.transactionReceiptPollingInterval = val;
}

public get transactionConfirmationPollingInterval() {
return this._config.transactionConfirmationPollingInterval;
}

public set transactionConfirmationPollingInterval(val) {
this.emit(Web3ConfigEvent.CONFIG_CHANGE, {
name: 'transactionConfirmationPollingInterval',
oldValue: this._config.transactionConfirmationPollingInterval,
newValue: val,
});

this._config.transactionConfirmationPollingInterval = val;
}

public get blockHeaderTimeout() {
return this._config.blockHeaderTimeout;
}
Expand Down
1 change: 1 addition & 0 deletions packages/web3-core/src/web3_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class Web3Context<
API extends Web3APISpec,
RegisteredSubs extends {
[key: string]: Web3SubscriptionConstructor<API>;
// eslint-disable-next-line @typescript-eslint/ban-types
} = {},
> extends Web3Config {
public static readonly providers = Web3RequestManager.providers;
Expand Down
1 change: 1 addition & 0 deletions packages/web3-core/src/web3_subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export abstract class Web3Subscription<

export type Web3SubscriptionConstructor<
API extends Web3APISpec,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
SubscriptionType extends Web3Subscription<any, any, API> = Web3Subscription<any, any, API>,
> = new (
// We accept any type of arguments here and don't deal with this type internally
Expand Down
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
133 changes: 67 additions & 66 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 @@ -169,14 +170,19 @@ export class Contract<Abi extends ContractAbi>
const modifiedOptions = { ...options };
delete modifiedOptions.to;

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

return txHash;
// eslint-disable-next-line no-void
void promiEvent.then(res => {
this._address = res.contractAddress;
});

return promiEvent;

// TODO: Use eth-tx functions to
//
Expand All @@ -194,17 +200,20 @@ export class Contract<Abi extends ContractAbi>
// provider: this.currentProvider,
// });
},
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 @@ -297,10 +306,12 @@ export class Contract<Abi extends ContractAbi>
call: async (options?: PayableCallOptions, block?: BlockNumberOrTag) =>
this._contractMethodCall(abi, params, options, block),
// TODO: Use `web3-eth-tx` package to return `PromiEvent` instead.
nazarhussain marked this conversation as resolved.
Show resolved Hide resolved
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 +323,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 +343,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
Loading