> For the complete documentation index, see [llms.txt](https://docs.surged.fun/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.surged.fun/integration/quickstart.md).

# Quickstart

Buying a token, end to end. Node 22 or newer.

```sh
npm add @surged/sdk viem
```

```ts
import { createWalletClient, createPublicClient, http, type Address } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import {
  arc,
  curveStateFromApi,
  encodeBuy,
  minOutWithSlippage,
  previewBuy,
} from '@surged/sdk'

const API = 'https://api.surged.fun'
const token = '0xA65DE690ea02Ec5e2D8071c7943B4a34AD6B026c' as Address

// 1. Read the curve and the head of the chain.
const launch = await fetch(`${API}/launches/${token}`).then((r) => r.json())
const { head } = await fetch(`${API}/health`).then((r) => r.json())

// 2. Price the buy. It lands in the next block, which is what the snipe tax is measured against.
const quoteIn = 10n * 10n ** 18n // 10 USDC
const quote = previewBuy(curveStateFromApi(launch), quoteIn, {
  currentBlock: BigInt(head) + 1n,
})
console.log('tokens out', quote.tokensOut, 'snipe tax', quote.snipeTax)

// 3. Send it. `minTokensOut` is what protects you if the price moves first.
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
const chain = { ...arc, rpcUrls: { default: { http: ['https://rpc.mainnet.arc.io'] } } }
const wallet = createWalletClient({ account, chain, transport: http() })
const publicClient = createPublicClient({ chain, transport: http() })

const call = encodeBuy({
  pairToken: launch.pairToken,
  quoteIn,
  minTokensOut: minOutWithSlippage(quote.tokensOut, 500), // 5%
  recipient: account.address,
})
const hash = await wallet.sendTransaction({ to: launch.curve, ...call })
const receipt = await publicClient.waitForTransactionReceipt({ hash })
console.log(receipt.status)
```

## What to watch

**`quote.crossing`** is `true` when your buy takes the last tokens on the curve and triggers graduation. The curve only sells what is left and refunds the difference, which `quote.refund` tells you in advance.

**`quote.snipeTax`** is the anti-snipe charge, which is severe in the first blocks of a launch: it starts at 99% and reaches zero six blocks later, about three seconds. It is not a bug; see [Fees and the snipe tax](/integration/fees.md).

**Gas comes out of the same balance you are spending.** USDC is the native coin of Arc, so a buy sized at your full balance cannot pay for itself. Keep a reserve; the frontend holds back the worst-case gas at the current base fee, which on a busy day is far above the 20 gwei floor.

## Selling

Selling needs an approval first, because the curve pulls the tokens from you.

```ts
import { encodeSell, launcherTokenAbi, previewSell } from '@surged/sdk'
import { encodeFunctionData } from 'viem'

const quote = previewSell(curveStateFromApi(launch), tokensIn)

await wallet.sendTransaction({
  to: launch.token,
  data: encodeFunctionData({
    abi: launcherTokenAbi,
    functionName: 'approve',
    args: [launch.curve, tokensIn],
  }),
})
await wallet.sendTransaction({
  to: launch.curve,
  ...encodeSell({
    tokensIn,
    minQuoteOut: minOutWithSlippage(quote.quoteOut, 500),
    recipient: account.address,
  }),
})
```

Once a token has graduated its curve stops trading. `launch.phase` tells you: while it is `curve` you trade here, and once it is `pool` you trade on Uniswap. See [Graduation](/integration/graduation.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.surged.fun/integration/quickstart.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
