Skip to content

feat(standard): migrate ton connect cookbook examples#2079

Open
coalus wants to merge 7 commits intoton-org:mainfrom
coalus:feat/cookbook-transfers
Open

feat(standard): migrate ton connect cookbook examples#2079
coalus wants to merge 7 commits intoton-org:mainfrom
coalus:feat/cookbook-transfers

Conversation

@coalus
Copy link
Copy Markdown
Contributor

@coalus coalus commented Apr 10, 2026

resolves #2078

Summary by CodeRabbit

  • Documentation
    • Added guides for Jetton transfers and burns via TON Connect, including transfer-with-comment and burn workflows.
    • Added NFT transfer via TON Connect, plus marketplace listing (GetGems) and purchase verification and buy instructions.
    • Included React and TypeScript end-to-end examples showing transaction assembly, valid-until handling, and payload/amount composition.

@coalus coalus requested a review from a team as a code owner April 10, 2026 20:28
@github-actions
Copy link
Copy Markdown
Contributor

Skipping AI review because this PR is from a fork. A maintainer can start the review by commenting /review in this PR.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cc8bd6f0-d38a-4cf1-b57b-12fc285f6a11

📥 Commits

Reviewing files that changed from the base of the PR and between bc91d22 and c028932.

📒 Files selected for processing (1)
  • standard/tokens/nft/transfer.mdx
🚧 Files skipped from review as they are similar to previous changes (1)
  • standard/tokens/nft/transfer.mdx

📝 Walkthrough

Walkthrough

Added TON Connect examples to jetton and NFT transfer docs: React/TypeScript snippets that build TEP-74 / NFT transfer message bodies, base64-BOC encode them, and submit transfer, burn, list-for-sale, and buy transactions via tonConnectUI. New example components exported in each document.

Changes

Cohort / File(s) Summary
Jetton Transfer Examples
standard/tokens/jettons/transfer.mdx
Added "Transfer via TON Connect" and "Burn via TON Connect" sections with React/TypeScript examples that construct TEP-74 transfer and burn bodies (opcode, query_id, amount, destination/response, optional custom payload / forward_payload/comments), encode as base64 BOC, build a TON Connect transaction, and call tonConnectUI.sendTransaction. Exports TransferJetton and BurnJetton.
NFT Transfer & Marketplace Examples
standard/tokens/nft/transfer.mdx
Added "Transfer via TON Connect", "List an NFT for sale (GetGems)", and "Buy an NFT (GetGems)" sections. Examples build NFT transfer#5fcc3d14 bodies, derive GetGems sale address/stateInit, construct sale forward payloads, perform verification checks (code hash / getters / ownership), and submit transactions via TON Connect. Exports TransferNft and BuyNft.

Sequence Diagram(s)

sequenceDiagram
    participant DApp as DApp (web)
    participant TON as TON Connect UI
    participant Wallet as User Wallet
    participant Chain as TON Blockchain
    participant Contract as Token/Sale Contract

    DApp->>TON: build transaction (base64 BOC message, validUntil)
    TON->>Wallet: request signature & send
    Wallet->>TON: signed transaction
    TON->>Chain: broadcast transaction
    Chain->>Contract: deliver message (transfer / burn / sale)
    Contract-->>Chain: state update
    Chain-->>DApp: confirm transaction status
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I stitched a BOC with care and flair,
Hopped opcodes into the evening air,
Jettons, NFTs in tidy rows,
Wallets wink as the transaction goes,
A rabbit hums—docs bloom and glow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(standard): migrate ton connect cookbook examples' clearly and concisely describes the main change: migrating TON Connect cookbook examples into the standard documentation.
Linked Issues check ✅ Passed The PR successfully addresses issue #2078 by migrating TON Connect cookbook examples into the jetton and NFT transfer documentation pages as required.
Out of Scope Changes check ✅ Passed All changes are within scope: the PR adds TON Connect examples to jetton/NFT transfer pages and includes sale contract verification, which align with the stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
standard/tokens/nft/transfer.mdx (1)

273-275: Avoid floating-point math for TON amounts in examples.

Using JS floats for currency (5.0 + 1.0) is error-prone. Prefer nano amounts (bigint) or string literals before conversion.

