Skip to content

docs(cookbook): upgrade kit examples to plugin client#1469

Merged
ZYJLiu merged 4 commits into
mainfrom
docs(ts)/add-plugin-examples
May 21, 2026
Merged

docs(cookbook): upgrade kit examples to plugin client#1469
ZYJLiu merged 4 commits into
mainfrom
docs(ts)/add-plugin-examples

Conversation

@amilz

@amilz amilz commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Refactor 8 cookbook kit examples to the @solana/kit-plugin-rpc + @solana/kit-plugin-signer client pattern introduced in #1465. Replaces manual pipe() / createTransactionMessage / blockhash / sendAndConfirm wiring with createClient().use(payer).use(solanaLocalRpc()).use(airdropPayer()) + client.sendTransaction([...]).

438 → 153 lines (~65% reduction).

Per-file approach

  • send-sol, add-memo, create-account — full plugin refactor
  • add-priority-fees — priority fees configured via solanaLocalRpc({ transactionConfig: { microLamportsPerComputeUnit } }); planner/executor auto-handle CU price + limit
  • fee-sponsorship — uses tokenProgram() plugin (createMint / mintToATA / transferToATA) instead of manual ATA derivation
  • create-token-with-metadata — plugin client for setup, single Metaplex createV1 instruction
  • calculate-cost — partial: plugin for setup/airdrop, kept manual pipe() + getFeeForMessage since fee calculation is the recipe's whole point
  • mev-protection — partial: plugin for setup, kept manual build + base64 + Jito POST

Test plan

  • pnpm --filter @workspace/docs-examples lint (tsc --noEmit)
  • pnpm --filter @workspace/docs-examples test — all 61 tests pass against surfpool
  • pre-commit eslint + prettier clean

Refactor 8 cookbook kit examples to use the @solana/kit-plugin-rpc +
@solana/kit-plugin-signer client pattern introduced in #1465. Replaces
manual pipe() / createTransactionMessage / blockhash / sendAndConfirm
wiring with createClient().use(payer).use(solanaLocalRpc()).use(airdropPayer())
and client.sendTransaction([...]).

- send-sol, add-memo, create-account: full plugin refactor
- add-priority-fees: priority fees configured via solanaLocalRpc
  transactionConfig; planner/executor auto-handle CU price + limit
- fee-sponsorship: uses tokenProgram() plugin (createMint, mintToATA,
  transferToATA) instead of manual ATA derivation
- create-token-with-metadata: plugin client for setup, single Metaplex
  createV1 instruction
- calculate-cost: plugin for setup/airdrop, kept manual pipe + getFeeForMessage
  since fee calculation is the recipe's whole point
- mev-protection: plugin for setup, kept manual build + base64 + Jito POST

438 -> 153 lines (~65% reduction). #region markers preserved so MDX
includes are unchanged. All 61 docs-examples tests pass.
@amilz amilz self-assigned this May 21, 2026
@vercel

vercel Bot commented May 21, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
solana-com-docs Ready Ready Preview, Comment May 21, 2026 9:21pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
solana-com Skipped Skipped May 21, 2026 9:21pm
solana-com-accelerate Skipped Skipped May 21, 2026 9:21pm
solana-com-breakpoint-2 Skipped Skipped May 21, 2026 9:21pm
solana-com-media Skipped Skipped May 21, 2026 9:21pm
templates Skipped Skipped May 21, 2026 9:21pm

Request Review

@greptile-apps

greptile-apps Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR migrates 8 cookbook @solana/kit examples from verbose manual transaction wiring (pipe() / blockhash fetch / sendAndConfirmTransactionFactory) to the new createClient().use(payer).use(solanaRpc()).use(airdropPayer()) plugin pattern, reducing code by ~65% (438 → 153 lines) while preserving the same on-chain behaviour.

  • Full refactors (send-sol, add-memo, create-account, add-priority-fees, fee-sponsorship, create-token-with-metadata): replace all manual boilerplate with client.sendTransaction([...]), with priority fees now configured via transactionConfig and token-program operations delegated to the tokenProgram() plugin.
  • Partial refactors (calculate-cost, mev-protection): only setup / airdrop moves to the plugin client; the manual pipe() transaction build is intentionally kept because inspecting the fee or submitting to Jito is the recipe's whole point.
  • MDX docs: highlight= attributes are removed from the four updated recipes since the plugin version no longer has distinct lines to call out.

Confidence Score: 5/5

Safe to merge — the refactoring is mechanically correct across all eight examples, tests are green, and fee sponsorship semantics are preserved.

Every changed example was read in full. The plugin client correctly inherits fee-payer semantics (feePayer in fee-sponsorship, signer everywhere else), the two partial refactors deliberately retain manual transaction construction for pedagogical clarity, and the TypeScript compiler confirms type correctness. No logic regressions were found.

No files require special attention.

Important Files Changed

