Skip to content

Commit

Permalink
few edits at providers guides
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad-Altabba committed Mar 13, 2023
1 parent 76dbe86 commit d586feb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ In 4.x the third parameter is called `reconnectOptions` that is of the type `Rec

```ts
// this is the same options interface used for both WebSocketProvider and IpcProvider
export type ReconnectOptions = {
autoReconnect: boolean;
delay: number;
maxAttempts: number;
type ReconnectOptions = {
autoReconnect: boolean; // default: `true`
delay: number; // default: `5000`
maxAttempts: number; // default: `5`
};
```

Expand Down
31 changes: 9 additions & 22 deletions docs/docs/guides/web3_providers_guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,14 @@ The options object is of type `ClientRequestArgs` or of `ClientOptions`. See [he
The second option parameter can be given regarding reconnecting. And here is its type:

```ts
// this is the same options interface used for both WebSocketProvider and IpcProvider
type ReconnectOptions = {
autoReconnect: boolean;
delay: number;
maxAttempts: number;
autoReconnect: boolean; // default: `true`
delay: number; // default: `5000`
maxAttempts: number; // default: `5`
};
```

:::info
Here is how to catch the error if max attempts reached when the auto reconnecting:

```ts
provider.on('error', errorMessage => {
if (errorMessage.startsWith('Maximum number of reconnect attempts reached!')) {
// the `errorMessage` will be `Maximum number of reconnect attempts reached! (${maxAttempts})`
// the `maxAttempts` is equal to the provided value by the user or the default `5`.
}
});
```

And here is a sample instantiation for the `WebSocketProvider`:

```ts
Expand Down Expand Up @@ -201,8 +190,6 @@ const provider = new WebSocketProvider(
);
```

:::

##### Options example

Below is an example for the passed options:
Expand Down Expand Up @@ -243,10 +230,10 @@ And, the third parameter is called `reconnectOptions` that is of the type `Recon

```ts
// this is the same options interface used for both WebSocketProvider and IpcProvider
export type ReconnectOptions = {
autoReconnect: boolean;
delay: number;
maxAttempts: number;
type ReconnectOptions = {
autoReconnect: boolean; // default: `true`
delay: number; // default: `5000`
maxAttempts: number; // default: `5`
};
```

Expand Down Expand Up @@ -300,7 +287,7 @@ const provider = new IpcProvider(

#### Error message for reconnect attempts

:::note
:::info
This section applies for both `IpcProvider` and `WebSocketProvider`.
:::

Expand Down

0 comments on commit d586feb

Please sign in to comment.