Skip to content

cookbook tokens: point Token-2022 fetch examples at mainnet#1467

Closed
catmcgee wants to merge 1 commit into
solana-foundation:mainfrom
catmcgee:fix/cookbook-tokens-deploy
Closed

cookbook tokens: point Token-2022 fetch examples at mainnet#1467
catmcgee wants to merge 1 commit into
solana-foundation:mainfrom
catmcgee:fix/cookbook-tokens-deploy

Conversation

@catmcgee

Copy link
Copy Markdown
Contributor

Problem

get-token-account, get-token-balance, and get-token-mint hit Token-2022 accounts that the surfnet doesn't lazy-clone cleanly (the rewriter swaps localhost for the hosted surfnet, which returns null for these two)

Other read-only pages still work because their accounts are classic-Token / Token Program itself, which surfnet does have

Summary of Changes

Switch the URL to api.mainnet.solana.com so the Run button leaves it alone and the code hits mainnet

get-token-account and get-token-balance hit Token-2022 accounts that
the docs Run-button surfnet doesn't lazy-clone cleanly (the rewriter
swaps localhost for the hosted surfnet, which returns null for these
two). Other read-only pages still work because their accounts are
classic-Token / Token Program itself, which surfnet does have.

Switch the URL to api.mainnet.solana.com so the Run button leaves it
alone and the code hits real mainnet. Token-2022 logic stays.
@vercel

vercel Bot commented May 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

6 Skipped Deployments
Project Deployment Actions Updated (UTC)
solana-com Skipped Skipped May 21, 2026 2:30pm
solana-com-accelerate Skipped Skipped May 21, 2026 2:30pm
solana-com-breakpoint-2 Skipped Skipped May 21, 2026 2:30pm
solana-com-docs Skipped Skipped May 21, 2026 2:30pm
solana-com-media Skipped Skipped May 21, 2026 2:30pm
templates Skipped Skipped May 21, 2026 2:30pm

Request Review

@vercel vercel Bot temporarily deployed to Preview – solana-com-breakpoint-2 May 21, 2026 14:30 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com-docs May 21, 2026 14:30 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com May 21, 2026 14:30 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com-accelerate May 21, 2026 14:30 Inactive
@vercel vercel Bot temporarily deployed to Preview – templates May 21, 2026 14:30 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com-media May 21, 2026 14:30 Inactive
@catmcgee catmcgee requested a review from ZYJLiu May 21, 2026 14:30
@catmcgee catmcgee marked this pull request as ready for review May 21, 2026 14:30
@greptile-apps

greptile-apps Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes three Token-2022 cookbook examples (get-token-account, get-token-balance, get-token-mint) that returned null results in the docs playground by pointing them directly at https://api.mainnet.solana.com instead of http://localhost:8899. The surfnet rewriter substitutes localhost with its hosted endpoint, but that endpoint does not lazy-clone Token-2022 accounts cleanly, so hardcoding the official mainnet URL causes the playground's Run button to skip rewriting and hit mainnet directly.

  • 9 files changed across TypeScript (kit + legacy) and Rust implementations, all with the same single-line URL swap and no logic changes.
  • All three examples are read-only RPC calls on stable, long-lived mainnet accounts, so pointing at mainnet carries no write-side risk and the queried accounts will remain available.
  • As a side effect, the vitest suite (which previously routed these examples through the surfnet proxy at localhost:8899) will now hit the public mainnet RPC directly; the read-only nature of the calls makes this safe, though CI runs are now subject to the public endpoint's rate limits.

Confidence Score: 5/5

Safe to merge — all changes are single-line URL swaps in read-only cookbook examples with no logic modifications.

Every changed file replaces http://localhost:8899 with https://api.mainnet.solana.com, which is the current official Solana mainnet endpoint documented at solana.com/docs/rpc. All three examples perform only read-only RPC calls on known, stable mainnet accounts, and the vitest tests import the modules end-to-end, so the fix is exercised on each test run. The only observable difference in CI is that these three tests now call the public mainnet RPC directly rather than through the surfnet proxy, introducing a mild rate-limit dependency, but this is consistent with how the playground is intended to work post-fix.

No files require special attention.

Important Files Changed

Filename Overview
packages/docs-examples/cookbook/tokens/get-token-account/kit.ts Swaps localhost:8899 for https://api.mainnet.solana.com so the docs-playground Run button hits mainnet directly instead of the surfnet rewriter
packages/docs-examples/cookbook/tokens/get-token-account/legacy.ts Same mainnet URL swap for the web3.js/spl-token legacy implementation; formatting adjusted to multi-line Connection constructor call
packages/docs-examples/cookbook/tokens/get-token-account/rust/src/main.rs Rust example updated to mainnet URL; read-only operation, no correctness issues
packages/docs-examples/cookbook/tokens/get-token-balance/kit.ts Mainnet URL swap for the @solana/kit balance example; read-only RPC call unaffected by the endpoint change
packages/docs-examples/cookbook/tokens/get-token-balance/legacy.ts Legacy balance example updated to mainnet; same read-only pattern, no issues
packages/docs-examples/cookbook/tokens/get-token-balance/rust/src/main.rs Rust balance example updated to mainnet; clean single-line change
packages/docs-examples/cookbook/tokens/get-token-mint/kit.ts Mainnet URL swap for the fetchMint/@solana/kit example; no logic changes
packages/docs-examples/cookbook/tokens/get-token-mint/legacy.ts Legacy getMint example updated to mainnet; multi-line Connection reformatting only
packages/docs-examples/cookbook/tokens/get-token-mint/rust/src/main.rs Rust mint example updated to mainnet; clean single-line change

Sequence Diagram

sequenceDiagram
    participant User as Docs Playground User
    participant Rewriter as Surfnet URL Rewriter
    participant Surfnet as Hosted Surfnet
    participant Mainnet as api.mainnet.solana.com

    Note over User,Mainnet: Before this PR (localhost:8899)
    User->>Rewriter: Run example (localhost:8899)
    Rewriter->>Surfnet: Rewrites to hosted surfnet
    Surfnet-->>User: null (Token-2022 accounts not cloned)

    Note over User,Mainnet: After this PR (api.mainnet.solana.com)
    User->>Rewriter: Run example (api.mainnet.solana.com)
    Rewriter-->>User: URL left unchanged (not localhost)
    User->>Mainnet: Direct RPC call
    Mainnet-->>User: Token-2022 account data ✓
Loading

Reviews (1): Last reviewed commit: "cookbook tokens: point Token-2022 fetch ..." | Re-trigger Greptile

@catmcgee

Copy link
Copy Markdown
Contributor Author

closing as we're just going to fix surfpool instead

@catmcgee catmcgee closed this May 21, 2026
@catmcgee catmcgee deleted the fix/cookbook-tokens-deploy branch May 21, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant