Files
FragmentAPI/docs/getting-started/configuration.md
T

2.0 KiB

Library and Configuration

Main entry point of the library is FragmentClient.

FragmentClient(
    seed: str,
    api_key: str,
    cookies: dict[str, Any] | str,
    wallet_version: str = "V5R1",
    api_provider: str = "tonapi",
    timeout: float = 30.0,
)

Parameters

  • seed: wallet mnemonic (12 or 24 words)
  • api_key: API key — from tonconsole.com (tonapi) or @toncenter
  • cookies: Fragment cookies as a dictionary or JSON string
  • wallet_version: "V4R2", "V5R1", "HighloadV2", or "HighloadV3R1"
  • api_provider: blockchain API provider — "tonapi" (default) or "toncenter"
  • timeout: request timeout in seconds

If api_key or cookies are missing, initialization fails immediately.

Required cookies

  • stel_ssid
  • stel_dt
  • stel_token
  • stel_ton_token

Minimal initialization pattern

from pyfragment import FragmentClient

async with FragmentClient(
    seed="word1 word2 ... word24",
    api_key="YOUR_API_KEY",
    cookies={
        "stel_ssid": "...",
        "stel_dt": "...",
        "stel_token": "...",
        "stel_ton_token": "...",
    },
) as client:
    wallet = await client.get_wallet()

Switching API provider

By default, the library uses tonconsole.com (tonapi). To use toncenter instead, pass api_provider="toncenter":

async with FragmentClient(
    seed="...",
    api_key="YOUR_TONCENTER_API_KEY",
    cookies={...},
    api_provider="toncenter",
) as client:
    ...

Both providers work identically — the correct tonutils client is selected automatically based on api_provider.

Validation behavior

At initialization, library validates:

  • seed format,
  • cookie shape and required keys,
  • supported wallet version,
  • supported API provider,
  • parseability of cookie JSON strings.

Constructor-level issues are raised as ConfigurationError or CookieError.