# Read me

**📦 Live on npm:** [`@tontonfun/sdk`](https://www.npmjs.com/package/@tontonfun/sdk)

`@tontonfun/sdk` is a wallet-agnostic TypeScript SDK for the tonton bonding-curve launchpad on TON. It gives you:

* **Off-chain quote math** that mirrors the deployed contract bit-for-bit (so your previews are correct to the last unit).
* **Body builders** for every tonton op (`LAUNCH_TOKEN`, `BUY_TOKENS`, `SELL_TRANSFER`, `GRADUATE`, `RETRY_MINT`, `RETRY_DEPOSIT`).
* **Get-method readers** for curve state, jetton wallets, deterministic curve addresses.
* **Envelope helpers** (`prepareBuyTx`, `prepareSellTx`) that return `{ to, value, body }` — drop into TonConnect, `@ton/ton`, blueprint, raw RPC, whatever you use to sign.

The SDK does *not* sign transactions. Hand the envelope to your sender of choice.

## Install

{% tabs %}
{% tab title="npm" %}

```bash
npm install @tontonfun/sdk @ton/core @ton/ton
```

{% endtab %}

{% tab title="bun" %}

```bash
bun add @tontonfun/sdk @ton/core @ton/ton
```

{% endtab %}
{% endtabs %}

`@ton/core` and `@ton/ton` are peer dependencies — the SDK uses their `Address`, `Cell`, and `TonClient` types but doesn't pin them.

## Module layout

| Import                         | Contents                                                                                                                            |
| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- |
| `@tontonfun/sdk`               | Re-exports everything below — most apps just need this.                                                                             |
| `@tontonfun/sdk` → codec       | `buildBuyTokens`, `buildSellTransfer`, `buildLaunchToken`, `buildOffchainContent`, decoders (`tryDecode*`, `peekOp`), `ipfsToHttp`. |
| `@tontonfun/sdk` → curve       | All bonding-curve math + constants.                                                                                                 |
| `@tontonfun/sdk` → get-methods | `getCurveAddress`, `getCurveState`, `getJettonWalletAddress`, `getJettonWalletBalance`.                                             |
| `@tontonfun/sdk` → tx          | `prepareBuyTx`, `prepareSellTx`, `sendInternal`, `pollUntil`, `newRandomQueryId`, `envelopeToTonConnect`.                           |
| `@tontonfun/sdk` → ops         | The `OP` opcode map.                                                                                                                |
| `@tontonfun/sdk` → constants   | `MAINNET_FACTORY`, `STONFI_ROUTER`.                                                                                                 |
| `@tontonfun/sdk` → network     | `tonViewerTxUrl`, `tonViewerAddrUrl`, `stonFiSwapUrl`.                                                                              |

## Quick example

```ts
import {
  getCurveState,
  prepareBuyTx,
  envelopeToTonConnect,
  tonToNano,
} from "@tontonfun/sdk";
import { TonClient } from "@ton/ton";
import { TonConnectUI } from "@tonconnect/ui-react";

const client = new TonClient({
  endpoint: "https://toncenter.com/api/v2/jsonRPC",
});

const curveAddress = "EQBM0PUXzH6BAtkGhNo1RKhQLOy1dhuB49EiEtF1AYq6GKR3";
const state = await getCurveState(client, curveAddress);

const tx = prepareBuyTx({
  curve: curveAddress,
  tonAmount: tonToNano(1),
  curveState: state,
  slippagePct: 5,
});

// Hand off to TonConnect — no SDK opinion about signing.
await tonConnectUI.sendTransaction({
  validUntil: Math.floor(Date.now() / 1000) + 360,
  messages: [envelopeToTonConnect(tx)],
});
```

See [Quickstart](broken://pages/62c84d56f6052f931acf805acc1dd0303d7da7c2) for full read/buy/sell/launch examples and [Reference](broken://pages/c2f33f35cf8bb447fe3d5438184fefcf18fa7e47) for every public function.


---

# Agent Instructions: 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:

```
GET https://docs.tonton.fun/sdk/read-me.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
