Skip to main content
This guide walks through integrating Jupiter Plugin into a Next.js application from scratch. It covers both App Router and Pages Router setups, TypeScript declarations, and two initialization methods: the window object approach and the @jup-ag/plugin npm package.

Prerequisites

Before you begin, make sure you have the following installed on your system. Node.js and npm: Download and install from nodejs.org

Step 1: Create a New Next.js Project

Head to your preferred directory and create a new Next.js project using create-next-app with TypeScript template (you can use other templates or methods to start your project too):

Step 2: Add TypeScript Support

Create a type declaration file plugin.d.ts in your project’s /src/types folder:

Step 3: Embed the Plugin Script

For Next.js applications, you can add the script in two ways:

Using App Router (Next.js 13+)

In your app/layout.tsx:

Using Pages Router

In your pages/_app.tsx:

Step 4: Initialize Plugin

There are two ways to initialize Jupiter Plugin in a Next.js application:

Method 1: Using Window Object

Create a new component for the plugin at components/plugin.tsx:

Method 2: Using @jup-ag/plugin Package

WARNINGDo note that using this method will require you to maintain its dependencies.
1
Install the package:
2
Create a new component for the plugin at components/plugin.tsx:

Step 5: Add the Plugin Component to Your Page

In your app/page.tsx (or pages/index.tsx if you’re using Pages Router):
There you have it! You’ve successfully integrated Jupiter Plugin into your Next.js application.
  • Please test the swap functionality and check the transaction.
  • If you require more customizations, check out the Plugin Playground or the Customization documentation.
  • If you have any questions or issues, please refer to the FAQ or contact us on Discord.