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

Enable the user to use only web3 as dependency #5771

Merged
merged 20 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d22fc0e
export web3 sub-packages and their default exports from `web3` package
Muhammad-Altabba Jan 20, 2023
5bc4071
Merge branch '4.x' into feature/5508/use-web3-as-only-dependency
Muhammad-Altabba Jan 22, 2023
39cc0d5
Merge branch '4.x' into feature/5508/use-web3-as-only-dependency
Muhammad-Altabba Jan 26, 2023
f74372c
export eth and providers sub-packages inside `eth` and `providers` na…
Muhammad-Altabba Jan 27, 2023
8b1c107
at web3-eth-accounts, rename `sign` and `signTransaction` to `signWit…
Muhammad-Altabba Jan 30, 2023
c7f9ad5
rename `Web3Error` interface to `Web3ErrorInterface`
Muhammad-Altabba Jan 30, 2023
a1da3d0
move all types from `/packages/web3-eth-abi/src/types.ts` to `web3-ty…
Muhammad-Altabba Jan 30, 2023
f90478f
fix import `AbiEventFragment`
Muhammad-Altabba Jan 30, 2023
a72431b
moved `TypedArray` to `web3-types`
Muhammad-Altabba Jan 30, 2023
e842d63
rename `Web3DeferredPromise` interface to `Web3DeferredPromiseInterface`
Muhammad-Altabba Jan 31, 2023
e0d4244
do a flat export for `web3-errors` and `web3-types` at `web3` package
Muhammad-Altabba Jan 31, 2023
faa5cd7
rename `Web3Error` to `BaseWeb3Error`
Muhammad-Altabba Jan 31, 2023
56f9391
revert naming change for signWithPrivateKey and signTransactionWithPr…
Muhammad-Altabba Feb 1, 2023
6ab11b1
update CHANGELOG.md for #5771
Muhammad-Altabba Feb 1, 2023
fda8a73
Merge remote-tracking branch 'origin/4.x' into feature/5508/use-web3-…
Muhammad-Altabba Feb 1, 2023
17f2dbd
export types defined at the `web3` package
Muhammad-Altabba Feb 1, 2023
8a02301
updates for the breaking change of using `require('web3')`
Muhammad-Altabba Feb 1, 2023
b06dcc3
Merge branch '4.x' into feature/5508/use-web3-as-only-dependency
Muhammad-Altabba Feb 2, 2023
a2afd9f
fix a broken documentation link
Muhammad-Altabba Feb 2, 2023
001a9bc
Merge branch '4.x' into feature/5508/use-web3-as-only-dependency
jdevcs Feb 2, 2023
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
56 changes: 53 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1139,16 +1139,66 @@ should use 4.0.1-alpha.0 for testing.

### Added

#### web3

- `registeredSubscriptions` was added by default in web3 constructor (#5792)
- Add named exports for all objects which are the default-exported-object in their packages (#5771)
- Export all packages' objects organized by namespaces (#5771)
- Add Additional flat exports for all types and constants from `web3-types`, `web3-errors` and `web3`. (#5771)

#### web3-core

- Added rpc exception codes following eip-1474 as an experimental feature (if `useRpcCallSpecification` at `enableExperimentalFeatures` is `true`) (#5525)

#### web3-providers-http

- Added named export for `HttpProvider` (#5771)

#### web3-providers-ipc

- Added named export for `IpcProvider` (#5771)

#### web3-providers-ws

- Added named export for `WebSocketProvider` (#5771)

#### web3-types

- Added types from `web3-eth-abi` and `TypedArray` from (#5771)
- Added `TypedArray` from `web3-utils` and `web3-validator` (it was defined twice) (#5771)

### Changed

#### web3

##### Removed
- `require('web3')` will now return all web3 exported-objects organized in namespaces . (#5771)

#### web3-errors

- The abstract class `Web3Error` is renamed to `BaseWeb3Error` (#5771)

#### web3-eth

- Update imports statements for objects that was moved between web3 packages (#5771)

#### web3-eth-contract

- Update imports statements for objects that was moved between web3 packages (#5771)

### Removed

#### web3

- Private static `_contracts:Contract[]` and static `setProvider` function was removed (#5792)

##### Added
#### web3-eth-abi

- `registeredSubscriptions` was added by default in web3 constructor (#5792)
- Moved all types and interfaces to `web3-types` (#5771)

#### web3-utils

- Moved `TypedArray` to `web3-types` (was also duplicated at `web3-validator`) (#5771)

#### web3-validator

- Moved `TypedArray` to `web3-types` (was also duplicated at `web3-utils`) (#5771)
21 changes: 21 additions & 0 deletions docs/docs/guides/web3_migration_guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ This migration guide is for migration from web3.js 1.x to web3.js 4.x.

## Breaking Changes

### The `web3` package will return all web3.js exported objects

`require('web3')` will now return all web3 exported-objects organized in namespaces (and few are available on top level). So, it is no longer supported to write the following code:

```ts
// This will return the name space and the line after it will throw an error!
const Web3 = require('web3');

const web3 = new Web3();
```

And the correct usage now is:

```ts
const { Web3 } = require('web3');

const web3 = new Web3();
```

### Passing Callbacks to functions

Passing callbacks to functions is no longer supported, except for event listeners.

### Not Implemented or Exported
Expand Down
6 changes: 6 additions & 0 deletions packages/web3-errors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- web3.js dependencies (#5757)

## [Unreleased]

### Changed

#### web3-errors

- The abstract class `Web3Error` is renamed to `BaseWeb3Error` (#5771)
20 changes: 10 additions & 10 deletions packages/web3-errors/src/errors/account_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,65 +28,65 @@ import {
ERR_IV_LENGTH,
ERR_PBKDF2_ITERATIONS,
} from '../error_codes';
import { Web3Error } from '../web3_error_base';
import { BaseWeb3Error } from '../web3_error_base';

export class PrivateKeyLengthError extends Web3Error {
export class PrivateKeyLengthError extends BaseWeb3Error {
public code = ERR_PRIVATE_KEY_LENGTH;
public constructor() {
super(`Private key must be 32 bytes.`);
}
}

export class InvalidPrivateKeyError extends Web3Error {
export class InvalidPrivateKeyError extends BaseWeb3Error {
public code = ERR_INVALID_PRIVATE_KEY;
public constructor() {
super(`Invalid Private Key, Not a valid string or buffer`);
}
}

export class InvalidSignatureError extends Web3Error {
export class InvalidSignatureError extends BaseWeb3Error {
public code = ERR_INVALID_SIGNATURE;
public constructor(errorDetails: string) {
super(`"${errorDetails}"`);
}
}

export class InvalidKdfError extends Web3Error {
export class InvalidKdfError extends BaseWeb3Error {
public code = ERR_UNSUPPORTED_KDF;
public constructor() {
super(`Invalid key derivation function`);
}
}

export class KeyDerivationError extends Web3Error {
export class KeyDerivationError extends BaseWeb3Error {
public code = ERR_KEY_DERIVATION_FAIL;
public constructor() {
super(`Key derivation failed - possibly wrong password`);
}
}

export class KeyStoreVersionError extends Web3Error {
export class KeyStoreVersionError extends BaseWeb3Error {
public code = ERR_KEY_VERSION_UNSUPPORTED;
public constructor() {
super('Unsupported key store version');
}
}

export class InvalidPasswordError extends Web3Error {
export class InvalidPasswordError extends BaseWeb3Error {
public code = ERR_INVALID_PASSWORD;
public constructor() {
super('Password cannot be empty');
}
}

export class IVLengthError extends Web3Error {
export class IVLengthError extends BaseWeb3Error {
public code = ERR_IV_LENGTH;
public constructor() {
super('Initialization vector must be 16 bytes');
}
}

export class PBKDF2IterationsError extends Web3Error {
export class PBKDF2IterationsError extends BaseWeb3Error {
public code = ERR_PBKDF2_ITERATIONS;
public constructor() {
super('c > 1000, pbkdf2 is less secure with less iterations');
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/connection_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import {
ERR_CONN_PENDING_REQUESTS,
ERR_REQ_ALREADY_SENT,
} from '../error_codes';
import { Web3Error } from '../web3_error_base';
import { BaseWeb3Error } from '../web3_error_base';

export class ConnectionError extends Web3Error {
export class ConnectionError extends BaseWeb3Error {
public code = ERR_CONN;
public errorCode?: number;
public errorReason?: string;
Expand Down
22 changes: 11 additions & 11 deletions packages/web3-errors/src/errors/contract_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import {
ERR_CONTRACT_RESERVED_EVENT,
ERR_CONTRACT_RESOLVER_MISSING,
} from '../error_codes';
import { Web3Error } from '../web3_error_base';
import { BaseWeb3Error } from '../web3_error_base';

export class Web3ContractError extends Web3Error {
export class Web3ContractError extends BaseWeb3Error {
public code = ERR_CONTRACT;
public receipt?: TransactionReceipt;

Expand All @@ -43,7 +43,7 @@ export class Web3ContractError extends Web3Error {
this.receipt = receipt;
}
}
export class ResolverMethodMissingError extends Web3Error {
export class ResolverMethodMissingError extends BaseWeb3Error {
public code = ERR_CONTRACT_RESOLVER_MISSING;

public constructor(public address: string, public name: string) {
Expand All @@ -55,7 +55,7 @@ export class ResolverMethodMissingError extends Web3Error {
}
}

export class ContractMissingABIError extends Web3Error {
export class ContractMissingABIError extends BaseWeb3Error {
public code = ERR_CONTRACT_ABI_MISSING;

public constructor() {
Expand All @@ -65,15 +65,15 @@ export class ContractMissingABIError extends Web3Error {
}
}

export class ContractOnceRequiresCallbackError extends Web3Error {
export class ContractOnceRequiresCallbackError extends BaseWeb3Error {
public code = ERR_CONTRACT_REQUIRED_CALLBACK;

public constructor() {
super('Once requires a callback as the second parameter.');
}
}

export class ContractEventDoesNotExistError extends Web3Error {
export class ContractEventDoesNotExistError extends BaseWeb3Error {
public code = ERR_CONTRACT_EVENT_NOT_EXISTS;

public constructor(public eventName: string) {
Expand All @@ -85,7 +85,7 @@ export class ContractEventDoesNotExistError extends Web3Error {
}
}

export class ContractReservedEventError extends Web3Error {
export class ContractReservedEventError extends BaseWeb3Error {
public code = ERR_CONTRACT_RESERVED_EVENT;

public constructor(public type: string) {
Expand All @@ -97,31 +97,31 @@ export class ContractReservedEventError extends Web3Error {
}
}

export class ContractMissingDeployDataError extends Web3Error {
export class ContractMissingDeployDataError extends BaseWeb3Error {
public code = ERR_CONTRACT_MISSING_DEPLOY_DATA;

public constructor() {
super(`No "data" specified in neither the given options, nor the default options.`);
}
}

export class ContractNoAddressDefinedError extends Web3Error {
export class ContractNoAddressDefinedError extends BaseWeb3Error {
public code = ERR_CONTRACT_MISSING_ADDRESS;

public constructor() {
super("This contract object doesn't have address set yet, please set an address first.");
}
}

export class ContractNoFromAddressDefinedError extends Web3Error {
export class ContractNoFromAddressDefinedError extends BaseWeb3Error {
public code = ERR_CONTRACT_MISSING_FROM_ADDRESS;

public constructor() {
super('No "from" address specified in neither the given options, nor the default options.');
}
}

export class ContractInstantiationError extends Web3Error {
export class ContractInstantiationError extends BaseWeb3Error {
public code = ERR_CONTRACT_INSTANTIATION;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/web3-errors/src/errors/core_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.

/* eslint-disable max-classes-per-file */

import { Web3Error } from '../web3_error_base';
import { BaseWeb3Error } from '../web3_error_base';
import { ERR_CORE_HARDFORK_MISMATCH } from '../error_codes';

export class ConfigHardforkMismatchError extends Web3Error {
export class ConfigHardforkMismatchError extends BaseWeb3Error {
public code = ERR_CORE_HARDFORK_MISMATCH;

public constructor(defaultHardfork: string, commonHardFork: string) {
Expand All @@ -30,7 +30,7 @@ export class ConfigHardforkMismatchError extends Web3Error {
}
}

export class ConfigChainMismatchError extends Web3Error {
export class ConfigChainMismatchError extends BaseWeb3Error {
public code = ERR_CORE_HARDFORK_MISMATCH;

public constructor(defaultHardfork: string, commonHardFork: string) {
Expand Down
8 changes: 4 additions & 4 deletions packages/web3-errors/src/errors/ens_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ import {
ERR_ENS_NETWORK_NOT_SYNCED,
ERR_ENS_UNSUPPORTED_NETWORK,
} from '../error_codes';
import { Web3Error } from '../web3_error_base';
import { BaseWeb3Error } from '../web3_error_base';

export class ENSCheckInterfaceSupportError extends Web3Error {
export class ENSCheckInterfaceSupportError extends BaseWeb3Error {
public code = ERR_ENS_CHECK_INTERFACE_SUPPORT;
public constructor(errorDetails: string) {
super(`ENS resolver check interface support error. "${errorDetails}"`);
}
}

export class ENSUnsupportedNetworkError extends Web3Error {
export class ENSUnsupportedNetworkError extends BaseWeb3Error {
public code = ERR_ENS_UNSUPPORTED_NETWORK;
public constructor(networkType: string) {
super(`ENS is not supported on network ${networkType}`);
}
}

export class ENSNetworkNotSyncedError extends Web3Error {
export class ENSNetworkNotSyncedError extends BaseWeb3Error {
public code = ERR_ENS_NETWORK_NOT_SYNCED;
public constructor() {
super(`Network not synced`);
Expand Down
16 changes: 8 additions & 8 deletions packages/web3-errors/src/errors/generic_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {
ERR_PARAM,
ERR_EXISTING_PLUGIN_NAMESPACE,
} from '../error_codes';
import { Web3Error } from '../web3_error_base';
import { BaseWeb3Error } from '../web3_error_base';

export class InvalidNumberOfParamsError extends Web3Error {
export class InvalidNumberOfParamsError extends BaseWeb3Error {
public code = ERR_PARAM;

public constructor(public got: number, public expected: number, public method: string) {
Expand All @@ -45,31 +45,31 @@ export class InvalidNumberOfParamsError extends Web3Error {
}
}

export class FormatterError extends Web3Error {
export class FormatterError extends BaseWeb3Error {
public code = ERR_FORMATTERS;
}

export class MethodNotImplementedError extends Web3Error {
export class MethodNotImplementedError extends BaseWeb3Error {
public code = ERR_METHOD_NOT_IMPLEMENTED;

public constructor() {
super("The method you're trying to call is not implemented.");
}
}

export class OperationTimeoutError extends Web3Error {
export class OperationTimeoutError extends BaseWeb3Error {
public code = ERR_OPERATION_TIMEOUT;
}

export class OperationAbortError extends Web3Error {
export class OperationAbortError extends BaseWeb3Error {
public code = ERR_OPERATION_ABORT;
}

export class AbiError extends Web3Error {
export class AbiError extends BaseWeb3Error {
public code = ERR_ABI_ENCODING;
}

export class ExistingPluginNamespaceError extends Web3Error {
export class ExistingPluginNamespaceError extends BaseWeb3Error {
public code = ERR_EXISTING_PLUGIN_NAMESPACE;

public constructor(pluginNamespace: string) {
Expand Down
Loading