React + Vite
A guide to quickly integrate the Capsule Modal into your Vite-powered React application.
This guide will walk you through the process of integrating the Capsule Modal into a Vite-powered React application, providing a seamless way to manage user authentication and wallets.
If you haven’t already created a new Vite project, you can follow the official Vite docs to get started. Alternatively, you can fork our minimal starter that already includes the Capsule Modal setup: Capsule Vite Starter.
Prerequisites
To use Capsule, you need an API key. This key authenticates your requests to Capsule services and is essential for integration.
Don’t have an API key yet? Request access to the Developer Portal to create API keys, manage billing, teams, and more.
Installing Dependencies
First, install the Capsule React SDK using your preferred package manager:
Setting Up Polyfills with Vite
Some Node.js modules that Capsule relies on (e.g., crypto
, buffer
, stream
) may need to be polyfilled in a Vite
environment. One easy option is to use vite-plugin-node-polyfills
:
This ensures Node-specific modules are properly polyfilled in the browser environment.
Setting Up the Capsule SDK
Now that you’ve installed the necessary dependencies, let’s set up the Capsule SDK in your Vite project. This involves creating a client instance.
Creating a Capsule Client Instance
You can create the Capsule client instance in a dedicated file, such as clients/capsule.tsx
, or as part of your state
management logic. Below is a basic example:
This step initializes the Capsule SDK with your API key and the chosen environment. If successful, you should see the
Capsule instance logged in your console (if you choose to console.log
it).
Capsule offers two hosted environments: Environment.BETA
(alias Environment.DEVELOPMENT
) for
testing, and Environment.PROD
(alias Environment.PRODUCTION
) for live use. Select the
environment that matches your current development phase.
Integrating the Capsule Modal
Integrate the Capsule Modal into your React component by importing the CapsuleModal
component from the Capsule SDK,
adding a button to trigger the modal, and managing the modal’s state.
This creates a button that, when clicked, opens the Capsule Modal for user authentication. The Capsule Modal handles all aspects of user authentication and wallet management.
Beta Testing Credentials
In the BETA
Environment, you can use any email ending in @test.usecapsule.com
(like dev@test.usecapsule.com) or US phone numbers (+1) in the format (area code)-555-xxxx
(like (425)-555-1234). Any OTP code will work for verification with these test credentials.
These credentials are for beta testing only. You can delete test users anytime in the beta developer console to free up user slots.
Customizing the Capsule Modal
To provide the best experience for your users, you can customize the appearance and behavior of the Capsule Modal to match your application’s branding.
When rendering the CapsuleModal component, you can pass props to customize its appearance and behavior:
For a full list of available CapsuleModalProps
, refer to the customization guide:
Examples
For practical implementation of the Capsule SDK in Vite-based React applications, explore our example repository. This repository contains real-world examples to help you get started.
Next Steps
After integrating Capsule, you can explore other features and integrations to enhance your Capsule experience. Here are some resources to help you get started:
Ecosystems
Learn how to use Capsule with popular Web3 clients and wallet connectors. We’ll cover integration with key libraries for EVM, Solana, and Cosmos ecosystems.
If you’re ready to go live with your Capsule integration, make sure to review our go-live checklist:
Troubleshooting
If you encounter issues during the integration or usage of the Capsule Modal in a Vite-based app, here are some common problems and their solutions:
For a more comprehensive list of solutions, visit our troubleshooting guide:
Integration Support
If you’re experiencing issues that aren’t resolved by our troubleshooting resources, please contact our team for assistance. To help us resolve your issue quickly, please include the following information in your request:
1
A detailed description of the problem you’re encountering.
2
Any relevant error messages or logs.
3
Steps to reproduce the issue.
4
Details about your system or environment (e.g., device, operating system, software version).
Providing this information will enable our team to address your concerns more efficiently.
Was this page helpful?