React & Web
A user-friendly guide to quickly integrate the Capsule Modal into your web application, providing an easy-to-use, pre-built interface for user authentication and wallet management.
This guide will walk you through the process of integrating the Capsule Modal into your web application, providing a seamless way to manage user authentication and wallets.
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
In this section, you’ll install the Capsule React SDK, which is the core dependency needed to integrate Capsule into your web application.
First, install the Capsule React SDK using your preferred package manager:
Setting Up the Capsule SDK
Now that you’ve installed the necessary dependencies, let’s set up the Capsule SDK. This will involve creating a client instance, setting up polyfills, and integrating the Capsule Modal into your application.
Creating a Capsule Client Instance
First, create a Capsule client instance. This instance will be used to interact with the Capsule SDK and manage the authentication flow.
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.
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.
Setting Up Polyfills
Depending on your target environment, you may need to set up polyfills for certain features that Capsule relies on. This step ensures that all required functionalities are supported in your application.
Common polyfills include:crypto
,buffer
,stream
,process
The exact method for including these polyfills will depend on your build tool and framework. Here’s a general example using webpack:
Make sure to install the necessary packages (e.g., crypto-browserify
, buffer
, etc.) before using them in your
config.
If you’re using Vite, consider using the Vite Plugin Node Polyfills to simplify the polyfilling process. If you’re using Create React App (CRA), you can use CRACO to modify the webpack configuration as shown above.
The specific polyfills and setup may vary based on your project’s needs and the framework you’re using. Consult your framework’s documentation for best practices on polyfilling or consult our troubleshooting guide for more information.
Integrating the Capsule Modal
Now, 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 handling 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.
Make sure to import the Capsule CSS file (@usecapsule/react-sdk/styles.css
) to apply the default styles to the modal.
If you’re using Next.js or another server-side rendering framework, you’ll need to use dynamic imports for the CapsuleModal component to avoid SSR-related issues. An example of dynamic import in Next.js:
This ensures that the CapsuleModal is only loaded on the client-side. You may need to adjust this approach based on your specific SSR framework.
Consult your framework’s documentation or community resources for best practices on integrating client-side components in SSR applications.
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. This allows you to adjust the look and feel of the modal to align with your application’s branding.
For a full list of available CapsuleModalProps
, refer to the customization guide:
Examples
For practical implementation of the Capsule SDK in 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, here are some common problems and their solutions:
For a more comprehensive list of solutions, visit our troubleshooting guide:
Support
If you’re experiencing issues that aren’t resolved by our troubleshooting resources, please contact our support team for assistance. To help us serve you better, include the following information in your support 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?