♻️ Suggested refactor
- const nftPrice = 5.0; // TON
- const buyAmount = nftPrice + 1.0;
+ const nftPrice = toNano('5'); // TON
+ const buyAmount = nftPrice + toNano('1');

  const transaction = {
    ...
    messages: [
      {
        address: '<NFT_SALE_CONTRACT>',
-       amount: toNano(buyAmount).toString(),
+       amount: buyAmount.toString(),
      },
    ],
  };

Also applies to: 281-282, 301-303, 309-310

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@standard/tokens/nft/transfer.mdx` around lines 273 - 275, Replace JS
floating-point TON literals with explicit nano-TON integer representations or
string-to-nano conversions: change nftPrice and buyAmount to use BigInt nanos
(e.g., nftPriceNano = BigInt(5) * 10n**9n) or keep human strings and convert via
your toNano utility (e.g., toNano("5")). Update every other floating TON literal
in this file (the other numeric currency variables used around the transfer
flow) to follow the same pattern and ensure downstream calls expect the
nano/BigInt or converted value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@standard/tokens/jettons/transfer.mdx`:
- Around line 137-165: The TypeScript examples use an undefined tonConnectUI and
a default import; change the import to the named TonConnectUI and instantiate it
before use (e.g., const tonConnectUI = new TonConnectUI(/* config */)); then
call tonConnectUI.sendTransaction(transaction). Update both blocks that
reference tonConnectUI.sendTransaction to ensure they import { TonConnectUI },
create a tonConnectUI instance (with any required config) and use that instance
when sending the transaction.

In `@standard/tokens/nft/transfer.mdx`:
- Around line 121-147: The snippet imports TonConnectUI but never instantiates
it and also uses a default import instead of the named export; change the import
to a named import (import { TonConnectUI } from '@tonconnect/ui') and create an
instance (e.g., const tonConnectUI = new TonConnectUI({ manifestUrl:
'<YOUR_MANIFEST_URL>' })) before calling tonConnectUI.sendTransaction(...);
apply the same fix to both TypeScript blocks where TonConnectUI and
sendTransaction are used.

---

Nitpick comments:
In `@standard/tokens/nft/transfer.mdx`:
- Around line 273-275: Replace JS floating-point TON literals with explicit
nano-TON integer representations or string-to-nano conversions: change nftPrice
and buyAmount to use BigInt nanos (e.g., nftPriceNano = BigInt(5) * 10n**9n) or
keep human strings and convert via your toNano utility (e.g., toNano("5")).
Update every other floating TON literal in this file (the other numeric currency
variables used around the transfer flow) to follow the same pattern and ensure
downstream calls expect the nano/BigInt or converted value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b2b2690f-07d4-4b1c-aeb8-504a9c1d4b26

📥 Commits

Reviewing files that changed from the base of the PR and between c797f44 and 75363c5.

📒 Files selected for processing (2)
  • standard/tokens/jettons/transfer.mdx
  • standard/tokens/nft/transfer.mdx

Comment thread standard/tokens/jettons/transfer.mdx
Comment thread standard/tokens/nft/transfer.mdx
Copy link
Copy Markdown
Contributor

@delovoyhomie delovoyhomie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found two safety-critical issues in the new GetGems section.

One example still hardcodes the old EQAIFun... deployer address from the deprecated cookbook, while the current upstream getgems-io/nft-contracts README explicitly warns not to use that contract for listing NFTs. The buy section also needs an explicit verification step before readers send TON directly to a sale contract.

Because these examples move real funds, I think both points should be fixed before merge.

Comment thread standard/tokens/nft/transfer.mdx Outdated
Comment thread standard/tokens/nft/transfer.mdx
@novusnota novusnota added the from-old-docs Move or rewrite pages from old-docs.ton.org and adjust the redirects label Apr 17, 2026
@aigerimu aigerimu marked this pull request as draft April 17, 2026 09:14
@coalus coalus marked this pull request as ready for review April 27, 2026 05:35
@coalus coalus requested a review from delovoyhomie April 27, 2026 05:35
Comment on lines +110 to +120
.storeCoins(toNano('0.05')) // forward_ton_amount — if >0, sends notification
.storeBit(1) // forward_payload as reference
.storeRef(beginCell().endCell()) // empty payload reference
.endCell();

