Getting Started with Terminal
Prerequisites
Before integrating Jupiter Terminal, ensure you have:
- A Solana RPC endpoint (you can use public endpoints or services like Helius)
- A React or Next.js application
- Basic understanding of TypeScript (recommended)
React Application Example
Step 1: Add TypeScript Support
Create a type declaration file terminal.d.ts
in your project's types folder:
declare global {
interface Window {
Jupiter: JupiterTerminal;
}
}
Step 2: Embed the Terminal Script
In your index.html
, add the Jupiter Terminal script:
<head>
<script src="https://terminal.jup.ag/main-v4.js" data-preload defer></script>
</head>
Step 3: Initialize Terminal
There are two ways to initialize Jupiter Terminal in a React application:
Method 1: Using Window Object
import React, { useEffect } from "react";
function App() {
useEffect(() => {
// Create container for terminal
const terminalContainer = document.createElement("div");
terminalContainer.id = "jupiter-terminal";
document.body.appendChild(terminalContainer);
// Initialize terminal
window.Jupiter.init({
displayMode: "integrated",
integratedTargetId: "jupiter-terminal",
endpoint: "https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY",
formProps: {
fixedOutputMint: false,
},
});
}, []);
return (
<div>
<h1>Jupiter Terminal Demo</h1>
<div id="jupiter-terminal" style={{ width: "100%", height: "500px" }} />
</div>
);
}
Method 2: Using @jup-ag/terminal Package
- Install the package:
npm install @jup-ag/terminal
- Initialize the terminal:
import React, { useEffect } from "react";
import "@jup-ag/terminal/css";
function App() {
useEffect(() => {
import("@jup-ag/terminal").then((mod) => {
const { init } = mod;
init({
displayMode: "integrated",
integratedTargetId: "jupiter-terminal",
endpoint: "https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY",
});
});
}, []);
return (
<div>
<h1>Jupiter Terminal Demo</h1>
<div id="jupiter-terminal" style={{ width: "100%", height: "500px" }} />
</div>
);
}
Next.js Application Example
Step 1: Add TypeScript Support
Create a type declaration file terminal.d.ts
in your project's types folder:
declare global {
interface Window {
Jupiter: JupiterTerminal;
}
}
Step 2: Embed the Terminal Script
For Next.js applications, you can add the script in two ways:
Using App Router (Next.js 13+)
In your app/layout.tsx
:
import Script from "next/script";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<head>
<Script
src="https://terminal.jup.ag/main-v4.js"
strategy="beforeInteractive"
data-preload
defer
/>
</head>
<body>{children}</body>
</html>
);
}
Using Pages Router
In your pages/_app.tsx
:
import Script from "next/script";
function MyApp({ Component, pageProps }) {
return (
<>
<Script
src="https://terminal.jup.ag/main-v4.js"
strategy="beforeInteractive"
data-preload
defer
/>
<Component {...pageProps} />
</>
);
}
export default MyApp;
Step 3: Initialize Terminal
Create a new component for the terminal:
"use client";
import React, { useEffect } from "react";
export default function TerminalComponent() {
useEffect(() => {
if (typeof window !== "undefined") {
window.Jupiter.init({
displayMode: "integrated",
integratedTargetId: "jupiter-terminal",
endpoint: "https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY",
formProps: {
fixedOutputMint: false,
},
});
}
}, []);
return (
<div>
<h1>Jupiter Terminal Demo</h1>
<div
id="jupiter-terminal"
style={{
width: "100%",
height: "500px",
borderRadius: "8px",
overflow: "hidden",
}}
/>
</div>
);
}
Best Practices
- Always use a reliable RPC endpoint
- Implement proper error handling
- Consider using environment variables for sensitive data
- Test thoroughly in development before deploying
- Monitor swap success rates and user feedback