Integration Guide
Step-by-step guide to integrating PrismGPT into your application.
Prerequisites
- Node.js 18+ installed
- BNB Chain compatible wallet (MetaMask recommended)
- Basic understanding of Web3 development
- PrismGPT API key (contact team for access)
Step 1: Set Up Your Project
npm init -y npm install ethers @walletconnect/ethereum-provider
Step 2: Install PrismGPT SDK
Copy the SDK file from the PrismGPT repository:
// Copy sdk/prism.js to your project
// Import in your application
import { Prism } from './sdk/prism.js';Step 3: Connect Wallet
import { ethers } from 'ethers';
async function connectWallet() {
if (typeof window.ethereum !== 'undefined') {
const provider = new ethers.BrowserProvider(window.ethereum);
const accounts = await provider.send("eth_requestAccounts", []);
const signer = await provider.getSigner();
const address = await signer.getAddress();
return address;
} else {
throw new Error('No wallet detected');
}
}Step 4: Initialize PrismGPT
import { Prism } from './sdk/prism.js';
const prism = new Prism(
'your-api-key',
'https://prismgpt.io'
);
// Track the connected wallet
const wallet = await connectWallet();
await prism.trackUser(wallet);Step 5: Use AI Agents
async function askAI(prompt, agent = 'general') {
const wallet = await connectWallet();
const response = await prism.requestAI(
agent,
prompt,
wallet
);
return response.response;
}
// Example usage
const answer = await askAI(
'What are the gas fees on BNB Chain?',
'general'
);
console.log(answer);Step 6: Implement Rewards
async function claimDailyReward() {
const wallet = await connectWallet();
// Check if can claim
const status = await prism.checkRewardsStatus(wallet);
if (!status.canClaim) {
console.log('Cooldown active:', status.cooldownRemaining, 'seconds');
return null;
}
// Claim reward
const result = await prism.spinRewards(wallet);
console.log('Claimed:', result.amount, 'BNB');
return result;
}Complete Integration Example
import { ethers } from 'ethers';
import { Prism } from './sdk/prism.js';
class PrismGPTIntegration {
constructor(apiKey) {
this.prism = new Prism(apiKey);
this.wallet = null;
}
async connect() {
const provider = new ethers.BrowserProvider(window.ethereum);
const accounts = await provider.send("eth_requestAccounts", []);
const signer = await provider.getSigner();
this.wallet = await signer.getAddress();
// Track user
await this.prism.trackUser(this.wallet);
return this.wallet;
}
async askQuestion(question, agent = 'general') {
if (!this.wallet) await this.connect();
const response = await this.prism.requestAI(
agent,
question,
this.wallet
);
return response.response;
}
async claimReward() {
if (!this.wallet) await this.connect();
const status = await this.prism.checkRewardsStatus(this.wallet);
if (status.canClaim) {
return await this.prism.spinRewards(this.wallet);
}
return { error: 'Cooldown active', cooldown: status.cooldownRemaining };
}
async getMyRank() {
const leaderboard = await this.prism.getLeaderboard();
const myEntry = leaderboard.leaderboard.find(
entry => entry.wallet.toLowerCase() === this.wallet.toLowerCase()
);
return myEntry || null;
}
}
// Usage
const integration = new PrismGPTIntegration('your-api-key');
// Connect wallet
await integration.connect();
// Ask AI
const answer = await integration.askQuestion(
'Explain how to optimize gas fees',
'developer'
);
// Claim rewards
const reward = await integration.claimReward();
// Check rank
const rank = await integration.getMyRank();Best Practices
Security
Never expose your API key in client-side code. Use environment variables and server-side proxies.
Performance
Cache responses when possible and implement proper error handling.
User Experience
Show loading states during API calls and provide clear feedback for cooldown periods.