Introduction
Real-time monitoring of token activities on Solana is crucial for developers, traders, and decentralized application (dApp) users. This guide explores how to leverage Shyft Callback APIs to track token events like mints, burns, and swaps instantly.
👉 Discover how Solana's real-time tracking can enhance your dApp
Prerequisites
1. Shyft API Key
- Register for a free account on Shyft to obtain your
x-api-key. - This key authenticates access to Shyft’s callback services.
2. Supabase Setup
- Use Supabase (or any preferred database) to store callback data.
- Follow this Next.js + Supabase guide for integration.
Step-by-Step Implementation
Step 1: Register a Callback for Token Addresses
Shyft allows registering callbacks for specific token addresses to receive instant updates.
Example Code (Shyft JS SDK):
import { Network, ShyftSdk, TxnAction } from "@shyft-to/js";
const shyft = new ShyftSdk({
apiKey: "YOUR_API_KEY",
network: Network.Mainnet,
});
await shyft.callback.register({
network: Network.Mainnet,
addresses: ["TOKEN_ADDRESS"],
callbackUrl: "YOUR_API_ENDPOINT", // e.g., `/api/callback`
events: [TxnAction.TOKEN_MINT, TxnAction.TOKEN_BURN, TxnAction.SWAP],
});Step 2: Configure Callback API
Create a POST endpoint to process Shyft’s real-time data and store it in Supabase.
Key Actions:
- Validate transaction types (
MINT,BURN,SWAP). - Insert
type,timestamp, andactiondata into Supabase.
Example Endpoint:
import { supabase } from "@/lib/supabase";
export async function POST(req: Request) {
const body = await req.json();
const { data, error } = await supabase.from("token_activities").insert({
type: body.type,
timestamp: body.timestamp,
action: body.actions[0], // First action details
});
return Response.json({ success: !error });
}Step 3: Display Real-Time Data
Use Supabase’s real-time subscriptions to update the front-end dynamically.
Example (React Hook):
useEffect(() => {
const channel = supabase
.channel("token_updates")
.on("postgres_changes", {
event: "INSERT",
table: "token_activities",
}, (payload) => {
setTransactions((prev) => [payload.new, ...prev]);
})
.subscribe();
return () => channel.unsubscribe();
}, []);UI Examples:
- Swap: Display token pairs and values.
- Mint/Burn: Show token quantities and affected wallets.
👉 Explore advanced Solana tracking techniques
FAQs
1. What events can Shyft callbacks track?
Shyft supports tracking MINT, BURN, SWAP, and other token-related events.
2. Is Supabase mandatory for callback storage?
No—any database (Firebase, PostgreSQL) can store callback data.
3. Can I use Discord for callback notifications?
Yes! Replace callbackUrl with a Discord webhook URL and set type: DISCORD.
Conclusion
Shyft’s callback APIs simplify real-time token tracking on Solana. By following this guide, you can:
- Monitor token activities instantly.
- Store data efficiently using Supabase.
- Display updates via a responsive front-end.
Resources: