Skip to content

Commit

Permalink
Merge pull request #2 from electroneum/release/4.2.2
Browse files Browse the repository at this point in the history
Release/4.2.2
  • Loading branch information
andrepatta authored Nov 6, 2023
2 parents a14e938 + 0af1561 commit 220eaf2
Show file tree
Hide file tree
Showing 542 changed files with 1,630 additions and 1,771 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,10 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
- Interface `MetaMaskProvider` added and is part of `SupportedProviders` (#6534)
- `gasPrice` was added to `Transaction1559UnsignedAPI` type. (#6539)

#### web3-eth-accounts

- Added support for `ETNIP-1 PriorityTransactions`

### Changed

#### web3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This will give your plugin access to [requestManager](/api/web3-core/class/Web3C
:::caution

```ts
import { Web3PluginBase } from 'web3';
import { Web3PluginBase } from '@etn-sc/web3';

export default class CustomRpcMethodsPlugin extends Web3PluginBase {
// step 1
Expand All @@ -35,7 +35,7 @@ export default class CustomRpcMethodsPlugin extends Web3PluginBase {
2. After that add public `pluginNamespace` property. This will be used to access your plugin, as mentioned in step number 5 code example.

```ts
import { Web3PluginBase } from 'web3';
import { Web3PluginBase } from '@etn-sc/web3';

export default class CustomRpcMethodsPlugin extends Web3PluginBase {
public pluginNamespace = 'customRpcMethods'; // step 2
Expand All @@ -45,7 +45,7 @@ export default class CustomRpcMethodsPlugin extends Web3PluginBase {
3. Once plugin class is created using above mentioned steps, its very easy to add new RPC methods like:

```ts
import { Web3PluginBase } from 'web3';
import { Web3PluginBase } from '@etn-sc/web3';

export default class CustomRpcMethodsPlugin extends Web3PluginBase {
public pluginNamespace = 'customRpcMethods';
Expand All @@ -64,7 +64,7 @@ export default class CustomRpcMethodsPlugin extends Web3PluginBase {
4. Final step is setting up module [augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation), this will allow you to access plugin on web3 object.

```ts
import { Web3PluginBase } from 'web3';
import { Web3PluginBase } from '@etn-sc/web3';

export default class CustomRpcMethodsPlugin extends Web3PluginBase {
public pluginNamespace = 'customRpcMethods';
Expand Down Expand Up @@ -99,8 +99,8 @@ After the plugin is ready, it is recommended to publish it on the NPM registry.
Once plugin is registered its custom methods will be available to use.

```ts
import { Web3 } from 'web3';
import CustomRpcMethodsPlugin from 'web3-plugin-example';
import { Web3 } from '@etn-sc/web3';
import CustomRpcMethodsPlugin from '@etn-sc/web3-plugin-example';

const web3 = new Web3('http://127.0.0.1:8545');
web3.registerPlugin(new CustomRpcMethodsPlugin()); // step 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ For further information about `sideEffects` see [webpack docs](https://webpack.j
For example, if you need `web.eth`:

```ts
import Web3Eth from 'web3-eth';
import Web3Eth from '@etn-sc/web3-eth';
```

If you only need a few functions from `web3-utils`:

```ts
import { numberToHex, hexToNumber } from 'web3-utils';
import { numberToHex, hexToNumber } from '@etn-sc/web3-utils';
```

You can find an example app with tree shaking [here](https://github.com/ChainSafe/web3js-example-react-app).
8 changes: 4 additions & 4 deletions docs/docs/guides/basics/eth.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Note that we are installing the latest version of 4.x, at the time of this tutor
Next, create a new file called `index.ts` in your project directory and add the following code to it:

```javascript
const { Web3 } = require('web3'); // web3.js has native ESM builds and (`import Web3 from 'web3'`)
const { Web3 } = require('web3'); // web3.js has native ESM builds and (`import Web3 from '@etn-sc/web3'`)

// Set up a connection to the Ganache network
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));
Expand Down Expand Up @@ -99,7 +99,7 @@ In the first example, we are going to send a simple value transaction.
Create a file named `transaction.ts` and fill it with the following code:

```typescript
const { Web3 } = require('web3'); // web3.js has native ESM builds and (`import Web3 from 'web3'`)
const { Web3 } = require('web3'); // web3.js has native ESM builds and (`import Web3 from '@etn-sc/web3'`)
const fs = require('fs');
const path = require('path');

Expand Down Expand Up @@ -202,7 +202,7 @@ transactionHash {
In the next example, we are going to use `estimateGas` function to see the expected gas for contract deployment. (For more on contracts, please see the corresponding tutotial). Create a file named `estimate.ts` and fill it with the following code:

```typescript
import Web3, { ETH_DATA_FORMAT, DEFAULT_RETURN_FORMAT } from 'web3';
import Web3, { ETH_DATA_FORMAT, DEFAULT_RETURN_FORMAT } from '@etn-sc/web3';

async function estimate() {
// abi of our contract
Expand Down Expand Up @@ -284,7 +284,7 @@ If everything is working correctly, you should see something like the following:
In the next example we are going to sign a transaction and use `sendSignedTransaction` to send the signed transaction. Create a file named `sendSigned.ts` and fill it with the following code:

```typescript
import Web3 from 'web3';
import Web3 from '@etn-sc/web3';
const web3 = new Web3('http://localhost:7545');

//make sure to copy the private key from ganache
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/guides/basics/sign_and_send_tx/local_wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The simplest way to sign and send transactions is using a local wallet:

```ts
// First step: initialize `web3` instance
import Web3 from 'web3';
import Web3 from '@etn-sc/web3';
const web3 = new Web3(/* PROVIDER*/);

// Second step: add an account to wallet
Expand Down Expand Up @@ -45,7 +45,7 @@ List of references:

```ts
// First step: initialize `web3` instance
import Web3 from 'web3';
import Web3 from '@etn-sc/web3';
const web3 = new Web3(/* PROVIDER*/);

// Second step: add an account to wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If Ethereum node has unlocked account in its wallet you can send transaction wit

```ts
// First step: initialize web3 instance
import Web3 from 'web3';
import Web3 from '@etn-sc/web3';
const web3 = new Web3(/* PROVIDER*/);

// Second step: add an account to the Ethereum node and unlock it
Expand Down Expand Up @@ -54,7 +54,7 @@ List of references:

```ts
// First step: initialize web3 instance
import Web3 from 'web3';
import Web3 from '@etn-sc/web3';
const web3 = new Web3(/* PROVIDER*/);

// Second step: add an account to the Ethereum node and unlock it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Note that we are installing the latest version of 4.x, at the time of this tutor
Next, create a new file called `index.js` in your project directory and add the following code to it:

```javascript
const { Web3 } = require('web3'); // web3.js has native ESM builds and (`import Web3 from 'web3'`)
const { Web3 } = require('web3'); // web3.js has native ESM builds and (`import Web3 from '@etn-sc/web3'`)

// Set up a connection to the Ganache network
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));
Expand Down Expand Up @@ -214,7 +214,7 @@ Create a file named `deploy.js` and fill it with the following code:
```javascript
// For simplicity we use `web3` package here. However, if you are concerned with the size,
// you may import individual packages like 'web3-eth', 'web3-eth-contract' and 'web3-providers-http'.
const { Web3 } = require('web3'); // web3.js has native ESM builds and (`import Web3 from 'web3'`)
const { Web3 } = require('web3'); // web3.js has native ESM builds and (`import Web3 from '@etn-sc/web3'`)
const fs = require('fs');
const path = require('path');

Expand Down Expand Up @@ -289,7 +289,7 @@ In this step, we will use web3.js to interact with the smart contract on the Gan
Create a file named `interact.js` and fill it with the following code:

```javascript
const { Web3 } = require('web3'); // web3.js has native ESM builds and (`import Web3 from 'web3'`)
const { Web3 } = require('web3'); // web3.js has native ESM builds and (`import Web3 from '@etn-sc/web3'`)
const fs = require('fs');
const path = require('path');

Expand Down Expand Up @@ -369,7 +369,7 @@ Here are examples:
```typescript

// Configuring Web3Context with `contractDataInputFill`
import { Web3Context } from 'web3-core';
import { Web3Context } from '@etn-sc/web3-core';

const expectedProvider = 'http://127.0.0.1:8545';
const web3Context = new Web3Context({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Before we dive into the problem, let's take a quick look at the problem. Web3.js
Web3.js uses ABI type to dynamically load available methods and events but Typescript currently [doesn't support loading JSON as const](https://github.com/microsoft/TypeScript/issues/32063). If you go to the [Playground Link](https://www.typescriptlang.org/play?#code/MYewdgzgLgBAhgIwJYwLwwNoCga5gbxz1wCIkwAHAVyghIC5MjjdCWWywoBTAJzDgAbACoBPCtwYwS0XuQDmJADTN20gQFtJjEpu4B9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E8ZgWmaReP8vN1lElQCB+HA3RHAAanKOUJIeDEal18Xard3DAE8cALHqGFYWJXO5H5mMBYpJEPjTMWEz4gPAqroN4ODuSQ9taUZZQWUIA0h15UjhWnQMaOXvLE0AUrql8hp9PhMTcGky7nV0nmTvmcCvNq1mew7Bzgizu1gfzdruC66QdbkCL3Bi9wEuYV8A3PeNVVU8rfKq27Ogaz4Wv82DLGcclnGpTDOhjDUdSmzLdHCZbRUlY7dsVZg8dacCHzanLPcO3gU3cvnMZWAEwfSCXUEpDPscwH3eTV9DPHSNKcPmzGx1WyjNuld3V2C9RERROFQ9jfbucfdTfLT4EEEA1HyT+Ioy+r-rNc7ZvJDbwOgjC2BUO6o2Pl2DGI9V51h6JxQQABlKghpBDpWvi9Eed8cafWWpRF+wJ55zWcnzNa3VEpVy2r-Q2+14YHhAcjTuY90Y52xgWB+HUCZF0BA2N+Id4xIXsH7aq7Do7ENnrZeybV4K4NWuwVcAserAmZpAPcnsODD2vFgthk9NYgCvvg9WvDpBl1IQo8hbEoa13-g3E2ZtgF73btbQRECgJQM0awyBIi6r8K4SQFMIA0xGNjOTP8Qi87Ow4T4gxOgeiEOCfwimithE6PInTaJVI7KtTiUHL+Z8bLKN3HwAAYqmbOt8PGuK8aFPRZpfFxJMXI9aEMKGWL-ntdQmUm52LoQ40BTiHREEyPACAMB2jQAANxAA) and choose ".d.ts" you can check type difference with and without `as const`.

```typescript
import { Contract, Web3 } from 'web3';
import { Contract, Web3 } from '@etn-sc/web3';
import ERC20 from './node_modules/@openzeppelin/contracts/build/contracts/ERC20.json';

(async function () {
Expand Down Expand Up @@ -100,7 +100,7 @@ and run the script with `node -r ts-node/register <script name>.ts <destination>
use those generated files in your code:

```typescript
import { Contract, ContractAbi, Web3 } from 'web3';
import { Contract, ContractAbi, Web3 } from '@etn-sc/web3';
import ERC20 from './artifacts/ERC20';

(async function () {
Expand Down
22 changes: 11 additions & 11 deletions docs/docs/guides/web3_plugin_guide/plugin_authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ Furthermore, you have the flexibility to expand your range of transaction types,

```typescript
// create new TransactionType class which extends BaseTransaction class
import { BaseTransaction } from 'web3-eth-accounts';
import { BaseTransaction } from '@etn-sc/web3-eth-accounts';
const TRANSACTION_TYPE = 15;
class SomeNewTxTypeTransaction extends BaseTransaction {
// ...
}

// create new plugin and add `SomeNewTxTypeTransaction` to the library
import { Web3EthPluginBase } from 'web3';
import { Web3EthPluginBase } from '@etn-sc/web3';

class SomeNewTxTypeTransactionPlugin extends Web3PluginBase {
public pluginNamespace = 'someNewTxTypeTransaction';
Expand All @@ -64,7 +64,7 @@ class SomeNewTxTypeTransactionPlugin extends Web3PluginBase {
Your plugin class should `extend` the `Web3PluginBase` abstract class. This class `extends` [Web3Context](/api/web3-core/class/Web3Context) and when the user registers your plugin with a class, your plugin's `Web3Context` will point to the module's `Web3Context` giving your plugin access to things such as user configured [requestManager](/api/web3-core/class/Web3Context#requestManager) and [accountProvider](/api/web3-core/class/Web3Context#accountProvider).

```typescript
import { Web3PluginBase } from 'web3';
import { Web3PluginBase } from '@etn-sc/web3';

export class CustomRpcMethodsPlugin extends Web3PluginBase { ... }
```
Expand All @@ -74,7 +74,7 @@ export class CustomRpcMethodsPlugin extends Web3PluginBase { ... }
In addition to `Web3PluginBase`, you can choose to extend `Web3EthPluginBase` which will provide the [Ethereum JSON RPC API interface](/api/web3-types#EthExecutionAPI), which packages such as `Web3Eth` use, as a generic to your plugin's `requestManager`, giving it type support for the [Ethereum JSON RPC spec](https://ethereum.github.io/execution-apis/api-documentation/). This would be the recommended approach if your plugin makes Ethereum JSON RPC calls directly to a provider using web3's provided `requestManager`.

```typescript
import { Web3EthPluginBase } from 'web3';
import { Web3EthPluginBase } from '@etn-sc/web3';

export class CustomRpcMethodsPlugin extends Web3EthPluginBase { ... }
```
Expand All @@ -87,7 +87,7 @@ The following represents your plugin code:

```typescript
// custom_rpc_methods_plugin.ts
import { Web3PluginBase } from 'web3';
import { Web3PluginBase } from '@etn-sc/web3';

export class CustomRpcMethodsPlugin extends Web3PluginBase {
public pluginNamespace = 'customRpcMethods';
Expand All @@ -102,7 +102,7 @@ The following represents the plugin user's code:

```typescript
// registering_a_plugin.ts
import { Web3Context } from 'web3';
import { Web3Context } from '@etn-sc/web3';

import { CustomRpcMethodsPlugin } from './custom_rpc_methods_plugin';

Expand All @@ -117,7 +117,7 @@ await web3Context.customRpcMethods.someMethod();
Below is an example of `CustomRpcMethodsPlugin` making use of `this.requestManager` which will have access to an Ethereum provider if one was configured by the user. In the event that no `provider` was set by the user, the below code will throw a [ProviderError](/api/web3-errors/class/ProviderError) if `customRpcMethod` was to be called:

```typescript
import { Web3PluginBase } from 'web3';
import { Web3PluginBase } from '@etn-sc/web3';

export class CustomRpcMethodsPlugin extends Web3PluginBase {
public pluginNamespace = 'customRpcMethods';
Expand All @@ -135,7 +135,7 @@ Below depicts a plugin user's code that does not configure an Ethereum provider,

```typescript
// registering_a_plugin.ts
import { Web3Context } from 'web3';
import { Web3Context } from '@etn-sc/web3';

import { CustomRpcMethodsPlugin } from './custom_rpc_methods_plugin';

Expand All @@ -158,7 +158,7 @@ ProviderError: Provider not available. Use `.setProvider` or `.provider=` to ini
If needed, you can provide an API type (that follows the [Web3ApiSpec](/api/web3-types#Web3APISpec) pattern) as a generic to `Web3PluginBase` that will add type hinting to the `requestManager` when developing your plugin. In the below code, this is the `CustomRpcApi` type that's being passed as `Web3PluginBase<CustomRpcApi>`

```typescript
import { Web3PluginBase } from 'web3';
import { Web3PluginBase } from '@etn-sc/web3';

type CustomRpcApi = {
custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
Expand All @@ -185,7 +185,7 @@ There currently exists [an issue](https://github.com/web3/web3.js/issues/5492) w
A workaround for this issue is available, below is an example of it:

```typescript
import { Contract, ContractAbi, Web3Context, Web3PluginBase, types, utils } from 'web3';
import { Contract, ContractAbi, Web3Context, Web3PluginBase, types, utils } from '@etn-sc/web3';

import { ERC20TokenAbi } from './ERC20Token';

Expand Down Expand Up @@ -252,7 +252,7 @@ When registering a plugin, you're adding additional methods and/or classes to th

```typescript
// custom_rpc_methods_plugin.ts
import { Web3PluginBase } from 'web3';
import { Web3PluginBase } from '@etn-sc/web3';

export class CustomRpcMethodsPlugin extends Web3PluginBase {
public pluginNamespace = 'customRpcMethods';
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/guides/web3_plugin_guide/plugin_users.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ For illustration purposes, let's assume a plugin developer has the following cod
```typescript
// code written by the plugin **developer**

import { Web3PluginBase } from 'web3';
import { Web3PluginBase } from '@etn-sc/web3';

export class PluginExample extends Web3PluginBase {
public pluginNamespace = 'pluginExample';
Expand All @@ -55,8 +55,8 @@ Here is an example of how to register the `PluginExample` onto an instance of `W
```typescript
// code written by the plugin **user**

import Web3 from 'web3';
import PluginExample from 'web3-plugin-example';
import Web3 from '@etn-sc/web3';
import PluginExample from '@etn-sc/web3-plugin-example';

const web3 = new Web3('http://127.0.0.1:8545');
web3.registerPlugin(new PluginExample(any_parameters, if_needed));
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guides/web3_providers_guide/events_listening.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Actually, the events can be categorized as follows ([according to EIP 1193](http
Below a sample code for listening and remove listening to EIP 1193 events:

```ts
import Web3 from 'web3'
import Web3 from '@etn-sc/web3'

const web3 = new Web3(/* PROVIDER*/);

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guides/web3_providers_guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ web3.js providers are objects responsible for enabling connectivity with the Eth
Connecting to a chain happens through a provider. You can pass the provider to the constructor as in the following example:

```ts
import Web3 from 'web3';
import Web3 from '@etn-sc/web3';

const web3 = new Web3(/* PROVIDER*/);

Expand Down
16 changes: 8 additions & 8 deletions docs/docs/guides/web3_upgrade_guide/1.x/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,24 @@ We don't encourage using the `@types/web3` package.
```ts
// Provider types
// in 1.x
import type { Provider, Callback, JsonRPCResponse } from 'web3/providers';
import type { Provider, Callback, JsonRPCResponse } from '@etn-sc/web3/providers';

// in 4.x
import type {
Web3BaseProvider as Provider,
Web3ProviderRequestCallback as Callback,
JsonRpcResponse,
} from 'web3-types';
} from '@etn-sc/web3-types';
```

Similarly some useable types from the old package `web3-core` are also moved to `web3-types`

```ts
// in 1.x
import type { Transaction, TransactionReceipt } from 'web3-core';
import type { Transaction, TransactionReceipt } from '@etn-sc/web3-core';

// in 4.x
import type { Transaction, TransactionReceipt } from 'web3-types';
import type { Transaction, TransactionReceipt } from '@etn-sc/web3-types';
```

### Web3 Extend
Expand Down Expand Up @@ -196,10 +196,10 @@ Starting 4.x releases, the package `web3-core-helpers` will not be maintained an

```ts
// in 1.x
import { formatters } from 'web3-core-helpers';
import { formatters } from '@etn-sc/web3-core-helpers';

// in 4.x
import { formatters } from 'web3-core';
import { formatters } from '@etn-sc/web3-core';
```

### PromiEvent
Expand All @@ -208,10 +208,10 @@ Starting 4.x releases, the package `web3-core-promievent` will not be maintained

```ts
// in 1.x
import Web3PromiEvent from 'web3-core-promievent';
import Web3PromiEvent from '@etn-sc/web3-core-promievent';

// in 4.x
import { Web3PromiEvent } from 'web3-core';
import { Web3PromiEvent } from '@etn-sc/web3-core';
```

The `PromiEvent` class does not support `removeEventListener` or `addEventListener`. Instead we recommend to use `on` and `off`.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ You can use it by installing `web3-providers-ipc` and creating a new instance. S
you can pass it on to the Web3 instance.

```ts
import { IpcProvider } from 'web3-providers-ipc';
import { IpcProvider } from '@etn-sc/web3-providers-ipc';

const ipcProvider = new IpcProvider('/Users/myuser/Library/Ethereum/geth.ipc');
```
Expand Down
Loading

0 comments on commit 220eaf2

Please sign in to comment.