Filename Overview
packages/docs-examples/cookbook/transactions/fee-sponsorship/kit.ts Most complex refactor; uses tokenProgram() plugin for createMint/mintToATA/transferToATA. Fee sponsorship is preserved: feePayer is the client payer, sender only signs as token authority with no SOL balance.
packages/docs-examples/cookbook/transactions/add-priority-fees/kit.ts Priority fee now configured via transactionConfig.microLamportsPerComputeUnit; planner/executor auto-inserts SetComputeUnitPrice and SetComputeUnitLimit. Less explicit but well-commented.
packages/docs-examples/cookbook/tokens/create-token-with-metadata/kit.ts Plugin refactor with payer aliased as kitPayer to avoid conflict with the payer variable; Metaplex getCreateV1InstructionAsync call unchanged; client.rpc used for fetchMetadataFromSeeds.
packages/docs-examples/cookbook/transactions/calculate-cost/kit.ts Partial refactor: setup/airdrop use plugin client; manual pipe()/getFeeForMessage kept intentionally as the recipe's core lesson. sendAndConfirmTransactionFactory rebuilt inline from client.rpc/rpcSubscriptions.
packages/docs-examples/cookbook/transactions/mev-protection/kit.ts Partial refactor: plugin client for setup/airdrop only; manual pipe() + base64 + Jito POST kept intact. Jito submission wrapped in try/catch for offline test compatibility.
packages/docs-examples/cookbook/accounts/create-account/kit.ts Refactored to plugin client; space changed from 0n to 0 and getMinimumBalance used via client; tsc passes.
packages/docs-examples/cookbook/transactions/send-sol/kit.ts Clean full refactor to plugin client; manual pipe/blockhash/sendAndConfirm removed, replaced by client.sendTransaction(). Logic identical.
packages/docs-examples/cookbook/transactions/add-memo/kit.ts Straightforward plugin refactor; memo instruction unchanged, only transaction plumbing replaced.

Sequence Diagram

sequenceDiagram
    participant Code as Example Code
    participant Client as createClient()
    participant Payer as payer(signer)
    participant RPC as solanaRpc()
    participant Airdrop as rpcAirdrop() + airdropPayer()
    participant Chain as Solana Localnet

    Code->>Client: createClient()
    Client->>Payer: .use(payer(signer))
    Client->>RPC: ".use(solanaRpc({rpcUrl, rpcSubscriptionsUrl}))"
    Client->>Airdrop: .use(rpcAirdrop()).use(airdropPayer(1 SOL))
    Airdrop->>Chain: airdrop(signer, 1 SOL)
    Chain-->>Airdrop: confirmed
    Airdrop-->>Code: client (ready)

    Note over Code,Chain: Full-refactor examples (send-sol, add-memo, etc.)
    Code->>Client: client.sendTransaction([ix])
    Client->>Chain: getLatestBlockhash + sign + sendAndConfirm
    Chain-->>Code: "{ context: { signature } }"

    Note over Code,Chain: Partial-refactor examples (calculate-cost, mev-protection)
    Code->>Chain: client.rpc.getLatestBlockhash().send()
    Chain-->>Code: latestBlockhash
    Code->>Code: "pipe() -> sign -> base64 / getFeeForMessage"
    Code->>Chain: sendAndConfirmTransactionFactory / Jito endpoint
Loading

Reviews (4): Last reviewed commit: "remove highlight, line numbers incorrect" | Re-trigger Greptile

The plugin-client refactor shortened the kit examples — old highlight=
directives pointed past the new file ends and codehike crashed the
async cookbook compile with "Cannot read properties of undefined
(reading 'range')". Repoint each at the new plugin .use() chain and
the simplified client.sendTransaction call.
@vercel vercel Bot temporarily deployed to Preview – templates May 21, 2026 20:29 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com-accelerate May 21, 2026 20:29 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com-breakpoint-2 May 21, 2026 20:29 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com-media May 21, 2026 20:29 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com May 21, 2026 20:29 Inactive
Comment thread packages/docs-examples/cookbook/accounts/create-account/kit.ts Outdated
Replace solanaLocalRpc() with solanaRpc({ rpcUrl, rpcSubscriptionsUrl })
+ rpcAirdrop() across all 8 cookbook kit examples so readers can swap
the localhost URL for a surfnet (or any other endpoint) without changing
imports or call shape.
@vercel vercel Bot temporarily deployed to Preview – templates May 21, 2026 20:52 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com-media May 21, 2026 20:52 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com-breakpoint-2 May 21, 2026 20:52 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com May 21, 2026 20:52 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com-accelerate May 21, 2026 20:52 Inactive
@amilz amilz requested a review from ZYJLiu May 21, 2026 21:03
@vercel vercel Bot temporarily deployed to Preview – solana-com-media May 21, 2026 21:19 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com-breakpoint-2 May 21, 2026 21:19 Inactive
@vercel vercel Bot temporarily deployed to Preview – templates May 21, 2026 21:19 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com-accelerate May 21, 2026 21:19 Inactive
@vercel vercel Bot temporarily deployed to Preview – solana-com May 21, 2026 21:19 Inactive
@ZYJLiu ZYJLiu merged commit 9cbd90f into main May 21, 2026
23 checks passed
@ZYJLiu ZYJLiu deleted the docs(ts)/add-plugin-examples branch May 21, 2026 21:30
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.

3 participants