mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-30 00:37:51 +00:00
docs: update documentation to reflect changes from TON to GRAM, including method renaming and new top-up method
This commit is contained in:
@@ -8,19 +8,21 @@ FragmentClient(
|
||||
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, 18, or 24 words**)
|
||||
- `api_key`: Tonapi key from https://tonconsole.com
|
||||
- `seed`: wallet mnemonic (**12 or 24 words**)
|
||||
- `api_key`: API key — from [tonconsole.com](https://tonconsole.com) (tonapi) or [@toncenter](https://t.me/toncenter)
|
||||
- `cookies`: Fragment cookies as a dictionary or JSON string
|
||||
- `wallet_version`: `"V4R2"` or `"V5R1"`
|
||||
- `wallet_version`: `"V4R2"`, `"V5R1"`, `"HighloadV2"`, or `"HighloadV3R1"`
|
||||
- `api_provider`: blockchain API provider — `"tonapi"` (default) or `"toncenter"`
|
||||
- `timeout`: request timeout in seconds
|
||||
|
||||
**If `api_key` is too short or cookies are incomplete, initialization fails immediately.**
|
||||
**If `api_key` or cookies are missing, initialization fails immediately.**
|
||||
|
||||
## Required cookies
|
||||
|
||||
@@ -34,26 +36,34 @@ FragmentClient(
|
||||
```python
|
||||
from pyfragment import FragmentClient
|
||||
|
||||
client = FragmentClient(
|
||||
async with FragmentClient(
|
||||
seed="word1 word2 ... word24",
|
||||
api_key="YOUR_TONAPI_KEY",
|
||||
api_key="YOUR_API_KEY",
|
||||
cookies={
|
||||
"stel_ssid": "...",
|
||||
"stel_dt": "...",
|
||||
"stel_token": "...",
|
||||
"stel_ton_token": "...",
|
||||
},
|
||||
)
|
||||
```
|
||||
|
||||
Use it inside async context manager:
|
||||
|
||||
```python
|
||||
async with client:
|
||||
) as client:
|
||||
wallet = await client.get_wallet()
|
||||
```
|
||||
|
||||
You can also create the client directly inside `async with` if you prefer one-block setup.
|
||||
## Switching API provider
|
||||
|
||||
By default, the library uses [tonconsole.com](https://tonconsole.com) (tonapi). To use [toncenter](https://t.me/toncenter) instead, pass `api_provider="toncenter"`:
|
||||
|
||||
```python
|
||||
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
|
||||
|
||||
@@ -62,8 +72,7 @@ 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`.
|
||||
|
||||
**Tip:** keep validation failures visible in logs during initial integration. They save a lot of debugging time.
|
||||
|
||||
@@ -8,7 +8,7 @@ Generate an API key at https://tonconsole.com.
|
||||
|
||||
## Seed phrase
|
||||
|
||||
Use your TON wallet mnemonic.
|
||||
Use your GRAM (ex TON) wallet mnemonic.
|
||||
|
||||
- **Keep it private.**
|
||||
- **Never log it or commit it to git.**
|
||||
|
||||
@@ -6,21 +6,33 @@ Use this minimal example to verify that your credentials, cookies, and wallet se
|
||||
import asyncio
|
||||
|
||||
from pyfragment import FragmentClient
|
||||
from pyfragment.enums import PaymentMethod
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
async with FragmentClient(
|
||||
seed="word1 word2 ... word24",
|
||||
api_key="YOUR_TONAPI_KEY",
|
||||
api_key="YOUR_API_KEY", # tonconsole.com (tonapi, default) or t.me/toncenter
|
||||
cookies={
|
||||
"stel_ssid": "...",
|
||||
"stel_dt": "...",
|
||||
"stel_token": "...",
|
||||
"stel_ton_token": "...",
|
||||
},
|
||||
wallet_version="V5R1", # or "V4R2", "HighloadV2", "HighloadV3R1"
|
||||
api_provider="tonapi", # or "toncenter"
|
||||
) as client:
|
||||
wallet = await client.get_wallet()
|
||||
print(wallet)
|
||||
print(f"GRAM: {wallet.gram_balance} | USDT: {wallet.usdt_balance}")
|
||||
|
||||
recipient = "https://t.me/username" # also: @username, username
|
||||
|
||||
stars = await client.purchase_stars(recipient, amount=500, payment_method=PaymentMethod.USDT_GRAM)
|
||||
print(f"Sent {stars.amount} Stars to {stars.username} | tx: {stars.transaction_id}")
|
||||
|
||||
premium = await client.purchase_premium(recipient, months=6, payment_method=PaymentMethod.GRAM)
|
||||
print(f"Sent Premium {premium.amount}m to {premium.username} | tx: {premium.transaction_id}")
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user