Subscriptions
π‘ Subscriptions API
The GoFundMeme SDK provides a WebSocket-based subscription system that allows real-time updates for Fair Launches, Bonding Curve swaps, Market Capitalization changes, Pool State updates, and more.
With gfmSDK.api.subscription, developers can efficiently listen to live events without polling.
π₯ Key Features
βοΈ Real-Time Pool State Updates β Get notified when a poolβs status changes.
βοΈ Live Market Cap Updates β Track the market cap of a token dynamically.
βοΈ Bonding Curve Swaps β Receive buy/sell events in real-time.
βοΈ Fair Launch Funding Events β Monitor funding and defunding actions.
βοΈ New & Migrated Pools β Be alerted when a pool is created or migrated.
βοΈ Seamless Disconnection β Easily unsubscribe when needed.
π How to Use Subscriptions
To start listening to real-time events, you can use the gfmSDK.api.subscription object and call one of the available listeners.
π Quick Example
import { Connection } from "@solana/web3.js";
import { initGoFundMemeSDK, NETWORK } from "@gofundmeme/sdk";
const connection = new Connection("https://api.mainnet-beta.solana.com");
(async () => {
const gfmSDK = await initGoFundMemeSDK({ connection });
// Listen for funding events on Fair Launch pools in Mainnet
const listener = gfmSDK.api.subscription.fairLaunch.funding.all(NETWORK.MAINNET);
listener.subscription.subscribe((event) => {
console.log("π‘ Fair Launch Funding Event:", event);
});
})();
π οΈ Explanation:
1οΈβ£ Initialize the SDK with a Solana RPC connection.
2οΈβ£ Subscribe to a WebSocket event (gfmSDK.api.subscription.fairLaunch.funding.all).
3οΈβ£ Log incoming events in real time.
π‘ Available Subscription Methods
1οΈβ£ Pool State Updates
Listens for pool state changes, such as raising, launching, or launched.
Subscribe by Network
const listener = gfmSDK.api.subscription.poolState.all(NETWORK.MAINNET);
listener.subscription.subscribe((event) => console.log("π‘ Pool State Update:", event));
Subscribe by Mint Address
const listener = gfmSDK.api.subscription.poolState.byMintAddress("YOUR_MINT_ADDRESS");
listener.subscription.subscribe((event) => console.log("π‘ Pool State Update:", event));
π Event Type:
type PoolStateEvent = {
status: PoolStatus;
totalRaised: number;
raisePercent: number;
token: TokenInfo;
pool: PoolInfo;
raiseType: RaiseType;
dexType: DexType;
network: NETWORK;
}
2οΈβ£ Market Cap Updates
Tracks market capitalization changes in real-time.
Subscribe by Network
const listener = gfmSDK.api.subscription.marketcap.all(NETWORK.MAINNET);
listener.subscription.subscribe((event) => console.log("π‘ Market Cap Update:", event));
Subscribe by Mint Address
const listener = gfmSDK.api.subscription.marketcap.byMintAddress("YOUR_MINT_ADDRESS");
listener.subscription.subscribe((event) => console.log("π‘ Market Cap Update:", event));
π Event Type:
type MarketcapUpdateEvent = {
network: NETWORK;
mintAddress: string;
mcSOL: number;
}
3οΈβ£ Bonding Curve Swaps
Listens for buy and sell transactions on Bonding Curve pools.
Subscribe by Network
const listener = gfmSDK.api.subscription.bondingCurve.swaps.all(NETWORK.MAINNET);
listener.subscription.subscribe((event) => console.log("π‘ Swap Event:", event));
Subscribe by Mint Address
const listener = gfmSDK.api.subscription.bondingCurve.swaps.byMintAddress("YOUR_MINT_ADDRESS");
listener.subscription.subscribe((event) => console.log("π‘ Swap Event:", event));
π Event Type:
type SwapEvent = {
direction: 'buy' | 'sell';
solAmountChange: number;
tokenAmountChange: number;
price: number;
pooledSOL: number;
targetSOL: number;
poolAddress: string;
funderAddress: string;
mintAddress: string;
txid: string;
}
4οΈβ£ Fair Launch Funding Events
Tracks contributions (funding) and withdrawals (defunding) from Fair Launch pools.
Subscribe by Network
const listener = gfmSDK.api.subscription.fairLaunch.funding.all(NETWORK.MAINNET);
listener.subscription.subscribe((event) => console.log("π‘ Funding Event:", event));
Subscribe by Mint Address
const listener = gfmSDK.api.subscription.fairLaunch.funding.byMintAddress("YOUR_MINT_ADDRESS");
listener.subscription.subscribe((event) => console.log("π‘ Funding Event:", event));
π Event Type:
type FundingEvent = {
direction: 'fund' | 'defund';
solAmountChange: number;
pooledSOL: number;
targetSOL: number;
poolAddress: string;
funderAddress: string;
mintAddress: string;
txid: string;
}
5οΈβ£ New & Migrated Pools
These subscriptions notify you when a pool is created or migrated.
New Pools (All Networks)
const listener = gfmSDK.api.subscription.pool.newPools(NETWORK.MAINNET);
listener.subscription.subscribe((event) => console.log("π‘ New Pool Created:", event));
Migrated Pools (All Networks)
const listener = gfmSDK.api.subscription.pool.migratedPools(NETWORK.MAINNET);
listener.subscription.subscribe((event) => console.log("π‘ Pool Migrated:", event));
π Event Type:
type PoolStateEvent = {
status: PoolStatus;
totalRaised: number;
raisePercent: number;
token: TokenInfo;
pool: PoolInfo;
raiseType: RaiseType;
dexType: DexType;
network: NETWORK;
}
π Unsubscribing & Disconnecting
You can unsubscribe from a specific subscription or disconnect from all WebSocket events.
Unsubscribe from a Specific Event
const listener = gfmSDK.api.subscription.fairLaunch.funding.all(NETWORK.MAINNET);
listener.subscription.subscribe((event) => console.log("π‘ Funding Event:", event));
// After 30 seconds, unsubscribe
setTimeout(() => {
console.log("π Disconnecting from funding events...");
listener.disconnect();
}, 30000);
Disconnect from All Subscriptions
gfmSDK.api.subscription.disconnectAll();
console.log("π« All WebSocket connections closed.");
π― Final Summary
Subscription Type
Method
Pool State Updates
poolState.all(network), poolState.byMintAddress(mintAddress)
Market Cap Updates
marketcap.all(network), marketcap.byMintAddress(mintAddress)
Bonding Curve Swaps
bondingCurve.swaps.all(network), bondingCurve.swaps.byMintAddress(mintAddress)
Fair Launch Funding
fairLaunch.funding.all(network), fairLaunch.funding.byMintAddress(mintAddress)
New Pools
pool.newPools(network)
Migrated Pools
pool.migratedPools(network)
Unsubscribe
listener.disconnect()
Disconnect All
gfmSDK.api.subscription.disconnectAll()
π Instant Updates β No need for manual polling!
β‘ Efficient WebSockets β Optimized real-time data streams.
π Simple API β Easy to integrate, minimal effort required.
Last updated