Install the required dependencies
Add OnchainKit and its peer dependencies to your project:Terminal
Terminal
Import styles
OnchainKit components need the base styles to look correct. Import them in your app’s root layout or main CSS file:app/layout.tsx
globals.css
Set up and configure the provider
Wrap your app with theOnchainKitProvider
. This gives all OnchainKit components access to your chain configuration and API keys.
OnchainKit handles Wagmi and React Query setup internally, so you just need to configure the provider with your preferences.
If you want to customize these providers, check out the Custom Providers page.
app/layout.tsx
Environment variables (optional)
While you can hardcode your API key directly in the provider, it may be cleaner to use environment variables for security, especially in production apps.Next.js
Create a.env.local
file in your project root:
.env.local
Vite
Create a.env
file in your project root:
.env
Other frameworks
Follow your framework’s convention for environment variables. Most React frameworks support.env
files.
Using the environment variable
Basic usage
Now you can start using OnchainKit components:components/WalletDemo.tsx
Mini app setup
If you’re building a mini app, you’ll need to follow a couple additional steps:1. Enable MiniKit in the provider
app/layout.tsx
2. Add SafeArea component
Wrap your main content to handle safe areas on mobile. If you want to wrap your whole application, put this in your root layout.app/page.tsx
3. Create the manifest endpoint
Create an API route that serves your Farcaster manifest. See the manifest documentation for more information.app/api/.well-known/farcaster.json/route.ts
Next steps
- Check out the component documentation to see what’s available
- Read the configuration guide for advanced setup options