Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
8910172
:sparkles: Add Web3Config class
nazarhussain Oct 11, 2021
d82f0ac
:sparkles: Add configuraitons for Web3Config
nazarhussain Oct 11, 2021
3f82f55
:white_check_mark: Add unit tests for Web3Config
nazarhussain Oct 11, 2021
18a0d43
:art: Remove unused import
nazarhussain Oct 11, 2021
402d3fc
:rotating_light: Remove linter warnings
nazarhussain Oct 12, 2021
679c7e0
:sparkles: Add a local storage wallet for web3-core
nazarhussain Oct 12, 2021
bf90842
:white_check_mark: Add unit tests for local storage wallet
nazarhussain Oct 12, 2021
9dec746
Add a strong type event emitter interface
nazarhussain Oct 15, 2021
d0d3650
:art: Update Web3Config to use strong type events
nazarhussain Oct 15, 2021
46307e5
:art: Update web3-base-provider with proper types and identity check
nazarhussain Oct 18, 2021
ccc1b3e
:art: Update Web3Config to use new event emitter
nazarhussain Oct 18, 2021
f6db13d
:sparkles: Add Web3RequestManager class
nazarhussain Oct 18, 2021
cf29655
Add subscription manager and subscription logic
nazarhussain Oct 19, 2021
b5c9efd
:rotating_light: Fix linter warnings
nazarhussain Oct 19, 2021
aef3292
Merge branch 'nh/4429-request-manager' of github.com:ChainSafe/web3.j…
nazarhussain Oct 19, 2021
6ff4afa
Merge branch '4.x' into nh/4429-request-manager
nazarhussain Oct 21, 2021
b6ce793
Init web3-eth package
spacesailor24 Oct 23, 2021
6f41ea3
Merge branch 'nh/4429-request-manager' into wyatt/4.x/4483-eth-rpc-me…
spacesailor24 Oct 23, 2021
aef59e1
:wastebasket: Remove a duplicate file
nazarhussain Oct 25, 2021
5a002b4
:art: Add new error constructors
nazarhussain Oct 25, 2021
8af3740
:art: Update RequestManager and SubscriptionManager
nazarhussain Oct 25, 2021
ba2b39a
:white_check_mark: Add unit tests for RequestManager and Subscription…
nazarhussain Oct 25, 2021
ff3bf0f
:art: Update the exports for web3-core
nazarhussain Oct 25, 2021
e11e103
:art: Update code as per feedback
nazarhussain Oct 25, 2021
80957c5
:white_check_mark: Fix failing tests
nazarhussain Oct 25, 2021
5fa9331
WIP
spacesailor24 Oct 26, 2021
3991644
Merge branch 'nh/4429-request-manager' into wyatt/4.x/4483-eth-rpc-me…
spacesailor24 Oct 26, 2021
1c0f9b9
WIP
spacesailor24 Oct 26, 2021
7a250a1
WIP
spacesailor24 Oct 27, 2021
c4d8f05
:art: Update the provider condition to set an object
nazarhussain Oct 27, 2021
955f5a9
Merge branch '4.x' into nh/4429-request-manager
nazarhussain Oct 27, 2021
79dcda2
Merge conflicts
spacesailor24 Oct 28, 2021
3d7099f
Merge conflicts
spacesailor24 Oct 28, 2021
705f9d0
Merge conflicts
spacesailor24 Oct 29, 2021
018966d
WIP RPC method wrappers
spacesailor24 Oct 29, 2021
9b190e1
:sparkles: Add eth execution API types
nazarhussain Oct 29, 2021
afecf27
:art: Update base provider to use eth api types
nazarhussain Oct 29, 2021
9b5572f
:sparkles: Add json-rpc helpers
nazarhussain Oct 29, 2021
8cfcfe5
:art: Update exports for web3-common
nazarhussain Oct 29, 2021
0251498
:art: Update API types
nazarhussain Oct 30, 2021
440b34f
:art: Update http-provider types
nazarhussain Oct 30, 2021
94d9106
:art: Update web3-core types
nazarhussain Oct 30, 2021
b374e56
WIP RPC method wrappers
spacesailor24 Oct 30, 2021
9fe3497
WIP Merge conflicts
spacesailor24 Oct 30, 2021
ce77d30
WIP RPC method wrappers - updated with changes from nh/eth-api-types
spacesailor24 Oct 30, 2021
7bd84bb
Apply suggestions from code review
nazarhussain Nov 1, 2021
968b31b
Merge branch 'nh/eth-api-types' into wyatt/4.x/4483-eth-rpc-methods
spacesailor24 Nov 2, 2021
f8f93d8
Merge branch '4.x' into wyatt/4.x/4483-eth-rpc-methods
spacesailor24 Nov 2, 2021
05c8d24
Finish implementing RPC method wrappers
spacesailor24 Nov 2, 2021
40606dc
:sparkles: Add common types to utils
nazarhussain Nov 2, 2021
7900dfb
:art: Updated the types as per feedback
nazarhussain Nov 2, 2021
67ef6a1
Merge branch '4.x' into nh/eth-api-types
nazarhussain Nov 2, 2021
4197309
Merge branch 'nh/eth-api-types' into wyatt/4.x/4483-eth-rpc-methods
spacesailor24 Nov 6, 2021
0a5658e
Merge branch '4.x' into wyatt/4.x/4483-eth-rpc-methods
spacesailor24 Nov 6, 2021
da1ae01
Remove outdated code
spacesailor24 Nov 9, 2021
b8c26a6
Update param and return types
spacesailor24 Nov 9, 2021
3f1c187
Update param and return types
spacesailor24 Nov 9, 2021
e8b36ee
Merge branch '4.x' into nh/eth-api-types
nazarhussain Nov 9, 2021
0ea2be8
:art: Update the code with feedback
nazarhussain Nov 9, 2021
5cfd63b
:art: Fix ReceiptInfo object
nazarhussain Nov 9, 2021
01ec03d
:art: Fix eth_submitWork spec
nazarhussain Nov 9, 2021
5012993
:art: Update eth_estimateGas spec to make all properties of tx optional
nazarhussain Nov 9, 2021
4d2ed7a
:art: Update transaction spec
nazarhussain Nov 9, 2021
26035ae
Apply suggestions from code review
nazarhussain Nov 9, 2021
cf5f781
Merge branch '4.x' into nh/eth-api-types
nazarhussain Nov 10, 2021
d1b6770
Merge branch 'nh/eth-api-types' into wyatt/4.x/4483-eth-rpc-methods
spacesailor24 Nov 10, 2021
c30c0e1
Remove return types for methods
spacesailor24 Nov 11, 2021
eb38e2a
Init ValidTypes and ValidReturnTypes
spacesailor24 Nov 11, 2021
605e193
Disable no-nested-ternary rule
spacesailor24 Nov 11, 2021
ff127fa
Init convertToValidType method
spacesailor24 Nov 11, 2021
85c02eb
Remove eslint disable for no-nested-ternary
spacesailor24 Nov 11, 2021
29249b4
WIP web3-eth rpc methods
spacesailor24 Nov 11, 2021
ff228ae
Merge branch '4.x' into nh/eth-api-types
nazarhussain Nov 11, 2021
36c82e0
WIP web3-eth rpc methods
spacesailor24 Nov 11, 2021
509d4a5
Add Partial to transaction type for estimateGas. Add getFeeHistory
spacesailor24 Nov 12, 2021
6e54fad
Add remaining web3-eth methods from 1.x
spacesailor24 Nov 12, 2021
e2b3c3c
Update packages/web3-common/src/eth_execution_api.ts
nazarhussain Nov 12, 2021
fdda413
WIP - debugging type errors
spacesailor24 Nov 12, 2021
1fc0d10
:art: Improve type safety for nested types
nazarhussain Nov 13, 2021
2ec91f3
Merge branch 'nh/eth-api-types' into wyatt/4.x/4483-eth-rpc-methods
spacesailor24 Nov 13, 2021
8a35135
Update type of transactionIndex for ReceiptInfo
spacesailor24 Nov 14, 2021
48491d2
Add defaultReturnType to config
spacesailor24 Nov 14, 2021
06b53b7
Add additional convertible properties
spacesailor24 Nov 14, 2021
bd14767
Remove colon from TODO comment
spacesailor24 Nov 14, 2021
ad4e4dc
Update methods to use convertObjectPropertiesToValidType
spacesailor24 Nov 14, 2021
12bfba7
Remove unneccessary return types
spacesailor24 Nov 14, 2021
0a4d680
Remove method return types
spacesailor24 Nov 15, 2021
5ec516a
Refactor rpcMethosNoParams test data
spacesailor24 Nov 15, 2021
e08ae76
Init rpcMethodsWithParams test data
spacesailor24 Nov 15, 2021
52d4bbf
Merge conflicts
spacesailor24 Nov 16, 2021
33ea63e
WIP Adding validation to RPC wrappers
spacesailor24 Nov 16, 2021
995b9dd
Add validation to RPC wrapper methods
spacesailor24 Nov 16, 2021
1addea7
WIP refactor validation tests and fixtures
spacesailor24 Nov 17, 2021
9cde6ab
Convert newly added validation methods to arrow functions
spacesailor24 Nov 17, 2021
b15b0cb
Change value type to any for InvalidBlockNumberOrTag
spacesailor24 Nov 17, 2021
48f38f1
Update type of parameter for InvalidFilter to any
spacesailor24 Nov 20, 2021
cacd381
Validation method tests, fixtures, and bug fixes
spacesailor24 Nov 20, 2021
42f6834
Add eslint-disables
spacesailor24 Nov 20, 2021
83bd73b
Correct Topic type
spacesailor24 Nov 20, 2021
03b0a0e
Refactor isFilterObject
spacesailor24 Nov 20, 2021
fdb30dd
Init InvalidHexString8Bytes
spacesailor24 Nov 22, 2021
291e716
Init isHexString8Bytes and validateHexString8Bytes
spacesailor24 Nov 22, 2021
aceb8d2
Init test data for HexString8Bytes
spacesailor24 Nov 22, 2021
f4d040f
Init tests for isHexString8Bytes and validateHexString8Bytes
spacesailor24 Nov 22, 2021
a9bf857
Correct validation methods
spacesailor24 Nov 22, 2021
63ece01
Init tests for rpc_methods_with_params
spacesailor24 Nov 22, 2021
71bce83
Init web3-eth validation method tests and fixtures
spacesailor24 Nov 23, 2021
2b7e34b
Init remaining rpc method tests
spacesailor24 Nov 23, 2021
20025d5
Merge branch '4.x' into wyatt/4.x/4483-eth-rpc-methods
spacesailor24 Nov 23, 2021
b4c1400
Fix failing test
spacesailor24 Nov 23, 2021
c7933b3
Update tools/eslint-config-web3-base/ts.js
spacesailor24 Nov 23, 2021
e89b6a0
Add inline eslint disables for no-nested-ternary
spacesailor24 Nov 23, 2021
bf5f087
Merge branch '4.x' into wyatt/4.x/4483-eth-rpc-methods
spacesailor24 Nov 29, 2021
7ecc37b
Replace 8byte and 32byte hex string errors with InvalidHexStringError
spacesailor24 Nov 30, 2021
6e20693
Add Error suffix to custom error classes
spacesailor24 Nov 30, 2021
ca25da4
Update use of substr with startsWith
spacesailor24 Nov 30, 2021
2d6fe10
Remove explicit declaration of generic values for rpc_methods.ts
spacesailor24 Nov 30, 2021
f1b9562
Update RpcMethods to rpcMethods. Disable default-param-last eslint rule
spacesailor24 Nov 30, 2021
740197b
Move ConfigOptions from web3_config to web3-core/src/types.ts
spacesailor24 Dec 2, 2021
872f48a
Tiny change: rpc_methods_no_params to rpc_methods_no_parameters
spacesailor24 Dec 2, 2021
9f882db
Tiny change: rpc_methods_with_params to rpc_methods_with_parameters
spacesailor24 Dec 2, 2021
9d02fb1
Add validation checks and corresponding errors to convertToValidType …
spacesailor24 Dec 2, 2021
21e5779
Init errors for validation of convertToValidType and convertObjectPro…
spacesailor24 Dec 2, 2021
4bf43f6
Fix bug with validation of isBlockNumberOrTag
spacesailor24 Dec 2, 2021
ebaa3a6
Init tests and fixture data for convertToValidType and convertObjectP…
spacesailor24 Dec 2, 2021
d988282
Add support for initializing Web3Context with user defined values (NE…
spacesailor24 Dec 2, 2021
afa6a4b
WIP Adding Web3Context, writing tests, creating custom transaction ty…
spacesailor24 Dec 2, 2021
e8d834c
Update type of transaction in Block to TransactionInfo from Transacti…
spacesailor24 Dec 5, 2021
59e3853
Init BlockFormatted type
spacesailor24 Dec 5, 2021
82201fc
Init BlockFormatted type
spacesailor24 Dec 6, 2021
bdcdf59
Init web3_eth_methods fixtures
spacesailor24 Dec 6, 2021
e4dcf8c
web3_eth_methods_no_parameters.test.ts
spacesailor24 Dec 6, 2021
8f59d01
WIP web3_eth_methods_with_parameters.test.ts
spacesailor24 Dec 6, 2021
55494d3
WIP writing tests for web3-eth and correcting types
spacesailor24 Dec 6, 2021
c519e5c
Formatting
spacesailor24 Dec 7, 2021
f905d27
Add formatted transaction, receipt, and feeHistoryResult interfaces
spacesailor24 Dec 7, 2021
f5c46d8
Init remaining tests and fixtures for methods with returnType
spacesailor24 Dec 7, 2021
c1935fa
Init tests for web3-eth methods with parameters but no returnType
spacesailor24 Dec 7, 2021
76060fb
Solve merge conflicts, ran yarn, revert eslint to ^7.32.0
spacesailor24 Dec 7, 2021
0ff0e95
Add prefix option to isHexXBytes validation methods
spacesailor24 Dec 7, 2021
4ca1169
Refactor validateNumbersInput (break into smaller methods)
spacesailor24 Dec 8, 2021
1b3e6cd
Init convertibleTransactionProperties
spacesailor24 Dec 9, 2021
f851d61
WIP transaction formatters
spacesailor24 Dec 9, 2021
e10d00a
Add ChainNames to Transaction interface
spacesailor24 Dec 9, 2021
83b3a15
Add generic FormattedType to convertObjectPropertiesToValidType. Upda…
spacesailor24 Dec 13, 2021
f0a3cad
Comment out estimateGas test - will be re-implemented later with tran…
spacesailor24 Dec 13, 2021
82efb35
Update types to unknown instead of any for isValidString and isBuffer
spacesailor24 Dec 13, 2021
380926f
Remove estimateGas test - will be re-implemented later
spacesailor24 Dec 13, 2021
1d1366c
remove normalize and fill transaction methods
spacesailor24 Dec 13, 2021
aa69a85
Refactor Web3Eth to extend Web3Context
spacesailor24 Dec 13, 2021
8f94363
WIP init remaining Web3Eth methods from 1.x
spacesailor24 Dec 13, 2021
215c2c5
Add return type formatting to added Web3Eth methods
spacesailor24 Dec 14, 2021
50d65be
Yarn format
spacesailor24 Dec 14, 2021
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"devDependencies": {
"@types/node": "*",
"eslint": "^8.3.0",
"eslint": "^7.32.0",
"husky": "^7.0.4",
"jest": "^27.3.1",
"lerna": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@types/jest": "^27.0.3",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"eslint": "^8.3.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-web3-base": "0.1.0",
"eslint-plugin-import": "^2.25.3",
Expand Down
21 changes: 6 additions & 15 deletions packages/web3-common/src/eth_execution_api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Address,
BlockNumberOrTag,
HexString,
HexString256Bytes,
HexString8Bytes,
Expand All @@ -8,6 +9,8 @@ import {
HexStringSingleByte,
Uint,
Uint256,
Topic,
Filter,
} from 'web3-utils';

// The types are generated manually by referring to following doc
Expand All @@ -20,9 +23,8 @@ export interface AccessListEntry {
export type AccessList = AccessListEntry[];
export type TransactionHash = HexString;
export type Uncles = HexString32Bytes[];
export type BlockTag = 'earliest' | 'latest' | 'pending';
export type BlockNumberOrTag = Uint | BlockTag;

// TODO Should probably support EIP-2930 and EIP-1559
export interface TransactionCall {
readonly from?: Address;
readonly to: Address;
Expand Down Expand Up @@ -118,14 +120,11 @@ export interface Block {
readonly totalDifficulty: Uint;
readonly baseFeePerGas?: Uint;
readonly size: Uint;
readonly transactions: TransactionHash[] | TransactionSigned[];
readonly transactions: TransactionHash[] | TransactionInfo[];
readonly uncles: Uncles;
readonly hash: HexString32Bytes | null;
}

// https://github.com/ethereum/execution-apis/blob/main/src/schemas/filter.json#L59
export type Topic = HexString256Bytes;

// https://github.com/ethereum/execution-apis/blob/main/src/schemas/receipt.json#L2
export interface Log {
readonly removed?: boolean;
Expand All @@ -142,7 +141,7 @@ export interface Log {
// https://github.com/ethereum/execution-apis/blob/main/src/schemas/receipt.json#L44
export interface ReceiptInfo {
readonly transactionHash: HexString32Bytes;
readonly transactionIndex: HexString32Bytes;
readonly transactionIndex: Uint;
readonly blockHash: HexString32Bytes;
readonly blockNumber: Uint;
readonly from: Address;
Expand All @@ -168,14 +167,6 @@ export interface FeeHistoryResult {
readonly reward: number[][];
}

// https://github.com/ethereum/execution-apis/blob/main/src/schemas/filter.json#L28
export interface Filter {
readonly fromBlock?: BlockNumberOrTag;
readonly toBlock?: BlockNumberOrTag;
readonly address?: Address | Address[];
readonly topics?: (Topic | Topic[] | null)[];
}

// https://github.com/ethereum/execution-apis/blob/main/src/schemas/filter.json#L2
export type FilterResults = HexString32Bytes[] | Log[];

Expand Down
13 changes: 2 additions & 11 deletions packages/web3-common/src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
toNumber,
toUtf8,
utf8ToHex,
isBlockTag,
} from 'web3-utils';
import { FormatterError } from './errors';
import {
Expand All @@ -28,7 +29,6 @@ import {
Mutable,
LogsInput,
LogsOutput,
PredefinedBlockNumbers,
} from './types';

/**
Expand All @@ -50,14 +50,6 @@ export const outputProofFormatter = (proof: Proof): Proof => ({
*/
export const outputBigIntegerFormatter = (number: Numbers) => toNumber(number);

/**
* Returns true if the given blockNumber is 'latest', 'pending', or 'earliest.
*/
export const isPredefinedBlockNumber = (blockNumber: string) =>
PredefinedBlockNumbers.LATEST === blockNumber ||
PredefinedBlockNumbers.PENDING === blockNumber ||
PredefinedBlockNumbers.EARLIEST === blockNumber;

/**
* Returns the given block number as hex string or the predefined block number 'latest', 'pending', 'earliest', 'genesis'
*/
Expand All @@ -66,15 +58,14 @@ export const inputBlockNumberFormatter = (blockNumber: Numbers | undefined) => {
return undefined;
}

if (typeof blockNumber === 'string' && isPredefinedBlockNumber(blockNumber)) {
if (typeof blockNumber === 'string' && isBlockTag(blockNumber)) {
return blockNumber;
}

if (blockNumber === 'genesis') {
return '0x0';
}

// eslint-disable-next-line no-nested-ternary
if (typeof blockNumber === 'string' && isHexStrict(blockNumber)) {
return blockNumber.toLowerCase();
}
Expand Down
6 changes: 0 additions & 6 deletions packages/web3-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,6 @@ export interface SyncOutput {
readonly pulledStates?: bigint | number;
}

export enum PredefinedBlockNumbers {
LATEST = 'latest',
PENDING = 'pending',
EARLIEST = 'earliest',
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Web3APISpec = Record<string, (...params: any) => any>;
export type Web3APIMethod<T extends Web3APISpec> = string & keyof T;
Expand Down
33 changes: 6 additions & 27 deletions packages/web3-common/test/unit/formatters.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import * as utils from 'web3-utils';

import { PredefinedBlockNumbers } from '../../src/types';
import {
inputAddressFormatter,
inputBlockNumberFormatter,
inputDefaultBlockNumberFormatter,
inputPostFormatter,
isPredefinedBlockNumber,
outputBigIntegerFormatter,
outputBlockFormatter,
outputLogFormatter,
Expand Down Expand Up @@ -71,36 +69,17 @@ describe('formatters', () => {
});
});

describe('isPredefinedBlockNumber', () => {
it('should return true for "latest"', () => {
expect(isPredefinedBlockNumber('latest')).toBeTruthy();
});

it('should return true for "pending"', () => {
expect(isPredefinedBlockNumber('pending')).toBeTruthy();
});

it('should return true for "earliest"', () => {
expect(isPredefinedBlockNumber('earliest')).toBeTruthy();
});

it('should return false for "unknown"', () => {
expect(isPredefinedBlockNumber('unknown')).toBeFalsy();
});
});

describe('inputBlockNumberFormatter', () => {
it('should return undefined if block number not given', () => {
expect(inputBlockNumberFormatter(undefined)).toBeUndefined();
});

it.each([
PredefinedBlockNumbers.EARLIEST,
PredefinedBlockNumbers.LATEST,
PredefinedBlockNumbers.PENDING,
])('should return "%s" values for "%s" block numbers', blockNumber => {
expect(inputBlockNumberFormatter(blockNumber)).toEqual(blockNumber);
});
it.each([utils.BlockTags.EARLIEST, utils.BlockTags.LATEST, utils.BlockTags.PENDING])(
'should return "%s" values for "%s" block numbers',
blockNumber => {
expect(inputBlockNumberFormatter(blockNumber)).toEqual(blockNumber);
},
);

it('should return valid genesis block number', () => {
expect(inputBlockNumberFormatter('genesis')).toBe('0x0');
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@types/jest-when": "^2.7.3",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"eslint": "^8.3.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-web3-base": "0.1.0",
"eslint-plugin-import": "^2.25.3",
Expand Down
16 changes: 16 additions & 0 deletions packages/web3-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
JsonRpcResult,
Web3BaseProvider,
} from 'web3-common';
import { HexString, ValidTypes } from 'web3-utils';

export type LegacyRequestProvider = {
request: <R = JsonRpcResult, P = unknown>(
Expand Down Expand Up @@ -37,3 +38,18 @@ export type Web3BaseProviderConstructor = new <API extends Web3APISpec>(
url: string,
net?: Socket,
) => Web3BaseProvider<API>;

export interface ConfigOptions {
handleRevert: boolean;
defaultAccount: HexString | null;
defaultBlock: HexString;
transactionBlockTimeout: number;
transactionConfirmationBlocks: number;
transactionPollingTimeout: number;
blockHeaderTimeout: number;
maxListenersWarningThreshold: number;
defaultChain: string | null;
defaultHardfork: string | null;
defaultCommon: Record<string, unknown> | null;
defaultReturnType: ValidTypes;
}
31 changes: 17 additions & 14 deletions packages/web3-core/src/web3_config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import { HexString } from 'web3-utils';
import { ValidTypes } from 'web3-utils';
import { Web3EventEmitter } from 'web3-common';

interface ConfigOptions {
handleRevert: boolean;
defaultAccount: HexString | null;
defaultBlock: HexString;
transactionBlockTimeout: number;
transactionConfirmationBlocks: number;
transactionPollingTimeout: number;
blockHeaderTimeout: number;
maxListenersWarningThreshold: number;
defaultChain: string | null;
defaultHardfork: string | null;
defaultCommon: Record<string, unknown> | null;
}
import { ConfigOptions } from './types';

type ConfigEvent<T, P extends keyof T = keyof T> = P extends unknown
? { name: P; oldValue: T[P]; newValue: T[P] }
Expand All @@ -39,6 +27,7 @@ export abstract class Web3Config
defaultChain: null,
defaultHardfork: null,
defaultCommon: null,
defaultReturnType: ValidTypes.HexString,
};

public getConfig() {
Expand Down Expand Up @@ -193,4 +182,18 @@ export abstract class Web3Config

this._config.defaultCommon = val;
}

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

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

this._config.defaultReturnType = val;
}
}
15 changes: 13 additions & 2 deletions packages/web3-core/src/web3_context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Web3APISpec } from 'web3-common';
import { SupportedProviders } from './types';
import { ConfigOptions, SupportedProviders } from './types';
import { Web3Config } from './web3_config';
import { Web3RequestManager } from './web3_request_manager';

Expand All @@ -10,9 +10,20 @@ export class Web3Context<API extends Web3APISpec> extends Web3Config {

public readonly requestManager: Web3RequestManager<API>;

public constructor(provider: SupportedProviders<API> | string) {
public constructor(
provider: SupportedProviders<API> | string,
options?: Partial<ConfigOptions>,
) {
super();
this.requestManager = new Web3RequestManager<API>(provider);

if (options !== undefined)
for (const key of Object.keys(options)) {
// TODO
// @ts-expect-error Not sure how to type this
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this[key] = options[key];
}
}

public get currentProvider(): SupportedProviders<API> | string {
Expand Down
2 changes: 2 additions & 0 deletions packages/web3-core/test/unit/web3_config.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ValidTypes } from 'web3-utils';
import { Web3Config, Web3ConfigEvent } from '../../src/web3_config';

class MyConfigObject extends Web3Config {}
Expand All @@ -9,6 +10,7 @@ const defaultConfig = {
defaultChain: null,
defaultCommon: null,
defaultHardfork: null,
defaultReturnType: ValidTypes.HexString,
handleRevert: false,
maxListenersWarningThreshold: 100,
transactionBlockTimeout: 50,
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-abi/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface JsonAbiFunctionFragment extends JsonAbiBaseFragment {
outputs?: Array<JsonAbiParameter>;

// legacy properties
constant?: boolean; // stateMutability == 'pure' or stateMutability == 'view'
constant?: boolean; // stateMutability == 'pure' or stateMutability == 'view'
payable?: boolean; // stateMutability == 'payable'
}

Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@types/jest": "^27.0.3",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"eslint": "^8.3.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-web3-base": "0.1.0",
"eslint-plugin-import": "^2.25.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@types/jest": "^27.0.3",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"eslint": "^8.3.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-web3-base": "0.1.0",
"eslint-plugin-import": "^2.25.3",
Expand Down
7 changes: 6 additions & 1 deletion packages/web3-eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@types/jest": "^27.0.3",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"eslint": "^8.3.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-web3-base": "0.1.0",
"eslint-plugin-import": "^2.25.3",
Expand All @@ -37,5 +37,10 @@
"prettier": "^2.4.1",
"ts-jest": "^27.0.7",
"typescript": "^4.5.2"
},
"dependencies": {
"web3-common": "1.0.0-alpha.0",
"web3-core": "4.0.0-alpha.0",
"web3-utils": "4.0.0-alpha.0"
}
}
Loading