import dotenv from "dotenv";
dotenv.config({ quiet: true });
import { BagsSDK } from "@bagsfm/bags-sdk";
import { PublicKey, Connection } from "@solana/web3.js";
// Initialize SDK
const BAGS_API_KEY = process.env.BAGS_API_KEY;
const SOLANA_RPC_URL = process.env.SOLANA_RPC_URL;
if (!BAGS_API_KEY || !SOLANA_RPC_URL) {
throw new Error("BAGS_API_KEY and SOLANA_RPC_URL are required");
}
const connection = new Connection(SOLANA_RPC_URL);
const sdk = new BagsSDK(BAGS_API_KEY, connection, "processed");
async function getTokenCreators(tokenMint: string) {
try {
console.log(`🔍 Fetching token creators for: ${tokenMint}`);
const creators = await sdk.state.getTokenCreators(new PublicKey(tokenMint));
console.log(`📊 Found ${creators.length} creator(s)/deployer(s)`);
const primaryCreator = creators.find(c => c.isCreator);
if (!primaryCreator) {
throw new Error("❌ No primary creator found for this token!");
}
console.log("✨ Primary Creator Details:");
console.log(`👤 Display Name: ${primaryCreator.providerUsername ?? primaryCreator.username ?? "N/A"}`);
console.log(`🔗 Provider: ${primaryCreator.provider ?? "unknown"}`);
console.log(`👛 Wallet: ${primaryCreator.wallet}`);
console.log(`🎨 Profile Picture: ${primaryCreator.pfp}`);
console.log(`💰 Royalty: ${primaryCreator.royaltyBps / 100}%`);
const others = creators.filter(c => !c.isCreator);
if (others.length > 0) {
console.log("\n🤝 Other Launch Participants:");
others.forEach((participant, idx) => {
console.log(`\n#${idx + 1}`);
console.log(`👤 Display Name: ${participant.providerUsername ?? participant.username ?? "N/A"}`);
console.log(`🔗 Provider: ${participant.provider ?? "unknown"}`);
console.log(`👛 Wallet: ${participant.wallet}`);
console.log(`🎨 Profile Picture: ${participant.pfp}`);
console.log(`💰 Royalty: ${participant.royaltyBps / 100}%`);
});
} else {
console.log("\n📝 No additional launch participants found for this token");
}
console.log("\n✅ Successfully retrieved token creators!");
}
catch (error) {
console.error("🚨 Error fetching token creators:", error);
}
}
getTokenCreators("CyXBDcVQuHyEDbG661Jf3iHqxyd9wNHhE2SiQdNrBAGS");