Svelte + Vite
A user-friendly guide to integrate the Capsule Modal (React-based) into your Svelte application powered by Vite.
This guide shows you how to integrate the Capsule Modal—which is React-based—within a Svelte application that is powered by Vite. Although mixing React and Svelte is unusual, we can do so via svelte-preprocess-react. If you prefer to build your own custom UI, you can also use @usecapsule/web-sdk
directly.
If you haven’t already you can create a new Svelte project with Vite by following the official Vite docs. Alternatively, you can fork our minimal starter that already includes the Capsule Modal setup: Capsule Svelte + 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 both the Capsule React SDK and React dependencies:
Setting Up the Svelte Preprocessor and Vite Polyfills
Svelte Preprocessor for React
You must configure your Svelte app to accept React components. For that, install and configure
svelte-preprocess-react
:
Then add it to your svelte.config.js
:
Vite Polyfills
Like other React-based setups, you may need Node.js polyfills for features like crypto
, buffer
, and stream
.
Install vite-plugin-node-polyfills
:
Then configure it in vite.config.js
or vite.config.ts
:
Setting Up the Capsule SDK
Now that you’ve installed the necessary dependencies, let’s set up the Capsule SDK in your Svelte application. This involves creating a client instance and integrating the Capsule Modal.
Creating a Capsule Client Instance
Much like in React or Vue, you’ll need a Capsule client instance. Keep it in a dedicated file (e.g.,
client/capsule.ts
):
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 in Svelte
With svelte-preprocess-react
, you can directly use React components in Svelte:
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.
When you click Open Capsule Modal, the React-based Capsule Modal will appear inside your Svelte application.
Customizing the Capsule Modal
Just like in React, you can provide any additional props to the <CapsuleModal>
component. For example, customizing
theming:
If You Don’t Want to Use the React Modal
You can instead use the @usecapsule/web-sdk to build your own Svelte-based UI. This avoids the React modal entirely, but you’ll need to manually implement authentication, wallet management, etc. For details on how to do this, refer to the Customize Capsule guide.
Examples
We have a Svelte + Vite starter template showcasing how to set up the Capsule Modal. Give it a try to see everything in action.
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
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.