[{"_path":"/providers/public","_draft":false,"_partial":false,"_empty":false,"title":"Public","description":"The publicProvider configures the chains with a public RPC URL and also provides an ethers.js getpublicProvider.","excerpt":{"type":"root","children":[{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Visit "},{"type":"element","tag":"a","props":{"href":"https://docs.ethers.io/v5/api/providers/#providers-getpublicProvider","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"ethers.js "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"getpublicProvider"}]}]},{"type":"text","value":"."}]},{"type":"element","tag":"h2","props":{"id":"usage"},"children":[{"type":"text","value":"Usage"}]},{"type":"element","tag":"code","props":{"code":"import { chain, configureChains } from 'vagmi';\nimport { publicProvider } from 'vagmi/providers/public';\n\nconst { chains, provider } = configureChains(\n  [chain.mainnet, chain.polygon],\n  [publicProvider()],\n);\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"import { chain, configureChains } from 'vagmi';\nimport { publicProvider } from 'vagmi/providers/public';\n\nconst { chains, provider } = configureChains(\n  [chain.mainnet, chain.polygon],\n  [publicProvider()],\n);\n"}]}]}]},{"type":"element","tag":"callout","props":{"emoji":"⚠️"},"children":[{"type":"text","value":"\n  Only having `publicProvider` in your providers will make the chain use the\n  public RPC URL which could lead to rate-limiting. It is recommended to also\n  include another provider in your list (such as: `alchemyProvider`,\n  `infuraProvider` or `jsonRpcProvider`).\n"}]},{"type":"element","tag":"h2","props":{"id":"return-value"},"children":[{"type":"text","value":"Return Value"}]},{"type":"element","tag":"code","props":{"code":"{\n  chains: Chain[],\n  provider: BaseProvider,\n  webSocketProvider: WebSocketProvider\n}\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"{\n  chains: Chain[],\n  provider: BaseProvider,\n  webSocketProvider: WebSocketProvider\n}\n"}]}]}]},{"type":"element","tag":"h2","props":{"id":"configuration"},"children":[{"type":"text","value":"Configuration"}]},{"type":"element","tag":"h3","props":{"id":"pollinginterval-optional"},"children":[{"type":"text","value":"pollingInterval (optional)"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"The frequency in milliseconds at which the provider polls."}]},{"type":"element","tag":"code","props":{"code":"import { chain, configureChains } from 'vagmi';\nimport { publicProvider } from 'vagmi/providers/public';\n\nconst { chains, provider } = configureChains(\n  [chain.mainnet, chain.polygon],\n  [publicProvider({ pollingInterval: 5000 })],\n);\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"import { chain, configureChains } from 'vagmi';\nimport { publicProvider } from 'vagmi/providers/public';\n\nconst { chains, provider } = configureChains(\n  [chain.mainnet, chain.polygon],\n  [publicProvider({ pollingInterval: 5000 })],\n);\n"}]}]}]},{"type":"element","tag":"h3","props":{"id":"priority-optional"},"children":[{"type":"text","value":"priority (optional)"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"The priority used for the provider. Lower-value priorities are favoured over higher-value priorities. If multiple providers share the same priority, they are chosen at random."}]},{"type":"element","tag":"code","props":{"code":"import { chain, configureChains } from 'vagmi';\nimport { publicProvider } from 'vagmi/providers/public';\n\nconst alchemyId = import.meta.env..ALCHEMY_ID;\n\nconst { chains, provider } = configureChains(\n  [chain.mainnet, chain.polygon],\n  [\n    alchemyProvider({ alchemyId, priority: 0 }),\n    publicProvider({ priority: 1 }),\n  ],\n);\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"import { chain, configureChains } from 'vagmi';\nimport { publicProvider } from 'vagmi/providers/public';\n\nconst alchemyId = import.meta.env..ALCHEMY_ID;\n\nconst { chains, provider } = configureChains(\n  [chain.mainnet, chain.polygon],\n  [\n    alchemyProvider({ alchemyId, priority: 0 }),\n    publicProvider({ priority: 1 }),\n  ],\n);\n"}]}]}]},{"type":"element","tag":"h3","props":{"id":"stalltimeout-optional"},"children":[{"type":"text","value":"stallTimeout (optional)"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"The timeout in milliseconds after which another provider will be attempted."}]},{"type":"element","tag":"code","props":{"code":"import { chain, configureChains } from 'vagmi';\nimport { publicProvider } from 'vagmi/providers/public';\n\nconst alchemyId = import.meta.env..ALCHEMY_ID;\n\nconst { chains, provider } = configureChains(\n  [chain.mainnet, chain.polygon],\n  [\n    alchemyProvider({ alchemyId, stallTimeout: 1000 }),\n    publicProvider({ stallTimeout: 1000 }),\n  ],\n);\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"import { chain, configureChains } from 'vagmi';\nimport { publicProvider } from 'vagmi/providers/public';\n\nconst alchemyId = import.meta.env..ALCHEMY_ID;\n\nconst { chains, provider } = configureChains(\n  [chain.mainnet, chain.polygon],\n  [\n    alchemyProvider({ alchemyId, stallTimeout: 1000 }),\n    publicProvider({ stallTimeout: 1000 }),\n  ],\n);\n"}]}]}]},{"type":"element","tag":"h3","props":{"id":"weight-optional"},"children":[{"type":"text","value":"weight (optional)"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"The weight a response from this provider provides. This can be used if a given provider is more trusted."}]},{"type":"element","tag":"code","props":{"code":"import { chain, configureChains } from 'vagmi';\nimport { publicProvider } from 'vagmi/providers/public';\n\nconst alchemyId = import.meta.env..ALCHEMY_ID;\n\nconst { chains, provider } = configureChains(\n  [chain.mainnet, chain.polygon],\n  [alchemyProvider({ alchemyId, weight: 1 }), publicProvider({ weight: 2 })],\n);\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"import { chain, configureChains } from 'vagmi';\nimport { publicProvider } from 'vagmi/providers/public';\n\nconst alchemyId = import.meta.env..ALCHEMY_ID;\n\nconst { chains, provider } = configureChains(\n  [chain.mainnet, chain.polygon],\n  [alchemyProvider({ alchemyId, weight: 1 }), publicProvider({ weight: 2 })],\n);\n"}]}]}]}]},"_type":"markdown","_id":"content:3.providers:4.public.md","_source":"content","_file":"3.providers/4.public.md","_extension":"md"},{"_path":"/connectors/injected","_draft":false,"_partial":false,"_empty":false,"title":"Injected","description":"The InjectedConnector supports wallets that inject an Ethereum Provider into the browser or window. The MetaMask browser extension is the most popular example of this.","excerpt":{"type":"root","children":[{"type":"element","tag":"h2","props":{"id":"usage"},"children":[{"type":"text","value":"Usage"}]},{"type":"element","tag":"code","props":{"code":"import { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector();\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"import { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector();\n"}]}]}]},{"type":"element","tag":"alert","props":{"type":"info"},"children":[{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"💼 Injected wallets can set up custom name mappings in vagmi. You can "},{"type":"element","tag":"a","props":{"href":"https://github.com/tmm/wagmi/blob/main/packages/core/src/utils/getInjectedName.ts","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"see the\nfull list and add to it\nhere"}]},{"type":"text","value":".\nBy default, \"Injected\" is the name for unmapped wallets."}]}]},{"type":"element","tag":"h2","props":{"id":"configuration"},"children":[{"type":"text","value":"Configuration"}]},{"type":"element","tag":"h3","props":{"id":"chains-optional"},"children":[{"type":"text","value":"chains (optional)"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Chains supported by app. Defaults to "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"defaultChains"}]},{"type":"text","value":"."}]},{"type":"element","tag":"code","props":{"code":"import { chain } from 'vagmi';\nimport { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector({\n  chains: [chain.mainnet, chain.optimism],\n});\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"import { chain } from 'vagmi';\nimport { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector({\n  chains: [chain.mainnet, chain.optimism],\n});\n"}]}]}]},{"type":"element","tag":"h3","props":{"id":"options-optional"},"children":[{"type":"text","value":"options (optional)"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Options for configuring the connector."}]},{"type":"element","tag":"code","props":{"code":"import { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector({\n  options: {\n    shimDisconnect: true,\n  },\n});\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"import { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector({\n  options: {\n    shimDisconnect: true,\n  },\n});\n"}]}]}]},{"type":"element","tag":"h4","props":{"id":"name"},"children":[{"type":"text","value":"name"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Name of connector instead of trying to detect from browser."}]},{"type":"element","tag":"code","props":{"code":"import { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector({\n  options: {\n    name: 'Injected',\n  },\n});\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"import { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector({\n  options: {\n    name: 'Injected',\n  },\n});\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"name"}]},{"type":"text","value":" can also be set to a function, which has the "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"detectedName"}]},{"type":"text","value":" as the first parameter. "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"detectedName"}]},{"type":"text","value":" can be a list of multiple detected names if there are multiple injected wallets detected."}]},{"type":"element","tag":"code","props":{"code":"import { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector({\n  options: {\n    name: detectedName =>\n      `Injected (${\n        typeof detectedName === 'string'\n          ? detectedName\n          : detectedName.join(', ')\n      })`,\n  },\n});\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"import { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector({\n  options: {\n    name: detectedName =>\n      `Injected (${\n        typeof detectedName === 'string'\n          ? detectedName\n          : detectedName.join(', ')\n      })`,\n  },\n});\n"}]}]}]},{"type":"element","tag":"h4","props":{"id":"shimchainchangeddisconnect"},"children":[{"type":"text","value":"shimChainChangedDisconnect"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Certain versions of MetaMask "},{"type":"element","tag":"a","props":{"href":"https://github.com/MetaMask/metamask-extension/issues/13375#issuecomment-1027663334","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"emit the "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"\"disconnect\""}]},{"type":"text","value":" event when chain is changed"}]},{"type":"text","value":". This flag prevents the "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"\"disconnect\""}]},{"type":"text","value":" event from being emitted upon switching chains. Defaults to "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"false"}]},{"type":"text","value":"."}]},{"type":"element","tag":"code","props":{"code":"import { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector({\n  options: {\n    shimChainChangedDisconnect: true,\n  },\n});\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"import { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector({\n  options: {\n    shimChainChangedDisconnect: true,\n  },\n});\n"}]}]}]},{"type":"element","tag":"h4","props":{"id":"shimdisconnect"},"children":[{"type":"text","value":"shimDisconnect"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"MetaMask and other injected providers "},{"type":"element","tag":"a","props":{"href":"https://github.com/MetaMask/metamask-extension/issues/10353","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"do not support programmatic disconnect"}]},{"type":"text","value":". This flag simulates the disconnect behavior by keeping track of connection status in storage. Defaults to "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"true"}]},{"type":"text","value":"."}]},{"type":"element","tag":"code","props":{"code":"import { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector({\n  options: {\n    shimDisconnect: false,\n  },\n});\n","highlights":[5],"language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"import { InjectedConnector } from 'vagmi/connectors/injected';\n\nconst connector = new InjectedConnector({\n  options: {\n    shimDisconnect: false,\n  },\n});\n"}]}]}]}]},"_type":"markdown","_id":"content:4.connectors:1.injected.md","_source":"content","_file":"4.connectors/1.injected.md","_extension":"md"}]