> ## Documentation Index
> Fetch the complete documentation index at: https://pons-labs-llc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Launching from code

> The v3 launch call, how much value to send, locking in the launch terms, and how to get a launch's pool id.

Launching takes one call, and the value sent has to be exact. For an ERC-20 quote
asset, send the launch fee. For a native ETH launch, send the launch fee plus the
opening buy. Any other amount reverts. For an ERC-20 quote asset, approve the
factory for the opening buy amount first.

```ts A launch theme={null}
import { parseAbi, toHex } from "viem";

const factoryAbi = parseAbi([
  "struct Socials { string twitter; string telegram; string discord; string website; string farcaster; }",
  "struct TokenParams { string name; string symbol; string logo; string description; Socials socials; address creatorFeeRecipient; uint16 creatorTaxBps; bool buybackEnabled; bytes32 expectedEconomics; bytes32 salt; }",
  "function launchTokenInstant(TokenParams params, uint256 launchConfigId, address pairToken, uint256 devBuyQuote, uint256 minDevBuyOut) payable returns (address token, uint256 positionId)",
  "function previewLaunchEconomics(uint256 launchConfigId, address pairToken) view returns (bytes32)",
  "function launchFee() view returns (uint256)",
]);

const launchConfigId = 0n;
const pairToken = "0x0000000000000000000000000000000000000000"; // native ETH
const devBuyQuote = 0n; // optional opening buy, in the quote asset
const salt = toHex(crypto.getRandomValues(new Uint8Array(32)));

// Read the current terms right before submitting and pass them in.
const [expectedEconomics, launchFee] = await Promise.all([
  client.readContract({
    address: factory,
    abi: factoryAbi,
    functionName: "previewLaunchEconomics",
    args: [launchConfigId, pairToken],
  }),
  client.readContract({
    address: factory,
    abi: factoryAbi,
    functionName: "launchFee",
  }),
]);

const hash = await wallet.writeContract({
  address: factory,
  abi: factoryAbi,
  functionName: "launchTokenInstant",
  args: [
    {
      name: "Moon Cat",
      symbol: "MCAT",
      logo: "https://example.com/mcat.png",
      description: "A cat, on the moon.",
      socials: {
        twitter: "mooncat",
        telegram: "",
        discord: "",
        website: "",
        farcaster: "",
      },
      // Zero means the caller, so set it when launching for someone else.
      creatorFeeRecipient: user,
      creatorTaxBps: 0,
      buybackEnabled: false,
      expectedEconomics,
      salt,
    },
    launchConfigId,
    pairToken,
    devBuyQuote,
    0n, // minDevBuyOut
  ],
  // Native launch: fee plus the opening buy. ERC-20 quote: fee only.
  value: launchFee + devBuyQuote,
});
```

> [!WARNING]
>
> Set `creatorFeeRecipient` explicitly. If it's zero, the caller becomes the
> recipient. If you launch for a user and leave it at zero, your wallet gets their
> fees and their vest.

## Configs and quote assets

Each launch picks a config by id and a quote asset by address. The config sets
the supply and pool settings. The opening price comes from the config for native
launches, and from the quote asset's own settings for ERC-20 launches. Check that
a quote asset is approved before offering it, and check `canLaunch` before
quoting a launch, since launching can be paused while whitelisted wallets can
still launch.

```ts Reading the terms theme={null}
// Configs are append-only, so an id always means the same config. They can
// be disabled, so load the list when building the form.
const factoryAbi = parseAbi([
  "struct LaunchConfig { uint256 supply; uint24 poolFee; int24 tickSpacing; int24 openingTick; bool enabled; }",
  "function launchConfigCount() view returns (uint256)",
  "function getLaunchConfig(uint256 id) view returns (LaunchConfig)",
  "function approvedPairTokens(address pairToken) view returns (bool)",
  "function pairTokenEconomics(address pairToken) view returns (uint8 decimals, int24 openingTick, uint256 supply)",
  "function canLaunch(address launcher) view returns (bool)",
]);

// A native launch opens at the config's openingTick. A launch against an
// approved ERC-20 opens at that asset's own openingTick instead.
const economics = await client.readContract({
  address: factory,
  abi: factoryAbi,
  functionName: "pairTokenEconomics",
  args: [pairToken],
});
```

## Pinned terms

Read `previewLaunchEconomics` right before launching and pass the result as
`expectedEconomics`. If the protocol changes the config or fee settings in
between, the launch reverts instead of going through on terms you didn't quote.
Passing zero skips the check. The value is a hash of the supply, pool settings,
fee settings and opening tick. It's computed differently from v2, so always read
it from the v3 factory. Don't reuse a v2 value or build it yourself.

## Deriving the pool id

Most hook functions take a pool id, and the factory doesn't store it. Rebuild the
pool key from the launch record and hash it. Currencies are sorted by address,
and native ETH is the zero address, so it always comes first.

```ts From a token address to a pool id theme={null}
import { encodeAbiParameters, keccak256, parseAbi } from "viem";

const factoryAbi = parseAbi([
  "struct LaunchedToken { address token; address curve; address deployer; address creatorFeeRecipient; address pairToken; uint256 graduationThreshold; uint24 poolFee; int24 tickSpacing; uint16 creatorTaxBps; bool buybackEnabled; uint8 phase; uint256 sweptQuote; uint256 sweptTokens; uint256 sweptAt; bool exists; }",
  "function getLaunchedToken(address token) view returns (LaunchedToken)",
]);

const launch = await client.readContract({
  address: factory,
  abi: factoryAbi,
  functionName: "getLaunchedToken",
  args: [token],
});

// Currencies sort by address. Native ETH is the zero address, so it is
// always currency0.
const [currency0, currency1] =
  BigInt(token) < BigInt(launch.pairToken)
    ? [token, launch.pairToken]
    : [launch.pairToken, token];

const poolId = keccak256(
  encodeAbiParameters(
    [
      { type: "address" }, // currency0
      { type: "address" }, // currency1
      { type: "uint24" },  // fee
      { type: "int24" },   // tickSpacing
      { type: "address" }, // hooks
    ],
    [currency0, currency1, launch.poolFee, launch.tickSpacing, memeHook],
  ),
);
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.