From 692fbd310b62f8554c97370171f7f3f97a188521 Mon Sep 17 00:00:00 2001 From: Noy <59097122+noyyyy@users.noreply.github.com> Date: Tue, 31 Jan 2023 02:34:13 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=83=20docs(cn):=20translate=20docs/pag?= =?UTF-8?q?es/react/providers=20to=20zh-CN=20(#1742)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/pages/react/_meta.zh-CN.json | 3 +- docs/pages/react/providers/_meta.zh-CN.json | 7 + docs/pages/react/providers/alchemy.zh-CN.mdx | 122 ++++++++++ .../providers/configuring-chains.zh-CN.mdx | 209 ++++++++++++++++++ docs/pages/react/providers/infura.zh-CN.mdx | 122 ++++++++++ docs/pages/react/providers/jsonRpc.zh-CN.mdx | 156 +++++++++++++ docs/pages/react/providers/public.zh-CN.mdx | 95 ++++++++ 7 files changed, 712 insertions(+), 2 deletions(-) create mode 100644 docs/pages/react/providers/_meta.zh-CN.json create mode 100644 docs/pages/react/providers/alchemy.zh-CN.mdx create mode 100644 docs/pages/react/providers/configuring-chains.zh-CN.mdx create mode 100644 docs/pages/react/providers/infura.zh-CN.mdx create mode 100644 docs/pages/react/providers/jsonRpc.zh-CN.mdx create mode 100644 docs/pages/react/providers/public.zh-CN.mdx diff --git a/docs/pages/react/_meta.zh-CN.json b/docs/pages/react/_meta.zh-CN.json index 9eb85668e7..40a905c921 100644 --- a/docs/pages/react/_meta.zh-CN.json +++ b/docs/pages/react/_meta.zh-CN.json @@ -24,8 +24,7 @@ "display": "hidden" }, "providers": { - "title": "Providers", - "display": "hidden" + "title": "Providers" }, "connectors": { "title": "Connectors", diff --git a/docs/pages/react/providers/_meta.zh-CN.json b/docs/pages/react/providers/_meta.zh-CN.json new file mode 100644 index 0000000000..68ce93f132 --- /dev/null +++ b/docs/pages/react/providers/_meta.zh-CN.json @@ -0,0 +1,7 @@ +{ + "configuring-chains": "configuring-chains", + "alchemy": "Alchemy", + "infura": "Infura", + "public": "公共 RPC", + "jsonRpc": "JSON RPC" +} diff --git a/docs/pages/react/providers/alchemy.zh-CN.mdx b/docs/pages/react/providers/alchemy.zh-CN.mdx new file mode 100644 index 0000000000..ee353fa779 --- /dev/null +++ b/docs/pages/react/providers/alchemy.zh-CN.mdx @@ -0,0 +1,122 @@ +--- +title: 'Alchemy' +description: 'Alchemy 的官方 wagmi Provider。' +--- + +import { Callout } from 'nextra-theme-docs' + +# Alchemy + +`alchemyProvider` 用 Alchemy RPC URLs 配置 chain,也提供一个 [ethers.js `AlchemyProvider`](https://docs.ethers.io/v5/api/providers/api-providers/#AlchemyProvider)。 + +```ts +import { alchemyProvider } from 'wagmi/providers/alchemy' +``` + +## 用法 + +```ts +import { mainnet, polygon } from 'wagmi/chains' +import { configureChains } from 'wagmi' +import { alchemyProvider } from 'wagmi/providers/alchemy' + +const { chains, provider } = configureChains( + [mainnet, polygon], + [alchemyProvider({ apiKey: 'yourAlchemyApiKey' })], +) +``` + +注意:上面的例子是使用来自 [`wagmi/chains`入口](/react/chains#wagmichains) 的 chain。 + +## 返回值 + +```ts +{ + chains: Chain[], + provider: AlchemyProvider, + webSocketProvider: AlchemyWebSocketProvider +} +``` + +## 配置项 + +### apiKey + +Alchemy API key,可以从 [Alchemy Dashboard](https://dashboard.alchemyapi.io/) 获取。 + +```ts {7} +import { configureChains } from 'wagmi' +import { mainnet, polygon } from 'wagmi/chains' +import { alchemyProvider } from 'wagmi/providers/alchemy' + +const { chains, provider } = configureChains( + [mainnet, polygon], + [alchemyProvider({ apiKey: 'yourAlchemyApiKey' })], +) +``` + +### priority (可选) + +用于设置 Provider 的优先级,priority 数值小的 Provider 优先级更高。如果多个 Provider 有相同的 priority,则会随机选择它们。 + +```ts {11,13} +import { configureChains } from 'wagmi' +import { mainnet, polygon } from 'wagmi/chains' +import { alchemyProvider } from 'wagmi/providers/alchemy' +import { publicProvider } from 'wagmi/providers/public' + +const { chains, provider } = configureChains( + [mainnet, polygon], + [ + alchemyProvider({ + apiKey: 'yourAlchemyApiKey', + priority: 0, + }), + publicProvider({ priority: 1 }), + ], +) +``` + +### stallTimeout (可选) + +请求超时时间,以毫秒为单位,超时后将尝试另一个 Provider。 + +```ts {11} +import { configureChains } from 'wagmi' +import { mainnet, polygon } from 'wagmi/chains' +import { alchemyProvider } from 'wagmi/providers/alchemy' +import { publicProvider } from 'wagmi/providers/public' + +const { chains, provider } = configureChains( + [mainnet, polygon], + [ + alchemyProvider({ + apiKey: 'yourAlchemyApiKey', + stallTimeout: 1_000, + }), + publicProvider(), + ], +) +``` + +### weight (可选) + +设置来自该 Provider 的响应的权重。如果一个给定的 Provider 更受你信任,就可以使用这个。 + +```ts {11,13} +import { configureChains } from 'wagmi' +import { mainnet, polygon } from 'wagmi/chains' +import { alchemyProvider } from 'wagmi/providers/alchemy' +import { publicProvider } from 'wagmi/providers/public' + +const { chains, provider } = configureChains( + [mainnet, polygon], + [ + alchemyProvider({ + apiKey: 'yourAlchemyApiKey', + weight: 1, + }), + publicProvider({ weight: 2 }), + ], +) +``` diff --git a/docs/pages/react/providers/configuring-chains.zh-CN.mdx b/docs/pages/react/providers/configuring-chains.zh-CN.mdx new file mode 100644 index 0000000000..2d78678ad2 --- /dev/null +++ b/docs/pages/react/providers/configuring-chains.zh-CN.mdx @@ -0,0 +1,209 @@ +--- +title: 'Configuring Chains' +description: 'configureChains 允许使用特定的 provider 来配置你的 chain,例如:Alchemy、Infura 或其他。这意味着你不需要担心在你的 connector 或 provider 中定义 RPC URLs 和 chain 的配置,这是由 wagmi 内部管理的。' +--- + +import { Callout } from 'nextra-theme-docs' + +# Configuring Chains + +`configureChains` 方法允许使用特定的 provider 来配置你的 chain ,例如:Alchemy、Infura 或其他。这意味着你不需要担心在你的 [connector](/react/connectors/walletconnect#options) 或 [provider](/react/client#provider-optional) 中定义 RPC URLs 和 chain 的配置,这是由 wagmi 内部管理的。 + +```ts +import { configureChains } from 'wagmi' +``` + +## 用法 + +`configureChains` 接受一个 chain 的数组和 provider 的数组,然后返回: + +- `chains`: 传递给你的 connector +- `provider`: 传递给 `createClient` +- `webSocketProvider`: 也传递给 `createClient`,不过是可选的 + +```ts +import { configureChains, createClient } from 'wagmi' +import { mainnet, optimism } from 'wagmi/chains' +import { alchemyProvider } from 'wagmi/providers/alchemy' +import { publicProvider } from 'wagmi/providers/public' +import { InjectedConnector } from 'wagmi/connectors/injected' + +const { chains, provider } = configureChains( + [mainnet, optimism], + [alchemyProvider({ apiKey: 'yourAlchemyApiKey' }), publicProvider()], +) + +const wagmiClient = createClient({ + autoConnect: true, + connectors: [new InjectedConnector({ chains })], + provider, +}) +``` + +可以在[这里](/core/chains)找到 wagmi 里支持的 chain 列表。 + +### 多个 Provider + +`configureChains` 方法可以接受多个 Provider. 如果你的 Provider 不能支持所有的 chain 的时候,这会是很有用的。 例如,你可能想用 [Alchemy](https://alchemy.com) 作为 Etheruem 的 Provider, 用 [avax.network](https://avax.network) 作为 Avalanche 的 Provider + +`configureChains` 将你配置的 Provider 配置成一个 [ethers.js `FallbackProvider`](https://docs.ethers.io/v5/api/providers/other/#FallbackProvider), 这样就直接支持了: + +- 如果一个 Provider 宕机了,可以自动转跳到另一个(例如,如果 Infura 宕机了,会将请求打到 Alchemy)。 +- 通过设置 targetQuorum 确保响应是合法的。 + +```ts +import { configureChains } from 'wagmi' +import { mainnet, optimism } from 'wagmi/chains' +import { alchemyProvider } from 'wagmi/providers/alchemy' +import { infuraProvider } from 'wagmi/providers/infura' +import { publicProvider } from 'wagmi/providers/public' + +const { provider } = configureChains( + [mainnet, avalanche], + [ + alchemyProvider({ apiKey: 'yourAlchemyApiKey' }), + infuraProvider({ apiKey: 'yourInfuraApiKey' }), + publicProvider(), + ], +) +``` + +### Quorum + +如果 targetQuorum 选项被设置为大于 1 值,它将向多个 Provider 进行请求,通过相互比较验证 Provider 的响应。如果结果相同并且达到设定的数量,那么结果才被返回。 + +```tsx +const { provider } = configureChains( + [mainnet, avalanche], + [ + alchemyProvider({ apiKey: 'yourAlchemyApiKey' }), + infuraProvider({ apiKey: 'yourInfuraApiKey' }), + publicProvider(), + ], + { targetQuorum: 2 }, +) +``` + +默认情况下,对于一个给定的 chain,它将 _尝试_ 设置`targetQuorum`,但如果 `targetQuorum` 值大于该 chain 的 Provider 数量,它将默认为提供者的数量。 + +例如,在上面提供的例子中,`targetQuorum = 2`,然而 Avalanche 只有一个可用的 Provider (`jsonRpcProvider`),所以`targetQuorum`将被设置为 1。 + +为了保证一个静态的 quorum,你可以提供一个`minQuorum`作为配置选项。 + +## 参数 + +### chains + +需要配置的 chain。 + +```ts {5} +import { configureChains } from 'wagmi' +import { mainnet, optimism } from 'wagmi/chains' +import { publicProvider } from 'wagmi/providers/public' + +const { chains } = configureChains([mainnet, optimism], [publicProvider()]) +``` + +### providers + +该 app 支持的 Provider。 + +如果一个 Provider 不支持一个 chain,它将退回到数组中的下一个。如果没有找到 RPC URL,`configureChains`将抛出一个错误。 + +```ts {7} +import { configureChains } from 'wagmi' +import { mainnet, optimism } from 'wagmi/chains' +import { alchemyProvider } from 'wagmi/providers/alchemy' +import { publicProvider } from 'wagmi/providers/public' + +const { chains } = configureChains( + [mainnet, optimism], + [alchemyProvider({ apiKey: 'yourAlchemyApiKey' }), publicProvider()], +) +``` + +## 配置项 + +### pollingInterval (可选) + +Provider 轮询的频率,以毫秒为单位,默认为 `4000`。 + +```ts {13} +import { configureChains } from 'wagmi' +import { mainnet, optimism } from 'wagmi/chains' +import { alchemyProvider } from 'wagmi/providers/alchemy' +import { publicProvider } from 'wagmi/providers/public' + +const { chains } = configureChains( + [mainnet, optimism], + [ + alchemyProvider({ apiKey: 'yourAlchemyApiKey' }), + infuraProvider({ apiKey: 'yourInfuraApiKey' }), + publicProvider(), + ], + { pollingInterval: 10_000, targetQuorum: 3 }, +) +``` + +### targetQuorum (可选) + +设置目标 quorum,默认为 1。 + +```ts {13} +import { configureChains } from 'wagmi' +import { mainnet, optimism } from 'wagmi/chains' +import { alchemyProvider } from 'wagmi/providers/alchemy' +import { publicProvider } from 'wagmi/providers/public' + +const { chains } = configureChains( + [mainnet, optimism], + [ + alchemyProvider({ apiKey: 'yourAlchemyApiKey' }), + infuraProvider({ apiKey: 'yourInfuraApiKey' }), + publicProvider(), + ], + { targetQuorum: 3 }, +) +``` + +### minQuorum (可选) + +设置 Provider 必须接受的最小 Quorum,默认为 1。 + +```ts {13} +import { configureChains } from 'wagmi' +import { mainnet, optimism } from 'wagmi/chains' +import { alchemyProvider } from 'wagmi/providers/alchemy' +import { publicProvider } from 'wagmi/providers/public' + +const { chains } = configureChains( + [mainnet, optimism], + [ + alchemyProvider({ apiKey: 'yourAlchemyApiKey' }), + infuraProvider({ apiKey: 'yourInfuraApiKey' }), + publicProvider(), + ], + { targetQuorum: 3, minQuorum: 2 }, +) +``` + +### stallTimeout (可选) + +请求超时时间,以毫秒为单位,超时后将尝试另一个 Provider。 + +```ts {13} +import { configureChains } from 'wagmi' +import { mainnet, optimism } from 'wagmi/chains' +import { alchemyProvider } from 'wagmi/providers/alchemy' +import { publicProvider } from 'wagmi/providers/public' + +const { chains } = configureChains( + [mainnet, optimism], + [ + alchemyProvider({ apiKey: 'yourAlchemyApiKey' }), + infuraProvider({ apiKey: 'yourInfuraApiKey' }), + publicProvider(), + ], + { stallTimeout: 5000 }, +) +``` diff --git a/docs/pages/react/providers/infura.zh-CN.mdx b/docs/pages/react/providers/infura.zh-CN.mdx new file mode 100644 index 0000000000..6b42253fc9 --- /dev/null +++ b/docs/pages/react/providers/infura.zh-CN.mdx @@ -0,0 +1,122 @@ +--- +title: 'Infura' +description: 'Infura 的官方 wagmi Provider。' +--- + +import { Callout } from 'nextra-theme-docs' + +# Infura + +`infuraProvider`用 Infura RPC URLs 来配置 chain ,还提供一个[ethers.js `InfuraProvider`](https://docs.ethers.io/v5/api/providers/api-providers/#InfuraProvider)。 + +```ts +import { infuraProvider } from 'wagmi/providers/infura' +``` + +## 用法 + +```ts +import { configureChains } from 'wagmi' +import { mainnet, polygon } from 'wagmi/chains' +import { infuraProvider } from 'wagmi/providers/infura' + +const { chains, provider } = configureChains( + [mainnet, polygon], + [infuraProvider({ apiKey: 'yourInfuraApiKey' })], +) +``` + +注意:上面的例子是使用来自 [`wagmi/chains`入口](/react/chains#wagmichains) 的 chain 。 + +## 返回值 + +```ts +{ + chains: Chain[], + provider: InfuraProvider, + webSocketProvider: InfuraWebSocketProvider +} +``` + +## 配置项 + +### apiKey + +Infura API key,可以从 [Infura Dashboard](https://infura.io/login) 获取。 + +```ts {7} +import { configureChains } from 'wagmi' +import { mainnet, polygon } from 'wagmi/chains' +import { infuraProvider } from 'wagmi/providers/infura' + +const { chains, provider } = configureChains( + [mainnet, polygon], + [infuraProvider({ apiKey: 'yourInfuraApiKey' })], +) +``` + +### priority (可选) + +用于设置 Provider 的优先级,priority 数值小的 Provider 优先级更高。如果多个 Provider 有相同的 priority,则会随机选择它们。 + +```ts {11,13} +import { configureChains } from 'wagmi' +import { mainnet, polygon } from 'wagmi/chains' +import { infuraProvider } from 'wagmi/providers/infura' +import { publicProvider } from 'wagmi/providers/public' + +const { chains, provider } = configureChains( + [mainnet, polygon], + [ + infuraProvider({ + apiKey: 'yourInfuraApiKey', + priority: 0, + }), + publicProvider({ priority: 1 }), + ], +) +``` + +### stallTimeout (可选) + +请求超时时间,以毫秒为单位,超时后将尝试另一个 Provider。 + +```ts {11} +import { configureChains } from 'wagmi' +import { mainnet, polygon } from 'wagmi/chains' +import { infuraProvider } from 'wagmi/providers/infura' +import { publicProvider } from 'wagmi/providers/public' + +const { chains, provider } = configureChains( + [mainnet, polygon], + [ + infuraProvider({ + apiKey: 'yourInfuraApiKey', + stallTimeout: 1_000, + }), + publicProvider(), + ], +) +``` + +### weight (可选) + +设置来自该 Provider 的响应的权重。如果一个给定的 Provider 更受你信任,就可以使用这个。 + +```ts {11,13} +import { configureChains } from 'wagmi' +import { mainnet, polygon } from 'wagmi/chains' +import { infuraProvider } from 'wagmi/providers/infura' +import { publicProvider } from 'wagmi/providers/public' + +const { chains, provider } = configureChains( + [mainnet, polygon], + [ + infuraProvider({ + apiKey: 'yourInfuraApiKey', + weight: 1, + }), + publicProvider({ weight: 2 }), + ], +) +``` diff --git a/docs/pages/react/providers/jsonRpc.zh-CN.mdx b/docs/pages/react/providers/jsonRpc.zh-CN.mdx new file mode 100644 index 0000000000..e3dae82393 --- /dev/null +++ b/docs/pages/react/providers/jsonRpc.zh-CN.mdx @@ -0,0 +1,156 @@ +--- +title: 'JSON RPC' +description: 'JSON RPC providers 的 wagmi 官方Provider。' +--- + +import { Callout } from 'nextra-theme-docs' + +# JSON RPC + +`jsonRpcProvider`用你指定的 RPC URL 配置 chain ,也提供一个 [ethers.js `StaticJsonRpcProvider`](https://docs.ethers.io/v5/api/providers/jsonrpc-provider/#StaticJsonRpcProvider)。 + +```ts +import { jsonRpcProvider } from 'wagmi/providers/jsonRpc' +``` + +## 用法 + +```ts +import { chain, configureChains } from 'wagmi' +import { jsonRpcProvider } from 'wagmi/providers/jsonRpc' + +const { chains, provider } = configureChains( + [chain.mainnet, chain.polygon], + [ + jsonRpcProvider({ + rpc: (chain) => ({ + http: `https://${chain.id}.example.com`, + }), + }), + ], +) +``` + +## 返回值 + +```ts +{ + chains: Chain[], + provider: JsonRpcProvider, + webSocketProvider: WebSocketProvider +} +``` + +## 配置项 + +### rpc + +需要填入一个函数,这个函数的接受 `chain` 作为输入并返回一个 `http` URL 和 `webSocket` URL,`webSocket` URL 不是必须的。 + +```tsx {8-11} +import { chain, configureChains } from 'wagmi' +import { jsonRpcProvider } from 'wagmi/providers/jsonRpc' + +const { chains, provider } = configureChains( + [chain.mainnet, chain.polygon], + [ + jsonRpcProvider({ + rpc: (chain) => ({ + http: `https://${chain.id}.example.com`, + webSocket: `wss://${chain.id}.example.com`, + }), + }), + ], +) +``` + +### priority (可选) + +用于设置 Provider 的优先级,priority 数值小的 Provider 优先级更高。如果多个 Provider 有相同的 priority,则会随机选择它们。 + +```ts {8} +import { chain, configureChains } from 'wagmi' +import { jsonRpcProvider } from 'wagmi/providers/jsonRpc' + +const { chains, provider } = configureChains( + [chain.mainnet, chain.polygon], + [ + jsonRpcProvider({ + priority: 0, + rpc: (chain) => ({ + http: `https://${chain.id}.example.com`, + webSocket: `wss://${chain.id}.example.com`, + }), + }), + alchemyProvider({ priority: 1 }), + ], +) +``` + +### stallTimeout (可选) + +请求超时时间,以毫秒为单位,超时后将尝试另一个 Provider。 + +```ts {12} +import { chain, configureChains } from 'wagmi' +import { jsonRpcProvider } from 'wagmi/providers/jsonRpc' + +const { chains, provider } = configureChains( + [chain.mainnet, chain.polygon], + [ + jsonRpcProvider({ + rpc: (chain) => ({ + http: `https://${chain.id}.example.com`, + webSocket: `wss://${chain.id}.example.com`, + }), + stallTimeout: 1000, + }), + alchemyProvider({ priority: 1, stallTimeout: 1000 }), + ], +) +``` + +### static (可选) + +设置表示 Provider 返回一个[`StaticJsonRpcProvider`](https://docs.ethers.io/v5/api/providers/jsonrpc-provider/#StaticJsonRpcProvider) 还是 [`JsonRpcProvider`](https://docs.ethers.io/v5/api/providers/jsonrpc-provider/#JsonRpcProvider)。默认为`true`,返回 `StaticJsonRpcProvider` 。 + +```tsx {12} +import { chain, configureChains } from 'wagmi' +import { jsonRpcProvider } from 'wagmi/providers/jsonRpc' + +const { chains, provider } = configureChains( + [chain.mainnet, chain.polygon], + [ + jsonRpcProvider({ + rpc: (chain) => ({ + http: `https://${chain.id}.example.com`, + webSocket: `wss://${chain.id}.example.com`, + }), + static: false, + }), + ], +) +``` + +### weight (可选) + +设置来自该 Provider 的响应的权重。如果一个给定的 Provider 更受你信任,就可以使用这个。 + +```ts {12} +import { chain, configureChains } from 'wagmi' +import { jsonRpcProvider } from 'wagmi/providers/jsonRpc' + +const { chains, provider } = configureChains( + [chain.mainnet, chain.polygon], + [ + jsonRpcProvider({ + rpc: (chain) => ({ + http: `https://${chain.id}.example.com`, + webSocket: `wss://${chain.id}.example.com`, + }), + weight: 1, + }), + alchemyProvider({ priority: 1, weight: 2 }), + ], +) +``` diff --git a/docs/pages/react/providers/public.zh-CN.mdx b/docs/pages/react/providers/public.zh-CN.mdx new file mode 100644 index 0000000000..f19537490b --- /dev/null +++ b/docs/pages/react/providers/public.zh-CN.mdx @@ -0,0 +1,95 @@ +--- +title: 'Public' +description: '公共 RPC providers 的 wagmi 官方 Provider。' +--- + +import { Callout } from 'nextra-theme-docs' + +# Public + +`publicProvider`用公共 RPC URL 配置 chain ,同时提供 [ethers.js `getpublicProvider`](https://docs.ethers.io/v5/api/providers/#providers-getpublicProvider)。 + +```ts +import { publicProvider } from 'wagmi/providers/public' +``` + +## 用法 + +```ts +import { chain, configureChains } from 'wagmi' +import { publicProvider } from 'wagmi/providers/public' + +const { chains, provider } = configureChains( + [chain.mainnet, chain.polygon], + [publicProvider()], +) +``` + + + 在你的提供者中只有 `publicProvider` 会使请求特定的 chain 时只使用公共 RPC + URL,这可能会导致速率限制。我们建议在你的列表中还应该包括另一个 + Provider(例如:`alchemyProvider`,`infuraProvider` 或 `jsonRpcProvider`)。 + + +## 返回值 + +```ts +{ + chains: Chain[], + provider: BaseProvider, + webSocketProvider: WebSocketProvider +} +``` + +## 配置项 + +### priority (可选) + +用于设置 Provider 的优先级,priority 数值小的 Provider 优先级更高。如果多个 Provider 有相同的 priority,则会随机选择它们。 + +```ts {7-8} +import { chain, configureChains } from 'wagmi' +import { publicProvider } from 'wagmi/providers/public' + +const { chains, provider } = configureChains( + [chain.mainnet, chain.polygon], + [ + alchemyProvider({ apiKey: 'yourAlchemyApiKey', priority: 0 }), + publicProvider({ priority: 1 }), + ], +) +``` + +### stallTimeout (可选) + +请求超时时间,以毫秒为单位,超时后将尝试另一个 Provider。 + +```ts {8} +import { chain, configureChains } from 'wagmi' +import { publicProvider } from 'wagmi/providers/public' + +const { chains, provider } = configureChains( + [chain.mainnet, chain.polygon], + [ + alchemyProvider({ apiKey: 'yourAlchemyApiKey' }), + publicProvider({ stallTimeout: 1_000 }), + ], +) +``` + +### weight (可选) + +设置来自该 Provider 的响应的权重。如果一个给定的 Provider 更受你信任,就可以使用这个。 + +```ts {7-8} +import { chain, configureChains } from 'wagmi' +import { publicProvider } from 'wagmi/providers/public' + +const { chains, provider } = configureChains( + [chain.mainnet, chain.polygon], + [ + alchemyProvider({ apiKey: 'yourAlchemyApiKey', weight: 1 }), + publicProvider({ weight: 2 }), + ], +) +```