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

Rename "API Providers" to "Providers" #453

Merged
merged 7 commits into from May 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions .changeset/pink-olives-accept.md
Expand Up @@ -6,13 +6,13 @@

**Passing a function to `connectors` has been deprecated.**

If you previously derived an RPC URL from the `chainId` in `connectors`, you will need to migrate to use the [`configureChains` API](https://wagmi.sh/docs/api-providers/configuring-chains).
If you previously derived an RPC URL from the `chainId` in `connectors`, you will need to migrate to use the [`configureChains` API](https://wagmi.sh/docs/providers/configuring-chains).

### Before

```tsx
import { providers } from 'ethers'
import { Provider, chain, createClient, defaultChains } from 'wagmi'
import { WagmiProvider, chain, createClient, defaultChains } from 'wagmi'
import { CoinbaseWalletConnector } from 'wagmi/connectors/coinbaseWallet'
import { InjectedConnector } from 'wagmi/connectors/injected'
import { MetaMaskConnector } from 'wagmi/connectors/metaMask'
Expand Down Expand Up @@ -59,10 +59,10 @@ const client = createClient({
### After

```tsx
import { Provider, chain, createClient, defaultChains } from 'wagmi'
import { WagmiProvider, chain, createClient, defaultChains } from 'wagmi'

import { alchemyProvider } from 'wagmi/apiProviders/alchemy'
import { publicProvider } from 'wagmi/apiProviders/public'
import { alchemyProvider } from 'wagmi/providers/alchemy'
import { publicProvider } from 'wagmi/providers/public'

import { CoinbaseWalletConnector } from 'wagmi/connectors/coinbaseWallet'
import { InjectedConnector } from 'wagmi/connectors/injected'
Expand Down
14 changes: 7 additions & 7 deletions .changeset/unlucky-deers-hammer.md
Expand Up @@ -5,17 +5,17 @@

Add `configureChains` API.

The `configureChains` function allows you to configure your chains with a selected API provider (Alchemy, Infura, JSON RPC, Public RPC URLs). This means you don't have to worry about deriving your own RPC URLs for each chain, or instantiating a Ethereum Provider.
The `configureChains` function allows you to configure your chains with a selected provider (Alchemy, Infura, JSON RPC, Public RPC URLs). This means you don't have to worry about deriving your own RPC URLs for each chain, or instantiating a Ethereum Provider.

`configureChains` accepts 3 parameters: an array of chains, and an array of API providers, and a config object.
`configureChains` accepts 3 parameters: an array of chains, and an array of providers, and a config object.

[Learn more about configuring chains & API providers.](https://wagmi.sh/docs/api-providers/configuring-chains)
[Learn more about configuring chains & providers.](https://wagmi.sh/docs/providers/configuring-chains)

### Before

```tsx
import { providers } from 'ethers'
import { Provider, chain, createClient, defaultChains } from 'wagmi'
import { WagmiProvider, chain, createClient, defaultChains } from 'wagmi'
import { CoinbaseWalletConnector } from 'wagmi/connectors/coinbaseWallet'
import { InjectedConnector } from 'wagmi/connectors/injected'
import { MetaMaskConnector } from 'wagmi/connectors/metaMask'
Expand Down Expand Up @@ -63,10 +63,10 @@ const client = createClient({
### After

```tsx
import { Provider, chain, createClient, defaultChains } from 'wagmi'
import { WagmiProvider, chain, createClient, defaultChains } from 'wagmi'

import { alchemyProvider } from 'wagmi/apiProviders/alchemy'
import { publicProvider } from 'wagmi/apiProviders/public'
import { alchemyProvider } from 'wagmi/providers/alchemy'
import { publicProvider } from 'wagmi/providers/public'

import { CoinbaseWalletConnector } from 'wagmi/connectors/coinbaseWallet'
import { InjectedConnector } from 'wagmi/connectors/injected'
Expand Down
2 changes: 1 addition & 1 deletion .config/hardhat.config.ts
Expand Up @@ -4,7 +4,7 @@ const config: HardhatUserConfig = {
networks: {
hardhat: {
forking: {
url: `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_ID}`,
url: `https://eth-mainnet.alchemyapi.io/v2/PjT72qifrAFZ4WV_drrd30N5onftY5VA`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shite

blockNumber: 14604308,
},
loggingEnabled: false,
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -55,15 +55,15 @@ npm install wagmi ethers
Connect a wallet in under 60 seconds. LFG.

```tsx
import { Provider, createClient } from 'wagmi'
import { WagmiProvider, createClient } from 'wagmi'

const client = createClient()

function App() {
return (
<Provider client={client}>
<WagmiProvider client={client}>
<Profile />
</Provider>
</WagmiProvider>
)
}
```
Expand Down
11 changes: 8 additions & 3 deletions docs/components/core/Providers.tsx
@@ -1,13 +1,18 @@
import * as React from 'react'

import { Provider, configureChains, createClient, defaultChains } from 'wagmi'
import {
WagmiProvider,
configureChains,
createClient,
defaultChains,
} from 'wagmi'

import { CoinbaseWalletConnector } from 'wagmi/connectors/coinbaseWallet'
import { InjectedConnector } from 'wagmi/connectors/injected'
import { MetaMaskConnector } from 'wagmi/connectors/metaMask'
import { WalletConnectConnector } from 'wagmi/connectors/walletConnect'

import { alchemyProvider } from '../../../packages/core/apiProviders/alchemy'
import { alchemyProvider } from '../../../packages/core/providers/alchemy'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we import this from the wagmi package entrypoint?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, tried to do this, but it was yelling at me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed now


const alchemyId = process.env.NEXT_PUBLIC_ALCHEMY_ID

Expand Down Expand Up @@ -45,5 +50,5 @@ type Props = {
}

export function Providers({ children }: Props) {
return <Provider client={client}>{children}</Provider>
return <WagmiProvider client={client}>{children}</WagmiProvider>
}
10 changes: 5 additions & 5 deletions docs/pages/docs/getting-started.en-US.mdx
Expand Up @@ -26,23 +26,23 @@ const client = createClient()
provider, and more, are [all configurable](/docs/client).
</Callout>

Next, wrap your app with the [`Provider`](/docs/provider) component, passing `client` to it.
Next, wrap your app with the [`WagmiProvider`](/docs/wagmi-provider) component, passing `client` to it.

```tsx {7-9}
import { Provider, createClient } from 'wagmi'
import { WagmiProvider, createClient } from 'wagmi'

const client = createClient()

function App() {
return (
<Provider client={client}>
<WagmiProvider client={client}>
<YourRoutes />
</Provider>
</WagmiProvider>
)
}
```

Finally, use hooks! Every component inside the `Provider` is now set up to use the wagmi hooks.
Finally, use hooks! Every component inside the `WagmiProvider` is now set up to use the wagmi hooks.

```tsx {5,6,7-9}
import { useAccount, useConnect, useEnsName } from 'wagmi'
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/docs/meta.en-US.json
Expand Up @@ -3,8 +3,8 @@
"comparison": "Library Comparison",
"migrating-to-03": "Migrating to 0.3.x",
"client": "Client",
"provider": "Provider",
"api-providers": "API Providers",
"wagmi-provider": "WagmiProvider",
"providers": "Providers",
"connectors": "Connectors",
"hooks": "Hooks",
"constants": "Constants"
Expand Down
Expand Up @@ -5,14 +5,14 @@ import Callout from 'nextra-theme-docs/callout'
The `alchemyProvider` configures the chains with Alchemy RPC URLs and also provides an [ethers.js `AlchemyProvider`](https://docs.ethers.io/v5/api/providers/api-providers/#AlchemyProvider).

```ts
import { alchemyProvider } from 'wagmi/apiProviders/alchemy'
import { alchemyProvider } from 'wagmi/providers/alchemy'
```

## Usage

```ts
import { configureChains, chain } from 'wagmi'
import { alchemyProvider } from 'wagmi/apiProviders/alchemy'
import { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/providers/alchemy'

const alchemyId = process.env.ALCHEMY_ID

Expand Down Expand Up @@ -41,8 +41,8 @@ Your Alchemy ID from the [Alchemy Dashboard](https://dashboard.alchemyapi.io/).
If no Alchemy ID is provided, it will use the public Alchemy ID. It is recommended to provide your own Alchemy ID to prevent being rate-limited.

```ts {8}
import { configureChains, chain } from 'wagmi'
import { alchemyProvider } from 'wagmi/apiProviders/alchemy'
import { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/providers/alchemy'

const alchemyId = process.env.ALCHEMY_ID

Expand Down
Expand Up @@ -2,24 +2,24 @@ import Callout from 'nextra-theme-docs/callout'

# Configuring Chains

The `configureChains` function allows you to configure your chains with API providers such as: Alchemy, Infura, or something else. This means you don't need to worry about defining RPC URLs and chain configuration in your [connector](/docs/connectors/walletconnect#options) or [provider](/docs/client#provider-optional). This is managed internally by wagmi.
The `configureChains` function allows you to configure your chains with providers such as: Alchemy, Infura, or something else. This means you don't need to worry about defining RPC URLs and chain configuration in your [connector](/docs/connectors/walletconnect#options) or [provider](/docs/client#provider-optional). This is managed internally by wagmi.

```ts
import { configureChains } from 'wagmi'
```

## Usage

`configureChains` accepts an array of chains and an array of API providers. It returns:
`configureChains` accepts an array of chains and an array of providers. It returns:

- `chains`: to pass to your connector(s)
- `provider`: to pass to `createClient`
- `webSocketProvider`: to optionally pass to `createClient`

```ts
import { configureChains, defaultChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/apiProviders/alchemy'
import { publicProvider } from 'wagmi/apiProviders/public'
import { alchemyProvider } from 'wagmi/providers/alchemy'
import { publicProvider } from 'wagmi/providers/public'
import { InjectedConnector } from 'wagmi/connectors/injected'

const alchemyId = process.env.ALCHEMY_ID
Expand All @@ -46,19 +46,19 @@ const wagmiClient = createClient({
app, the `provider` will use the first chain listed in the `chains` array.
</Callout>

### Multiple API providers
### Multiple providers

The `configureChains` function accepts multiple API Providers. This is useful if not all your chains support a single API provider. For example, you may want to use [Alchemy](https://alchemy.com) for Ethereum, and [avax.network](https://avax.network) for Avalanche.
The `configureChains` function accepts multiple providers. This is useful if not all your chains support a single provider. For example, you may want to use [Alchemy](https://alchemy.com) for Ethereum, and [avax.network](https://avax.network) for Avalanche.

`configureChains` wraps the API providers that you provide into an [ethers.js `FallbackProvider`](https://docs.ethers.io/v5/api/providers/other/#FallbackProvider), that comes with support for:
`configureChains` wraps the providers that you provide into an [ethers.js `FallbackProvider`](https://docs.ethers.io/v5/api/providers/other/#FallbackProvider), that comes with support for:

- Falling back to another provider if a provider goes down (e.g. If Infura goes down, we can fall back to Alchemy)
- Ensuring the responses are legitimate by setting a `targetQuorum`.

```ts
import { Chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/apiProviders/alchemy'
import { staticJsonRpcProvider } from 'wagmi/apiProviders/staticJsonRpc'
import { alchemyProvider } from 'wagmi/providers/alchemy'
import { staticJsonRpcProvider } from 'wagmi/providers/staticJsonRpc'

const alchemyId = process.env.ALCHEMY_ID
const infuraId = process.env.INFURA_ID
Expand Down Expand Up @@ -98,7 +98,7 @@ const { provider, chains } = configureChains(

#### Quorum

If the `targetQuorum` option is set to a value greater than `1`, it will dispatch interactions to multiple API providers, in which the responses are verified by comparing them to each other. If the quorum is reached, then the result will be returned to the consumer.
If the `targetQuorum` option is set to a value greater than `1`, it will dispatch interactions to multiple providers, in which the responses are verified by comparing them to each other. If the quorum is reached, then the result will be returned to the consumer.

```tsx
const { provider, chains } = configureChains(
Expand Down Expand Up @@ -131,24 +131,24 @@ Chains that need to be configured.

```ts {5}
import { chain, configureChains } from 'wagmi'
import { publicProvider } from 'wagmi/apiProviders/public'
import { publicProvider } from 'wagmi/providers/public'

const { chains } = configureChains(
[chain.mainnet, chain.optimism],
[publicProvider()],
)
```

### apiProviders
### providers

The API providers the app supports.
The providers the app supports.

If an API provider does not support a chain, it will fall back onto the next one in the array. If no RPC URLs are found, `configureChains` will throw an error.
If a provider does not support a chain, it will fall back onto the next one in the array. If no RPC URLs are found, `configureChains` will throw an error.

```ts {9}
import { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/apiProviders/alchemy'
import { publicProvider } from 'wagmi/apiProviders/public'
import { alchemyProvider } from 'wagmi/providers/alchemy'
import { publicProvider } from 'wagmi/providers/public'

const alchemyId = process.env.ALCHEMY_ID

Expand All @@ -166,8 +166,8 @@ Sets the target quorum. Defaults to `1`.

```ts {15}
import { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/apiProviders/alchemy'
import { publicProvider } from 'wagmi/apiProviders/public'
import { alchemyProvider } from 'wagmi/providers/alchemy'
import { publicProvider } from 'wagmi/providers/public'

const alchemyId = process.env.ALCHEMY_ID
const infuraId = process.env.INFURA_ID
Expand All @@ -185,12 +185,12 @@ const { chains } = configureChains(

#### minQuorum (optional)

Sets the minimum quorum that must be accepted by the API providers. Defaults to `1`.
Sets the minimum quorum that must be accepted by the providers. Defaults to `1`.

```ts {15}
import { chain, configureChains } from 'wagmi'
import { alchemyProvider } from 'wagmi/apiProviders/alchemy'
import { publicProvider } from 'wagmi/apiProviders/public'
import { alchemyProvider } from 'wagmi/providers/alchemy'
import { publicProvider } from 'wagmi/providers/public'

const alchemyId = process.env.ALCHEMY_ID
const infuraId = process.env.INFURA_ID
Expand Down
Expand Up @@ -5,14 +5,14 @@ import Callout from 'nextra-theme-docs/callout'
The `infuraProvider` configures the chains with Infura RPC URLs and also provides an [ethers.js `InfuraProvider`](https://docs.ethers.io/v5/api/providers/api-providers/#InfuraProvider).

```ts
import { infuraProvider } from 'wagmi/apiProviders/infura'
import { infuraProvider } from 'wagmi/providers/infura'
```

## Usage

```ts
import { configureChains, chain } from 'wagmi'
import { infuraProvider } from 'wagmi/apiProviders/infura'
import { chain, configureChains } from 'wagmi'
import { infuraProvider } from 'wagmi/providers/infura'

const infuraId = process.env.INFURA_ID

Expand Down Expand Up @@ -41,8 +41,8 @@ Your Infura ID from the [Infura Dashboard](https://infura.io/login).
If no Infura ID is provided, it will use the public Infura ID. It is recommended to provide your own Infura ID to prevent being rate-limited.

```ts {6}
import { configureChains, chain } from 'wagmi'
import { infuraProvider } from 'wagmi/apiProviders/infura'
import { chain, configureChains } from 'wagmi'
import { infuraProvider } from 'wagmi/providers/infura'

const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
Expand Down
Expand Up @@ -5,14 +5,14 @@ import Callout from 'nextra-theme-docs/callout'
The `staticJsonRpcProvider` configures the chains with the RPC URLs that you specify and also provides an [ethers.js `StaticJsonRpcProvider`](https://docs.ethers.io/v5/api/providers/jsonrpc-provider/#StaticJsonRpcProvider).

```ts
import { staticJsonRpcProvider } from 'wagmi/apiProviders/staticJsonRpc'
import { staticJsonRpcProvider } from 'wagmi/providers/staticJsonRpc'
```

## Usage

```ts
import { configureChains, chain } from 'wagmi'
import { staticJsonRpcProvider } from 'wagmi/apiProviders/staticJsonRpc'
import { chain, configureChains } from 'wagmi'
import { staticJsonRpcProvider } from 'wagmi/providers/staticJsonRpc'

const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
Expand Down Expand Up @@ -43,8 +43,8 @@ const { chains, provider } = configureChains(
Accepts a function which provides the `chain` and expects to receive an `rpcUrl` and optionally a `webSocketRpcUrl`.

```tsx {8-11}
import { configureChains, chain } from 'wagmi'
import { staticJsonRpcProvider } from 'wagmi/apiProviders/staticJsonRpc'
import { chain, configureChains } from 'wagmi'
import { staticJsonRpcProvider } from 'wagmi/providers/staticJsonRpc'

const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
Expand Down
Expand Up @@ -5,14 +5,14 @@ import Callout from 'nextra-theme-docs/callout'
The `publicProvider` configures the chains with a public RPC URL and also provides an [ethers.js `getpublicProvider`](https://docs.ethers.io/v5/api/providers/#providers-getpublicProvider).

```ts
import { publicProvider } from 'wagmi/apiProviders/public'
import { publicProvider } from 'wagmi/providers/public'
```

## Usage

```ts
import { configureChains, chain } from 'wagmi'
import { publicProvider } from 'wagmi/apiProviders/public'
import { chain, configureChains } from 'wagmi'
import { publicProvider } from 'wagmi/providers/public'

const { chains, provider } = configureChains(
[chain.mainnet, chain.polygon],
Expand All @@ -21,9 +21,9 @@ const { chains, provider } = configureChains(
```

<Callout emoji="⚠️">
Only having `publicProvider` in your API providers will make the chain use the
Only having `publicProvider` in your providers will make the chain use the
public RPC URL which could lead to rate-limiting. It is recommended to also
include another API provider in your list (such as: `alchemyProvider`,
include another provider in your list (such as: `alchemyProvider`,
`infuraProvider` or `staticJsonRpcProvider`).
</Callout>

Expand Down