A TypeScript SDK for seamless interaction with the Flaunch protocol and Uniswap V4.
Note: Add this llms-full.txt
file into Cursor IDE / LLMs to provide context about using the Flaunch SDK: llms-full.txt
- 🚀 Flaunch new memecoins
- 💱 Buy and sell memecoins via Uniswap V4 hooks
- 🏗️ Build your own token launchpads on top of the flaunch protocol
- 📊 Read functions for token and pool data
- 🔒 Built-in Permit2 support for gasless approvals
- 🔵 Works on Base and Base Sepolia networks
Using pnpm (recommended):
pnpm add @flaunch/sdk
Using npm:
npm install @flaunch/sdk
Using yarn:
yarn add @flaunch/sdk
Here's a simple example to get started with reading token metadata:
import { createFlaunch } from "@flaunch/sdk";
import { createPublicClient, http } from "viem";
import { base } from "viem/chains";
const publicClient = createPublicClient({
chain: base,
transport: http(),
});
const flaunchRead = createFlaunch({ publicClient });
const { symbol, name, image } = await flaunchRead.getCoinMetadata(coinAddress);
// returns: {symbol: "TEST", name: "Test", image: "https://<IMAGE_URL>"}
The SDK provides two types of operations:
- Read operations: Only require a
publicClient
- Write operations: Require both
publicClient
andwalletClient
import { createFlaunch } from "@flaunch/sdk";
import { createPublicClient, http } from "viem";
import { base } from "viem/chains";
const publicClient = createPublicClient({
chain: base,
transport: http("<RPC_URL>"), // "<RPC_URL>" is optional, defaults to public RPC
});
const flaunchRead = createFlaunch({ publicClient });
// Read token metadata
const { symbol, name, image } = await flaunchRead.getCoinMetadata(coinAddress);
// returns: {symbol: "TEST", name: "Test", image: "https://<IMAGE_URL>"}
For write operations, you'll need both Viem and Wagmi. Here's how to set it up in a React component:
import { createFlaunch, ReadWriteFlaunchSDK } from "@flaunch/sdk";
import { base } from "viem/chains";
import { useWalletClient } from "wagmi";
import { useMemo } from "react";
// ... your React component ...
const publicClient = createPublicClient({
chain: base,
transport: http("<RPC_URL>"), // "<RPC_URL>" is optional, defaults to public RPC
});
const { data: walletClient } = useWalletClient();
const flaunchWrite = useMemo(() => {
if (!publicClient && !walletClient) return null;
return createFlaunch({
publicClient,
walletClient,
}) as ReadWriteFlaunchSDK;
}, [publicClient, walletClient]);
// Execute a buy transaction
const buyTokens = async () => {
const hash = await flaunchWrite.buyCoin({
coinAddress,
slippagePercent: 5,
swapType: "EXACT_IN",
amountIn: parseEther("0.1"),
});
// Wait for confirmation
const receipt = await flaunchWrite.drift.waitForTransaction({ hash });
console.log(receipt.status === "success" ? "Success" : "Failed");
};
Permit2 enables gasless token approvals. Here's how to implement token selling with Permit2:
import { useSignTypedData } from "wagmi";
import { parseEther, Hex } from "viem";
const {
signTypedData,
status: sigStatus,
error: sigError,
data: signature,
} = useSignTypedData();
// Check allowance and permit if needed
const { allowance } = await flaunchWrite.getPermit2AllowanceAndNonce(
coinAddress
);
if (allowance < parseEther(coinAmount)) {
const { typedData, permitSingle } = await flaunchWrite.getPermit2TypedData(
coinAddress
);
signTypedData(typedData);
// then call this when signature is not undefined
const hash = await flaunchWrite.sellCoin({
coinAddress,
amountIn: parseEther(coinAmount),
slippagePercent: 5,
permitSingle,
signature,
});
} else {
// if already approved
const hash = await flaunchWrite.sellCoin({
coinAddress,
amountIn: parseEther(coinAmount),
slippagePercent: 5,
});
}
Flaunch your own memecoin with default parameters:
Flaunches below $10k market caps don't incur any protocol fees!
const hash = await flaunchWrite.flaunchIPFS({
name: "Test",
symbol: "TEST",
fairLaunchPercent: 60, // 60%
fairLaunchDuration: 30 * 60, // 30 mins
initialMarketCapUSD: 10_000, // $10k
creator: address,
creatorFeeAllocationPercent: 80, // 80% to creator, 20% to community
metadata: {
base64Image: imageData, // refer to the code below, on how to generate this base64Image
description: "Your memecoin description",
// optional:
websiteUrl: "https://example.com/",
discordUrl: "https://discord.gg/example",
twitterUrl: "https://x.com/example",
telegramUrl: "https://t.me/example",
},
pinataConfig: {
// Use one-time JWT for client-side uploads
// Refer: https://www.pinata.cloud/blog/how-to-upload-to-ipfs-from-the-frontend-with-signed-jwts/
jwt: pinataJWT,
},
});
// handle image file input and convert into base64
const handleImageChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files[0]) {
const file = e.target.files[0];
// read the file as base64
const reader = new FileReader();
reader.onloadend = () => {
const base64String = reader.result as string;
// this can be passed to the flaunch function call
handleFlaunch({ imageData: base64String });
// use `storedImagePreview` to display the uploaded image with <image src={storedImagePreview} />
setStoredImagePreview(base64String);
};
reader.readAsDataURL(file);
}
},
[setStoredImagePreview]
);
// File upload input
<input
type="file"
accept="image/*"
onchange="handleImageChange(event)"
id="image-upload"
/>;
For platforms building on top of Flaunch, the RevenueManager
contract enables sophisticated revenue-sharing models. It allows platforms to automatically take a protocol fee from the trading fees generated by memecoins launched through their integration.
Key Concepts:
-
Deployment & Initialization: Before flaunching tokens via your platform, deploy an instance of your
RevenueManager
with your protocol fee and recipient address.
const revenueManagerInstanceAddress = await flaunchWrite.deployRevenueManager({
protocolRecipient: "0xabc...",
protocolFeePercent: 20, // 20% revenue share between protocol and 80% to coin creators (of the 1% swap fees)
});
-
Flaunching Directly to Manager: Instead of the creator receiving the Flaunch NFT, you'd flaunch the token directly into the
RevenueManager
. This automatically sets up the fee split.
await flaunchWrite.flaunchIPFSWithRevenueManager({
name: "...",
symbol: "...",
metadata: {
base64Image: "...",
},
pinataConfig: {
jwt: "...",
},
fairLaunchPercent: 40,
fairLaunchDuration: 30 * 60, // 30 mins
initialMarketCapUSD: 1_000,
creator: "0x...",
creatorFeeAllocationPercent: 100,
// **Note:** Specify your instance of the RevenueManager here
revenueManagerInstanceAddress: "...",
});
-
Claiming Fees: Creators can claim their share of earned fees, and the protocol can claim its share via the
RevenueManager
contract.
// check address' balance
const balance = await flaunchRead.revenueManagerBalance({
revenueManagerAddress: revenueManagerInstanceAddress,
recipient: "0xabc...",
});
// protocol claim: the connected wallet must be the protocol recipient for the revenue manager
await flaunchWrite.revenueManagerProtocolClaim({
revenueManagerAddress: revenueManagerInstanceAddress,
});
// creator claim: the connected wallet must be the coin's creator for them to claim their share
await flaunchWrite.revenueManagerCreatorClaim({
revenueManagerAddress: revenueManagerInstanceAddress,
});
// creator claim: for specific flaunch token ids:
await flaunchWrite.revenueManagerCreatorClaimForTokens({
revenueManagerAddress: revenueManagerInstanceAddress,
flaunchTokens: [
{
flaunch: FlaunchAddress[base.id],
tokenId: 5,
},
{
flaunch: FlaunchV1_1Address[base.id],
tokenId: 10,
},
],
});
Refer to the RevenueManager Docs for detailed implementation guides and function references.
For a list of all the functions in the SDK, refer to: FlaunchSDK.ts
The package also has hooks to listen for new Flaunches and new Coin Swaps. Refer to: hooks
import { usePoolCreatedEvents, usePoolSwapEvents } from "@flaunch/sdk/hooks";
const { logs: poolCreatedLogs } = usePoolCreatedEvents(flaunchRead);
const { logs: poolSwapLogs } = usePoolSwapEvents(flaunchRead, coinAddress);
/**
* The `poolSwapLogs` calculates & returns the net swapped amount:
*
* type BuySwapLog = {
* ...eventLog,
* timestamp: number;
* type: "BUY";
* delta: {
* coinsBought: bigint;
* flETHSold: bigint;
* fees: {
* isInFLETH: boolean;
* amount: bigint;
* };
* };
* };
*
* type SellSwapLog = {
* ...eventLog,
* timestamp: number;
* type: "SELL";
* delta: {
* coinsSold: bigint;
* flETHBought: bigint;
* fees: {
* isInFLETH: boolean;
* amount: bigint;
* };
* };
* };
*/
For detailed protocol documentation, visit our Docs.