Examples

Full Token Creation Flow

Complete example: authenticate → deploy token on-chain → upload image → create metadata.

End-to-End Example
// Full token creation flow: deploy on-chain → upload image → create metadata
import { ethers } from "ethers";

async function createToken(sessionCookie) {
  const provider = new ethers.JsonRpcProvider("https://bsc-dataseed.binance.org");
  const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);

  // 1. Deploy token on-chain via Factory contract
  const factory = new ethers.Contract(FACTORY_ADDRESS, FACTORY_ABI, wallet);
  const tx = await factory.createToken(
    "SYM",           // symbol
    "My Token",      // name
    50,              // hybridMultiplier
    false,           // frozen
    10000,           // bondingUSDC
    1000,            // startLP
    false,           // autoVest
    0,               // vestingDays
    false,           // gradualVesting
    { value: ethers.parseEther("0.00001") }
  );
  const receipt = await tx.wait();
  const tokenAddress = receipt.logs[0].address;

  // 2. Upload image (purpose: "token" + address required)
  const imageFile = new File([imageBuffer], `${tokenAddress}.webp`, { type: "image/webp" });
  const formData = new FormData();
  formData.append("file", imageFile);
  formData.append("purpose", "token");
  formData.append("address", tokenAddress);

  const imgRes = await fetch("https://launchonbasis.com/api/images", {
    method: "POST",
    headers: { "Cookie": sessionCookie },
    body: formData,
  });
  const { url: imageUrl } = await imgRes.json();

  // 3. Create metadata (server verifies you are the on-chain DEV)
  await fetch("https://launchonbasis.com/api/metadata", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Cookie": sessionCookie,
    },
    body: JSON.stringify({
      address: tokenAddress,
      description: "Created via the API",
      image: imageUrl,
    }),
  });

  return tokenAddress;
}