Last active
May 9, 2022 00:49
-
-
Save djstein/af16278d6f940fb85f338d5fddc3e057 to your computer and use it in GitHub Desktop.
RainbowKitWrapper - Full example of using RainbowKit in a NextJS app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Head from 'next/head' | |
import type { AppProps } from 'next/app' | |
import RainbowKitWrapper from '../components/RainbowKitWrapper' | |
const YOUR_APP = 'Your App' | |
const App = ({ Component, pageProps }: AppProps): JSX.Element => { | |
return ( | |
<> | |
<Head> | |
<title>{YOUR_APP}</title> | |
<meta name="mobile-web-app-capable" content="yes" /> | |
<meta name="apple-touch-fullscreen" content="yes" /> | |
<meta name="apple-mobile-web-app-title" content={YOUR_APP} /> | |
<meta name="apple-mobile-web-app-capable" content="yes" /> | |
<meta charSet="utf-8" /> | |
<meta | |
name="viewport" | |
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no, viewport-fit=cover" | |
/> | |
</Head> | |
<RainbowKitWrapper> | |
<Component {...pageProps} /> | |
</RainbowKitWrapper> | |
</> | |
) | |
} | |
export default App |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import '@rainbow-me/rainbowkit/styles.css' | |
import { | |
apiProvider, | |
configureChains, | |
darkTheme, | |
getDefaultWallets, | |
lightTheme, | |
RainbowKitProvider | |
} from '@rainbow-me/rainbowkit' | |
import { chain, createClient, WagmiProvider } from 'wagmi' | |
const YOUR_APP_NAME = 'Test App' | |
const RainbowKitWrapper = ({ children }: { children: React.ReactNode }) => { | |
const { chains, provider } = configureChains( | |
[chain.mainnet, chain.polygon, chain.optimism, chain.arbitrum], | |
[apiProvider.alchemy(process.env.ALCHEMY_ID), apiProvider.fallback()] | |
) | |
const { connectors } = getDefaultWallets({ | |
appName: YOUR_APP_NAME, | |
chains | |
}) | |
const wagmiClient = createClient({ | |
autoConnect: true, | |
connectors, | |
provider | |
}) | |
return ( | |
<WagmiProvider client={wagmiClient}> | |
<RainbowKitProvider | |
chains={chains} | |
theme={{ | |
lightMode: lightTheme(), | |
darkMode: darkTheme() | |
> | |
{children} | |
</RainbowKitProvider> | |
</WagmiProvider> | |
) | |
} | |
export default RainbowKitWrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment