create-token
Generate a new token on the Pump.fun platform by specifying name, symbol, description, initial buy amount in SOL, and optional image URL. Ideal for deploying Solana-based assets efficiently.
Instructions
Create a new Pump.fun token
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountName | No | Name of the account to use (will be created if it doesn't exist) | default |
| description | Yes | Token description | |
| imageUrl | No | URL to token image (optional) | |
| initialBuyAmount | Yes | Initial buy amount in SOL | |
| name | Yes | Token name | |
| symbol | Yes | Token symbol |
Implementation Reference
- src/create-token.ts:22-105 (handler)Core handler function executing the token creation logic: balance check, mint generation, metadata setup, SDK call to createAndBuy, and result processing.export async function createToken( name: string, symbol: string, description: string, imageUrl: string | undefined, initialBuyAmount: number, accountName: string = "default" ) { try { const { sdk, connection } = initializeSDK(); const keysFolder = path.resolve(rootDir, ".keys"); const account = getOrCreateKeypair(keysFolder, accountName); const balance = await connection.getBalance(account.publicKey); const requiredBalance = initialBuyAmount * LAMPORTS_PER_SOL + 0.003 * LAMPORTS_PER_SOL; if (balance < requiredBalance) { return { success: false, error: `Insufficient SOL balance. Account ${account.publicKey.toString()} has ${ balance / LAMPORTS_PER_SOL } SOL, but needs at least ${ requiredBalance / LAMPORTS_PER_SOL } SOL. Please send SOL to this address and try again.`, }; } const mint = Keypair.generate(); let fileBlob: Blob | undefined; if (imageUrl) { const imageData = fs.readFileSync(imageUrl); fileBlob = new Blob([imageData], { type: "image/png" }); } const tokenMetadata: any = { name, symbol, description, file: fileBlob, }; const result = await sdk.createAndBuy( account, mint, tokenMetadata, BigInt(initialBuyAmount * LAMPORTS_PER_SOL), DEFAULT_SLIPPAGE_BASIS_POINTS, DEFAULT_PRIORITY_FEES ); if (!result.success) { return { success: false, error: result.error || "Unknown error", }; } fs.writeFileSync( path.join(keysFolder, `mint-${mint.publicKey.toString()}.json`), safeStringify(Array.from(mint.secretKey)) ); const tokenBalance = await getSPLBalance( connection, mint.publicKey, account.publicKey ); return { success: true, tokenAddress: mint.publicKey.toString(), tokenName: name, tokenSymbol: symbol, tokenBalance, signature: result.signature, pumpfunUrl: `https://pump.fun/${mint.publicKey.toString()}`, }; } catch (error: any) { console.error("Error creating token:", error); return { success: false, error: error?.message || "Unknown error" }; } }
- src/index.ts:101-116 (schema)Zod input schema defining parameters for the create-token tool: name, symbol, description, optional imageUrl, initialBuyAmount, and accountName.{ name: z.string().describe("Token name"), symbol: z.string().describe("Token symbol"), description: z.string().describe("Token description"), imageUrl: z.string().optional().describe("URL to token image (optional)"), initialBuyAmount: z .number() .min(0.0001) .describe("Initial buy amount in SOL"), accountName: z .string() .default("default") .describe( "Name of the account to use (will be created if it doesn't exist)" ), },
- src/index.ts:98-150 (registration)MCP server.tool registration for 'create-token', including description, input schema, and thin wrapper handler that invokes the core createToken function and formats response.server.tool( "create-token", "Create a new Pump.fun token", { name: z.string().describe("Token name"), symbol: z.string().describe("Token symbol"), description: z.string().describe("Token description"), imageUrl: z.string().optional().describe("URL to token image (optional)"), initialBuyAmount: z .number() .min(0.0001) .describe("Initial buy amount in SOL"), accountName: z .string() .default("default") .describe( "Name of the account to use (will be created if it doesn't exist)" ), }, async ({ name, symbol, description, imageUrl, initialBuyAmount, accountName, }) => { try { const result = await createToken( name, symbol, description, imageUrl, initialBuyAmount, accountName ); const formattedResult = formatCreateTokenResult(result); return createMcpResponse(formattedResult); } catch (error: any) { console.error("Error creating token:", error); return { content: [ { type: "text", text: `Error creating token: ${error?.message || "Unknown error"}`, }, ], }; } } );
- src/create-token.ts:107-123 (helper)Helper function to format the createToken result into a human-readable multi-line string for display in MCP response.export function formatCreateTokenResult( result: ReturnType<typeof createToken> extends Promise<infer T> ? T : never ) { if (!result.success) { return `Error creating token: ${result.error}`; } return [ `Successfully created token!`, `Token Address: ${result.tokenAddress}`, `Token Name: ${result.tokenName}`, `Token Symbol: ${result.tokenSymbol}`, `Your Balance: ${result.tokenBalance}`, `Transaction Signature: ${result.signature}`, `Pump.fun URL: ${result.pumpfunUrl}`, ].join("\n"); }