const transaction = {
validUntil: Math.floor(Date.now() / 1000) + 360,
messages: [
{
address: '<SENDER_JETTON_WALLET>', // sender's jetton wallet address
amount: toNano('0.05').toString(), // for gas fees, excess is returned
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the jetton wallet needs message_value > jetton_wallet_gas + forward_ton_amount + receiver_gas, but here forward_ton_amount = message value = 0.05 TON so by the time the chain reaches the receiver's jetton wallet there's nothing left to forward as the notification. typical safe values are total ~0.1 TON with forward ~0.02 TON (matches the low-level example below at lines 352/360). this also applies to the bare TS variant on lines 150/160

correct me if i am wrong

Suggested change
.storeCoins(toNano('0.05')) // forward_ton_amount — if >0, sends notification
.storeBit(1) // forward_payload as reference
.storeRef(beginCell().endCell()) // empty payload reference
.endCell();
const transaction = {
validUntil: Math.floor(Date.now() / 1000) + 360,
messages: [
{
address: '<SENDER_JETTON_WALLET>', // sender's jetton wallet address
amount: toNano('0.05').toString(), // for gas fees, excess is returned
.storeUint(0, 1) // custom_payload:(Maybe ^Cell)
.storeCoins(toNano('0.02')) // forward_ton_amount — must be < message value
.storeBit(0) // forward_payload inline, empty
.endCell();
const transaction = {
validUntil: Math.floor(Date.now() / 1000) + 360,
messages: [
{
address: '<SENDER_JETTON_WALLET>', // sender's jetton wallet address
amount: toNano('0.1').toString(), // for gas fees, excess is returned

- `<MANIFEST_URL>` — URL of the dApp manifest. See [manifest](/ecosystem/ton-connect/manifest).

<Aside>
`toNano` assumes 9 decimals. For tokens with different decimals (for example, 6 for USDT), compute the amount manually: `BigInt(value) * 10n ** BigInt(jettonDecimals)`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny: the Aside has no type= so it defaults to a note. that's probably what's intended here, but explicit type makes it consistent with the rest of the file (lines 9, 26, etc)

Suggested change
`toNano` assumes 9 decimals. For tokens with different decimals (for example, 6 for USDT), compute the amount manually: `BigInt(value) * 10n ** BigInt(jettonDecimals)`.
<Aside type="note">
`toNano` assumes 9 decimals. For tokens with different decimals (for example, 6 for USDT), compute the amount manually: `BigInt(value) * 10n ** BigInt(jettonDecimals)`.
</Aside>

SendMode,
storeStateInit,
toNano,
} from '@ton/ton';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SendMode is imported but never used in this snippet

fullPrice: bigint;
}

const GETGEMS_FEE_PERCENT = 5000;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to spell out the unit? 5000 could be basis points (50%), per-mille (5%), or hundredths-of-percent — a reader has to dig into the contract source to find out. a single-line comment is enough

Suggested change
const GETGEMS_FEE_PERCENT = 5000;
// GetGems platform fee, in 1/100000 (so 5000 = 5%)
const GETGEMS_FEE_PERCENT = 5000;

Comment on lines +373 to +374
const nftPrice = 5.0;
const buyAmount = nftPrice + 0.1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nftPrice + 0.1 happens in JS floats. 5.0 + 0.1 is fine but the moment nftPrice is, say, 0.2, 0.2 + 0.1 = 0.30000000000000004 and toNano rejects it / rounds. safer to keep everything in nanoTON

Suggested change
const nftPrice = 5.0;
const buyAmount = nftPrice + 0.1;
// NFT price in TON; total value is price + 0.1 TON for network gas, with excess returned
const nftPrice = toNano('5.0');
const buyAmount = nftPrice + toNano('0.1');

and drop the .toString()/toNano(...) around buyAmount below since it's already a bigint. same fix in the TS variant at lines 403-404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from-old-docs Move or rewrite pages from old-docs.ton.org and adjust the redirects

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Standard contracts] Add TON Connect examples to jetton/NFT transfer pages

3 participants