We are importing the styles for rainbow kit, already built in for us to use
import'@rainbow-me/rainbowkit/styles.css';
This imports the Provider Wrapper for our layout.tsx and setting for cometh connect wallet. We do need to import the rainbowkitComethConnect from the cometh sdk.
The providers can be confusing the wagmi docs and the rainbow docs. In short, a feature of Wagmi is to have failover RPCs. Let's say we start with an alchemy RPC and that fails, then we can use an Ankr RPC and that fails and finally we can use the Public RPCs so that people can keep using our dapp even if our account API fails.
Breaking down what is happening here in the configuration
Setting up configureChains hook. Here we are using the tool to let our variables "chains" and "provider" know what chains we are using and what providers we are using.
chains is taking in polygon.
provider is taking in both Alchemy provider (with our API key) and public provider. We can also add more providers as well. So it will first go with Alchemy first and if it fails, then the public provider.
Setting our Default wallets. This sets up our variable "connectors" to accepts the chains that we just previously set in the "configureChains" and giving the app our name (we can change that to whatever we want, our Dapp Name)
The createClient just puts it all together in a single Object call wagmiClient. We take "connectors" we just previously setup (this took in our chains we want to support) and our "Providers" (the RPCs we have setup) and bundle it up for wagmi to refer to.
Now that we have all the basic configurations setup, we can now wrap our layout.tsx so wagmi and rainbowkit will function throughout our entire website. We are going to turn this part:
We just wrapped out website "layout" with the RainbowKit wrapper and let it know we want to support these "chains" (the chains we chose in "configureChains"). Then we wrapped this entire wrapping with the WagmiConfig wrapper and set it to the wagmiClient (that set the type of wallets we will support and the RPC providers). That's a lot of wrapping but at the end, your layout.tsx file should look like this: